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

Added Right Click Melee Attack to Guns #24

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
56 changes: 35 additions & 21 deletions Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,9 @@ public override void Update(float frameTime)
return;
}

// TODO using targeted actions while combat mode is enabled should NOT trigger attacks.

// TODO: Need to make alt-fire melee its own component I guess?
// Melee and guns share a lot in the middle but share virtually nothing at the start and end so
// it's kinda tricky.
// I think as long as we make secondaries their own component it's probably fine
// as long as guncomp has an alt-use key then it shouldn't be too much of a PITA to deal with.
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
{
return;
}
// TODO using targeted actions while combat mode is enabled should NOT trigger attacks

Remuchi marked this conversation as resolved.
Show resolved Hide resolved
// WD EDIT

var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition);

Expand All @@ -112,24 +104,36 @@ public override void Update(float frameTime)
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
}

// Heavy attack.
// WD EDIT START

// Right click
// Unarmed will try to disarm
// Melee weapons will wideswing
// Ranged weapons will do a light attack.
if (altDown == BoundKeyState.Down)
{
// Get the target that was clicked on
EntityUid? target = null;

if (_stateManager.CurrentState is GameplayStateBase screen)
{
target = screen.GetClickedEntity(mousePos);
}
Vaaankas marked this conversation as resolved.
Show resolved Hide resolved

// If it's an unarmed attack then do a disarm
if (weapon.AltDisarm && weaponUid == entity)
{
EntityUid? target = null;

if (_stateManager.CurrentState is GameplayStateBase screen)
{
target = screen.GetClickedEntity(mousePos);
}

EntityManager.RaisePredictiveEvent(new DisarmAttackEvent(GetNetEntity(target), GetNetCoordinates(coordinates)));
return;
}

// WD EDIT START
// If it's a ranged weapon then do a light attack
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
Vaaankas marked this conversation as resolved.
Show resolved Hide resolved
{
RaisePredictiveEvent(new LightAttackEvent(GetNetEntity(target), GetNetEntity(weaponUid), GetNetCoordinates(coordinates)));
return;
}

if (HasComp<BlinkComponent>(weaponUid))
{
if (!_xformQuery.TryGetComponent(entity, out var userXform) || !Timing.IsFirstTimePredicted)
Expand All @@ -154,9 +158,19 @@ public override void Update(float frameTime)
return;
}

// Light attack
// WD EDIT START

// Left click
if (useDown == BoundKeyState.Down)
{
// If it's a gun that shoots with left click do not attack
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
{
return;
}
Vaaankas marked this conversation as resolved.
Show resolved Hide resolved

// WD EDIT END

var attackerPos = Transform(entity).MapPosition;

if (mousePos.MapId != attackerPos.MapId ||
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Linq;
using System.Numerics;
using Content.Shared.Chat;
using Content.Shared.Weapons.Ranged.Components; // WD EDIT

namespace Content.Server.Weapons.Melee;

Expand Down Expand Up @@ -58,7 +59,7 @@ private void OnMeleeExamineDamage(EntityUid uid, MeleeWeaponComponent component,

_damageExamine.AddDamageExamine(args.Message, damageSpec, Loc.GetString("damage-melee"));

if (damageSpec * component.HeavyDamageBaseModifier != damageSpec)
if (damageSpec * component.HeavyDamageBaseModifier != damageSpec && !TryComp<GunComponent>(uid, out var gun)) // Guns don't have a heavy attack // WD EDIT
Remuchi marked this conversation as resolved.
Show resolved Hide resolved
_damageExamine.AddDamageExamine(args.Message, damageSpec * component.HeavyDamageBaseModifier, Loc.GetString("damage-melee-heavy"));
}

Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using Content.Shared._White.Weapons.Melee.Events; // WD EDIT
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.CombatMode;
Expand Down Expand Up @@ -62,7 +63,7 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnMeleeSelected);
SubscribeLocalEvent<MeleeWeaponComponent, ShotAttemptedEvent>(OnMeleeShotAttempted);
SubscribeLocalEvent<MeleeWeaponComponent, MeleeAttemptedEvent>(OnMeleeAttempted); // WD EDIT
SubscribeLocalEvent<MeleeWeaponComponent, GunShotEvent>(OnMeleeShot);
SubscribeLocalEvent<BonusMeleeDamageComponent, GetMeleeDamageEvent>(OnGetBonusMeleeDamage);
SubscribeLocalEvent<BonusMeleeDamageComponent, GetHeavyDamageModifierEvent>(OnGetBonusHeavyDamageModifier);
Expand All @@ -86,7 +87,7 @@ private void OnMapInit(EntityUid uid, MeleeWeaponComponent component, MapInitEve
#endif
}

private void OnMeleeShotAttempted(EntityUid uid, MeleeWeaponComponent comp, ref ShotAttemptedEvent args)
private void OnMeleeAttempted(EntityUid uid, MeleeWeaponComponent comp, ref MeleeAttemptedEvent args) // WD EDIT
{
if (comp.NextAttack > Timing.CurTime)
args.Cancel();
Expand Down
9 changes: 6 additions & 3 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override void Initialize()
{
SubscribeAllEvent<RequestShootEvent>(OnShootRequest);
SubscribeAllEvent<RequestStopShootEvent>(OnStopShootRequest);
SubscribeLocalEvent<GunComponent, MeleeHitEvent>(OnGunMelee);
//SubscribeLocalEvent<GunComponent, MeleeHitEvent>(OnGunMelee); // WD EDIT

// Ammo providers
InitializeBallistic();
Expand Down Expand Up @@ -110,7 +110,9 @@ private void OnMapInit(Entity<GunComponent> gun, ref MapInitEvent args)
RefreshModifiers((gun, gun));
}

private void OnGunMelee(EntityUid uid, GunComponent component, MeleeHitEvent args)
// WD EDIT START
// Sets the gun cooldown to the melee attack cooldown on attack. Removed since it felt very unintuitive.
/*private void OnGunMelee(EntityUid uid, GunComponent component, MeleeHitEvent args)
{
if (!TryComp<MeleeWeaponComponent>(uid, out var melee))
return;
Expand All @@ -120,7 +122,8 @@ private void OnGunMelee(EntityUid uid, GunComponent component, MeleeHitEvent arg
component.NextFire = melee.NextAttack;
Dirty(component);
}
}
}*/
// WD EDIT END

private void OnShootRequest(RequestShootEvent msg, EntitySessionEventArgs args)
{
Expand Down
37 changes: 37 additions & 0 deletions Content.Shared/_White/Weapons/Melee/Events/MeleeAttemptedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Content.Shared._White.Weapons.Melee.Events;

/// <summary>
/// Raised on a melee when someone is attempting to attack with it.
/// Cancel this event to prevent it from attacking.
/// </summary>
[ByRefEvent]
public record struct MeleeAttemptedEvent
{
/// <summary>
/// The user attempting to attack with the weapon.
/// </summary>
public EntityUid User;

/// <summary>
/// The weapon being used.
/// </summary>
public EntityUid Used;

public bool Cancelled { get; private set; }

/// </summary>
/// Prevent the weapon from attacking
/// </summary>
public void Cancel()
{
Cancelled = true;
}

/// </summary>
/// Allow the weapon to attack again, only use if you know what you are doing
/// </summary>
public void Uncancel()
{
Cancelled = false;
}
}
Vaaankas marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/pka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,16 @@
- state: animation-icon
visible: false
map: [ "empty-icon" ]
- type: MeleeWeapon # WD EDIT
attackRate: 0.7
damage:
types:
Blunt: 7
soundHit:
collection: GenericHit
- type: IncreaseDamageOnWield # WD EDIT
damage:
types:
Blunt: 3
# todo: add itemcomponent with inhandVisuals states using unused texture and animation assets in kinetic_accelerator.rsi
Remuchi marked this conversation as resolved.
Show resolved Hide resolved
# todo: add clothingcomponent with clothingVisuals states using unused texture and animations assets in kinetic_accelerator.rsi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
- type: Appearance
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
attackRate: 0.7
damage:
types:
Blunt: 10
soundHit:
collection: GenericHit

- type: entity
id: BaseWeaponPowerCell
Expand Down Expand Up @@ -68,6 +75,13 @@
- type: ContainerContainer
containers:
gun_magazine: !type:ContainerSlot
- type: MeleeWeapon # WD EDIT
attackRate: 0.7
damage:
types:
Blunt: 10
soundHit:
collection: GenericHit

- type: entity
id: BaseWeaponBatterySmall
Expand All @@ -88,6 +102,11 @@
slots:
- Belt
- suitStorage
- type: MeleeWeapon # WD EDIT
attackRate: 1
damage:
types:
Blunt: 7

- type: entity
id: BaseWeaponPowerCellSmall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
price: 500
- type: UseDelay
delay: 1
- type: MeleeWeapon # WD EDIT
attackRate: 0.5
damage:
types:
Blunt: 8
soundHit:
collection: GenericHit

- type: entity
name: L6 SAW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
- type: Appearance
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
damage:
types:
Blunt: 7
soundHit:
collection: GenericHit

- type: entity
name: viper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
path: /Audio/Weapons/Guns/MagIn/revolver_magin.ogg
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
damage:
types:
Blunt: 7
soundHit:
collection: GenericHit

- type: entity
name: Deckard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
gun_chamber: !type:ContainerSlot
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
attackRate: 0.7
damage:
types:
Blunt: 10
soundHit:
collection: GenericHit

- type: entity
name: AKMS
Expand Down Expand Up @@ -98,6 +105,10 @@
steps: 1
zeroVisible: true
- type: Appearance
- type: MeleeWeapon # WD EDIT
damage:
types:
Blunt: 10
Remuchi marked this conversation as resolved.
Show resolved Hide resolved

- type: entity
name: M-90gl
Expand Down
11 changes: 9 additions & 2 deletions Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
maxAngle: 16
fireRate: 8
angleIncrease: 3
angleDecay: 16
angleDecay: 16
selectedMode: FullAuto
availableModes:
- SemiAuto
Expand Down Expand Up @@ -54,6 +54,13 @@
gun_chamber: !type:ContainerSlot
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
attackRate: 0.8
damage:
types:
Blunt: 8
soundHit:
collection: GenericHit

- type: entity
name: Atreides
Expand Down Expand Up @@ -234,7 +241,7 @@
minAngle: 1
maxAngle: 6
angleIncrease: 1.5
angleDecay: 6
angleDecay: 6
selectedMode: FullAuto
shotsPerBurst: 5
availableModes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
ents: []
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
attackRate: 0.7
damage:
types:
Blunt: 10
soundHit:
collection: GenericHit

- type: entity
name: Bulldog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
ents: []
- type: StaticPrice
price: 500
- type: MeleeWeapon # WD EDIT
attackRate: 0.5
damage:
types:
Blunt: 8
soundHit:
collection: GenericHit

- type: entity
name: Kardashev-Mosin
Expand All @@ -54,6 +61,13 @@
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/sniper.ogg
fireOnDropChance: 1
- type: MeleeWeapon # WD EDIT
damage:
types:
Piercing: 10
Slash: 5
soundHit:
path: /Audio/Weapons/bladeslice.ogg

- type: entity
name: Hristov
Expand Down
Loading