Skip to content

Commit

Permalink
meleeweaponsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
vanx committed Aug 28, 2024
1 parent 02d3cd1 commit 4121e60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
48 changes: 28 additions & 20 deletions Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,7 @@ 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

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

Expand All @@ -111,30 +101,48 @@ public override void Update(float frameTime)
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
}

// Heavy attack.
// 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);
}

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

// If it's a ranged weapon then do a light attack
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
{
RaisePredictiveEvent(new LightAttackEvent(GetNetEntity(target), GetNetEntity(weaponUid), GetNetCoordinates(coordinates)));
return;
}

// Otherwise do a wide swing
ClientHeavyAttack(entity, coordinates, weaponUid, weapon);
return;
}

// Light attack
// 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;
}

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;

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
_damageExamine.AddDamageExamine(args.Message, damageSpec * component.HeavyDamageBaseModifier, Loc.GetString("damage-melee-heavy"));
}

Expand Down

0 comments on commit 4121e60

Please sign in to comment.