Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tweak] The Gunnening #285

Merged
merged 14 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,36 @@ protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent comp
var cycledEvent = new GunCycledEvent();
RaiseLocalEvent(uid, ref cycledEvent);
}

// WWDP extract round
protected override void Extract(EntityUid uid, MapCoordinates coordinates, BallisticAmmoProviderComponent component,
EntityUid user)
{
if (!Timing.IsFirstTimePredicted)
return;

EntityUid entity;

if (component.Entities.Count > 0)
{
entity = component.Entities[^1];
component.Entities.RemoveAt(component.Entities.Count - 1);
EnsureShootable(entity);
}
else if (component.UnspawnedCount > 0)
{
component.UnspawnedCount--;
entity = Spawn(component.Proto, coordinates);
EnsureShootable(entity);
}
else
{
Popup("Empty", uid, user);
return;
}

if (IsClientSide(entity))
Del(entity);
}
// WWDP end
}
30 changes: 30 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.Ballistic.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Stack;
using Content.Shared.Hands.EntitySystems; // WWDP
using Content.Shared.Stacks;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
Expand All @@ -9,6 +10,7 @@ namespace Content.Server.Weapons.Ranged.Systems;
public sealed partial class GunSystem
{
[Dependency] private readonly StackSystem _stack = default!; // WD EDIT
[Dependency] private readonly SharedHandsSystem _handsSystem = default!; // WWDP

protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates)
{
Expand Down Expand Up @@ -37,6 +39,34 @@ protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent comp
RaiseLocalEvent(uid, ref cycledEvent);
}

// WWDP extract round
protected override void Extract(EntityUid uid, MapCoordinates coordinates, BallisticAmmoProviderComponent component,
EntityUid user)
{
EntityUid entity;

if (component.Entities.Count > 0)
{
entity = component.Entities[^1];
component.Entities.RemoveAt(component.Entities.Count - 1);
EnsureShootable(entity);
}
else if (component.UnspawnedCount > 0)
{
component.UnspawnedCount--;
entity = Spawn(component.Proto, coordinates);
EnsureShootable(entity);
}
else
{
Popup("Empty", uid, user);
return;
}

_handsSystem.PickupOrDrop(user, entity);
}
// WWDP extract round end

// WD EDIT START
protected override EntityUid GetStackEntity(EntityUid uid, StackComponent stack)
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/CCVar/CCVars.Accessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed partial class CCVars
/// Goes from 0 (no recoil at all) to 1 (regular amounts of recoil)
/// </summary>
public static readonly CVarDef<float> ScreenShakeIntensity =
CVarDef.Create("accessibility.screen_shake_intensity", 1f, CVar.CLIENTONLY | CVar.ARCHIVE);
CVarDef.Create("accessibility.screen_shake_intensity", 0.2f, CVar.CLIENTONLY | CVar.ARCHIVE); // WWDP less visual recoil

