Make PKA require wielding (#16638)

This commit is contained in:
metalgearsloth
2023-06-01 12:27:19 +10:00
committed by GitHub
parent f9df5f761c
commit 6537e683b0
8 changed files with 69 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
using Content.Shared.Wieldable;
using Robust.Shared.GameStates;
namespace Content.Shared.Weapons.Melee.Components;
@@ -5,7 +6,7 @@ namespace Content.Shared.Weapons.Melee.Components;
/// <summary>
/// Indicates that this meleeweapon requires wielding to be useable.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, Access(typeof(WieldableSystem))]
public sealed class MeleeRequiresWieldComponent : Component
{

View File

@@ -1,3 +1,4 @@
using Content.Shared.Wieldable;
using Robust.Shared.GameStates;
namespace Content.Shared.Weapons.Ranged.Components;
@@ -5,7 +6,7 @@ namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Indicates that this gun requires wielding to be useable.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, Access(typeof(WieldableSystem))]
public sealed class GunRequiresWieldComponent : Component
{

View File

@@ -0,0 +1,20 @@
using Content.Shared.Wieldable;
using Robust.Shared.GameStates;
namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Applies an accuracy bonus upon wielding.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(WieldableSystem))]
public sealed partial class GunWieldBonusComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("minAngle"), AutoNetworkedField]
public Angle MinAngle = Angle.FromDegrees(-43);
/// <summary>
/// Angle bonus applied upon being wielded.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxAngle"), AutoNetworkedField]
public Angle MaxAngle = Angle.FromDegrees(-43);
}

View File

@@ -29,6 +29,9 @@ public abstract partial class SharedGunSystem
private void OnBallisticUse(EntityUid uid, BallisticAmmoProviderComponent component, UseInHandEvent args)
{
if (args.Handled)
return;
ManualCycle(uid, component, Transform(uid).MapPosition, args.User);
args.Handled = true;
}

View File

@@ -26,7 +26,7 @@ public sealed partial class WieldableComponent : Component
public bool Wielded = false;
[DataField("wieldedInhandPrefix")]
public string WieldedInhandPrefix = "wielded";
public string? WieldedInhandPrefix = "wielded";
public string? OldInhandPrefix = null;

View File

@@ -0,0 +1,7 @@
namespace Content.Shared.Wieldable;
/// <summary>
/// Raised directed on an entity when it is wielded.
/// </summary>
[ByRefEvent]
public readonly record struct ItemWieldedEvent;

View File

@@ -39,6 +39,8 @@ public sealed class WieldableSystem : EntitySystem
SubscribeLocalEvent<MeleeRequiresWieldComponent, AttemptMeleeEvent>(OnMeleeAttempt);
SubscribeLocalEvent<GunRequiresWieldComponent, AttemptShootEvent>(OnShootAttempt);
SubscribeLocalEvent<GunWieldBonusComponent, ItemWieldedEvent>(OnGunWielded);
SubscribeLocalEvent<GunWieldBonusComponent, ItemUnwieldedEvent>(OnGunUnwielded);
SubscribeLocalEvent<IncreaseDamageOnWieldComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
}
@@ -63,6 +65,26 @@ public sealed class WieldableSystem : EntitySystem
}
}
private void OnGunUnwielded(EntityUid uid, GunWieldBonusComponent component, ItemUnwieldedEvent args)
{
if (!TryComp<GunComponent>(uid, out var gun))
return;
gun.MinAngle -= component.MinAngle;
gun.MaxAngle -= component.MaxAngle;
Dirty(gun);
}
private void OnGunWielded(EntityUid uid, GunWieldBonusComponent component, ref ItemWieldedEvent args)
{
if (!TryComp<GunComponent>(uid, out var gun))
return;
gun.MinAngle += component.MinAngle;
gun.MaxAngle += component.MaxAngle;
Dirty(gun);
}
private void OnDisarmAttemptEvent(EntityUid uid, WieldableComponent component, DisarmAttemptEvent args)
{
if (component.Wielded)
@@ -197,6 +219,9 @@ public sealed class WieldableSystem : EntitySystem
_popupSystem.PopupClient(Loc.GetString("wieldable-component-successful-wield", ("item", uid)), args.Args.User, args.Args.User);
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield-other", ("user", args.Args.User),("item", uid)), args.Args.User, Filter.PvsExcept(args.Args.User), true);
var ev = new ItemWieldedEvent();
RaiseLocalEvent(uid, ref ev);
Dirty(component);
args.Handled = true;
}

View File

@@ -8,9 +8,17 @@
- type: Item
sprite: Objects/Weapons/Guns/Basic/kinetic_accelerator.rsi
size: 30
- type: GunWieldBonus
minAngle: -43
maxAngle: -43
- type: Wieldable
wieldedInhandPrefix: null
- type: Gun
fireRate: 0.75
selectedMode: SemiAuto
angleDecay: 45
minAngle: 44
maxAngle: 45
availableModes:
- SemiAuto
soundGunshot:
@@ -24,7 +32,7 @@
True: { visible: False }
False: { visible: True }
- type: RechargeBasicEntityAmmo
rechargeCooldown: 1
rechargeCooldown: 0.75
rechargeSound:
path: /Audio/Weapons/Guns/MagIn/kinetic_reload.ogg
- type: BasicEntityAmmoProvider