/// <summary>
/// A generic toggle for various visual effects that are color sensitive.
Expand Down
7 changes: 6 additions & 1 deletion Content.Shared/Examine/ExamineSystemShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ public FormattedMessage GetExamineText(EntityUid entity, EntityUid? examiner)
//Add an entity description if one is declared
if (!string.IsNullOrEmpty(EntityManager.GetComponent<MetaDataComponent>(entity).EntityDescription))
{
message.AddText(EntityManager.GetComponent<MetaDataComponent>(entity).EntityDescription);
// WWDP edit
var description = EntityManager.GetComponent<MetaDataComponent>(entity).EntityDescription;
var descriptionWrapped = Loc.GetString("examine-entity-description-wrapper", ("description", description));

message.AddMarkup(descriptionWrapped);
// WWDP edit end
hasDescription = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public sealed partial class BallisticAmmoProviderComponent : Component

public Container Container = default!;

public bool Racked = true; // WWDP

// TODO: Make this use stacks when the typeserializer is done.
[DataField, AutoNetworkedField]
public List<EntityUid> Entities = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public sealed partial class ChamberMagazineAmmoProviderComponent : MagazineAmmoP
[ViewVariables(VVAccess.ReadWrite), DataField("autoCycle"), AutoNetworkedField]
public bool AutoCycle = true;

/// <summary>
/// WWDP - If true, the gun will lock the bolt open once the mag is empty.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("boltCatch"), AutoNetworkedField]
public bool BoltCatch = true;

/// <summary>
/// Can the gun be racked, which opens and then instantly closes the bolt to cycle a round.
/// </summary>
Expand Down
112 changes: 104 additions & 8 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems; // WWDP
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Stacks;
Expand All @@ -8,13 +9,16 @@
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Prototypes; // WWDP
using Robust.Shared.Serialization;

namespace Content.Shared.Weapons.Ranged.Systems;

public abstract partial class SharedGunSystem
{
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly IPrototypeManager _proto = default!; // WWDP
[Dependency] private readonly SharedHandsSystem _handsSystem = default!; // WWDP


protected virtual void InitializeBallistic()
Expand All @@ -27,7 +31,8 @@ protected virtual void InitializeBallistic()
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetAmmoCountEvent>(OnBallisticAmmoCount);

SubscribeLocalEvent<BallisticAmmoProviderComponent, ExaminedEvent>(OnBallisticExamine);
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<Verb>>(OnBallisticVerb);
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<InteractionVerb>>(AddInteractionVerb); // WWDP
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<AlternativeVerb>>(AddAlternativeVerb); // WWDP
SubscribeLocalEvent<BallisticAmmoProviderComponent, InteractUsingEvent>(OnBallisticInteractUsing);
SubscribeLocalEvent<BallisticAmmoProviderComponent, AfterInteractEvent>(OnBallisticAfterInteract);
SubscribeLocalEvent<BallisticAmmoProviderComponent, AmmoFillDoAfterEvent>(OnBallisticAmmoFillDoAfter);
Expand All @@ -50,9 +55,16 @@ private void OnBallisticInteractUsing(EntityUid uid, BallisticAmmoProviderCompon

if (_whitelistSystem.IsWhitelistFailOrNull(component.Whitelist, args.Used))
return;
// WWDP EDIT
if (HasComp<BallisticAmmoProviderComponent>(args.Used)) // Ammo providers use the doafter
return;

if (GetBallisticShots(component) >= component.Capacity)
{
Popup("Full", uid, args.User); // todo locale
return;
}
// WWDP EDIT END

// WD EDIT START
var entity = args.Used;
Expand Down Expand Up @@ -100,6 +112,9 @@ private void OnBallisticAfterInteract(EntityUid uid, BallisticAmmoProviderCompon

private void OnBallisticAmmoFillDoAfter(EntityUid uid, BallisticAmmoProviderComponent component, AmmoFillDoAfterEvent args)
{
if (args.Handled || args.Cancelled) // WWDP
return;

if (Deleted(args.Target) ||
!TryComp<BallisticAmmoProviderComponent>(args.Target, out var target) ||
target.Whitelist == null)
Expand Down Expand Up @@ -168,14 +183,14 @@ void SimulateInsertAmmo(EntityUid ammo, EntityUid ammoProvider, EntityCoordinate
args.Repeat = moreSpace && moreAmmo;
}

private void OnBallisticVerb(EntityUid uid, BallisticAmmoProviderComponent component, GetVerbsEvent<Verb> args)
private void AddInteractionVerb(EntityUid uid, BallisticAmmoProviderComponent component, GetVerbsEvent<InteractionVerb> args) // WWDP
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null || !component.Cycleable)
if (!args.CanAccess || !args.CanInteract || args.Hands == null) // WWDP
return;

if (component.Cycleable)
{
args.Verbs.Add(new Verb()
args.Verbs.Add(new InteractionVerb() // WWDP
{
Text = Loc.GetString("gun-ballistic-cycle"),
Disabled = GetBallisticShots(component) == 0,
Expand All @@ -185,13 +200,77 @@ private void OnBallisticVerb(EntityUid uid, BallisticAmmoProviderComponent compo
}
}

// WWDP edit alt-verb to extract ammunition
private void AddAlternativeVerb(EntityUid uid, BallisticAmmoProviderComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;

args.Verbs.Add(new AlternativeVerb()
{
Text = Loc.GetString("gun-ballistic-extract"),
Disabled = GetBallisticShots(component) == 0,
Act = () => ExtractAction(uid, Transform(uid).MapPosition, component, args.User),
});
}
// WWDP edit end

private void OnBallisticExamine(EntityUid uid, BallisticAmmoProviderComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;

args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", GetBallisticShots(component))));
// WWDP edit; better examine, no ammo count on guns
if (!HasComp<GunComponent>(uid))
{
args.PushMarkup(Loc.GetString("gun-ammocount-examine", ("color", AmmoExamineColor), ("count", GetBallisticShots(component))));
return;
}

if (component.Entities.Count > 0 && TryComp<MetaDataComponent>(component.Entities[^1], out var cartridgeMetaData))
{
args.PushMarkup(Loc.GetString("gun-chamber-examine", ("color", ModeExamineColor),
("cartridge", cartridgeMetaData.EntityName)), -1);
}
else if (component.UnspawnedCount > 0 && component.Proto != null)
{
var cartridge = _proto.Index<EntityPrototype>(component.Proto);
args.PushMarkup(Loc.GetString("gun-chamber-examine", ("color", ModeExamineColor),
("cartridge", cartridge.Name)), -1);
}
else
{
args.PushMarkup(Loc.GetString("gun-chamber-examine-empty", ("color", ModeExamineBadColor)), -1);
}

if (!component.AutoCycle)
{
if (component.Racked)
{
args.PushMarkup(Loc.GetString("gun-racked-examine", ("color", ModeExamineColor)), -1);
}
else
{
args.PushMarkup(Loc.GetString("gun-racked-examine-not", ("color", ModeExamineBadColor)), -1);
}
}

// WWDP edit end
}

// WWDP manual ammo extraction
private void ExtractAction(EntityUid uid, MapCoordinates coordinates, BallisticAmmoProviderComponent component, EntityUid user)
{
Extract(uid, coordinates, component, user);

Audio.PlayPredicted(component.SoundInsert, uid, user);
UpdateBallisticAppearance(uid, component);
UpdateAmmoCount(uid);
}
// WWDP edit end

protected abstract void Extract(EntityUid uid, MapCoordinates coordinates, BallisticAmmoProviderComponent component,
EntityUid user); // WWDP

private void ManualCycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates, EntityUid? user = null, GunComponent? gunComp = null)
{
Expand All @@ -214,6 +293,8 @@ private void ManualCycle(EntityUid uid, BallisticAmmoProviderComponent component

var text = Loc.GetString(shots == 0 ? "gun-ballistic-cycled-empty" : "gun-ballistic-cycled");

component.Racked = true; // WWDP

Popup(text, uid, user);
UpdateBallisticAppearance(uid, component);
UpdateAmmoCount(uid);
Expand Down Expand Up @@ -263,8 +344,19 @@ private void OnBallisticTakeAmmo(EntityUid uid, BallisticAmmoProviderComponent c
component.Entities.RemoveAt(component.Entities.Count - 1);
Containers.Remove(entity, component.Container);
}
// WWDP edit; support internal caseless ammo in hand-cycled guns
else if (TryComp<CartridgeAmmoComponent>(entity, out var cartridge) && cartridge.DeleteOnSpawn)
{
component.Entities.RemoveAt(component.Entities.Count - 1);
Containers.Remove(entity, component.Container);
component.Racked = false;
break;
} // WWDP edit end
else
{
component.Racked = false; // WWDP
break;
}
}
else if (component.UnspawnedCount > 0)
{
Expand All @@ -273,10 +365,14 @@ private void OnBallisticTakeAmmo(EntityUid uid, BallisticAmmoProviderComponent c
args.Ammo.Add((entity, EnsureShootable(entity)));

// WD EDIT START
if (!component.AutoCycle && HasComp<CartridgeAmmoComponent>(entity))
if (!component.AutoCycle && TryComp<CartridgeAmmoComponent>(entity, out var cartridge))
{
component.Entities.Add(entity);
Containers.Insert(entity, component.Container);
component.Racked = false; // WWDP
if (!cartridge.DeleteOnSpawn) // WWDP support caseless ammo
{
component.Entities.Add(entity);
Containers.Insert(entity, component.Container);
}
break;
}
// WD EDIT END
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ private void OnChamberMagazineExamine(EntityUid uid, ChamberMagazineAmmoProvider
if (!args.IsInDetailsRange)
return;

var (count, _) = GetChamberMagazineCountCapacity(uid, component);
string boltState;

using (args.PushGroup(nameof(ChamberMagazineAmmoProviderComponent)))
Expand All @@ -288,10 +287,28 @@ private void OnChamberMagazineExamine(EntityUid uid, ChamberMagazineAmmoProvider
else
boltState = Loc.GetString("gun-chamber-bolt-closed-state");
args.PushMarkup(Loc.GetString("gun-chamber-bolt", ("bolt", boltState),
("color", component.BoltClosed.Value ? Color.FromHex("#94e1f2") : Color.FromHex("#f29d94"))));
("color", component.BoltClosed.Value ? ModeExamineColor : ModeExamineBadColor))); // WWDP
}

args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", count)));
// WWDP examine: show bolt state, chamber & magazine

var cartridge = _slots.GetItemOrNull(uid, "gun_chamber");
var magazine = _slots.GetItemOrNull(uid, "gun_magazine");

if (cartridge != null && TryComp<MetaDataComponent>(cartridge, out var cartridgeMetaData))
{
args.PushMarkup(Loc.GetString("gun-chamber-examine", ("color", ModeExamineColor),
("cartridge", cartridgeMetaData.EntityName)), -1);
}
else
args.PushMarkup(Loc.GetString("gun-chamber-examine-empty", ("color", ModeExamineBadColor)), -1);

if (TryComp<MetaDataComponent>(magazine, out var magazineMetaData))
{
args.PushMarkup(Loc.GetString("gun-inserted-magazine-examine", ("color", ModeExamineColor),
("magazine", magazineMetaData.EntityName)), -2);
}
// WWDP edit end
}
}

Expand Down Expand Up @@ -402,7 +419,7 @@ private void OnChamberMagazineTakeAmmo(EntityUid uid, ChamberMagazineAmmoProvide
}

// If no more ammo then open bolt.
if (relayedArgs.Ammo.Count == 0)
if (relayedArgs.Ammo.Count == 0 && component.BoltCatch) // WWDP bolt catch
{
SetBoltClosed(uid, component, false, user: args.User, appearance: appearance);
}
Expand Down
Loading
Loading