Remove .Owner from melee weapons (#14600)

This commit is contained in:
metalgearsloth
2023-03-12 15:56:05 +11:00
committed by GitHub
parent 5541edbadc
commit e93d5113ad
8 changed files with 96 additions and 89 deletions

View File

@@ -42,9 +42,7 @@ public sealed class MeleeArcOverlay : Overlay
return; return;
} }
var weapon = _melee.GetWeapon(player.Value); if (!_melee.TryGetWeapon(player.Value, out _, out var weapon))
if (weapon == null)
return; return;
var mousePos = _inputManager.MouseScreenPosition; var mousePos = _inputManager.MouseScreenPosition;

View File

@@ -15,7 +15,6 @@ public sealed partial class MeleeWeaponSystem
/// </summary> /// </summary>
private const float DamageAnimationLength = 0.30f; private const float DamageAnimationLength = 0.30f;
private const string AnimationKey = "melee-animation";
private const string DamageAnimationKey = "damage-effect"; private const string DamageAnimationKey = "damage-effect";
private const string FadeAnimationKey = "melee-fade"; private const string FadeAnimationKey = "melee-fade";
private const string SlashAnimationKey = "melee-slash"; private const string SlashAnimationKey = "melee-slash";
@@ -154,10 +153,10 @@ public sealed partial class MeleeWeaponSystem
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.05f, 0.15f), FadeAnimationKey); _animation.Play(animationUid, GetFadeAnimation(sprite, 0.05f, 0.15f), FadeAnimationKey);
break; break;
case WeaponArcAnimation.None: case WeaponArcAnimation.None:
var mapPos = userXform.WorldPosition; var (mapPos, mapRot) = _transform.GetWorldPositionRotation(userXform, GetEntityQuery<TransformComponent>());
var xform = Transform(animationUid); var xform = Transform(animationUid);
xform.AttachToGridOrMap(); xform.AttachToGridOrMap();
xform.WorldPosition = mapPos + (userXform.WorldRotation - userXform.LocalRotation).RotateVec(localPos); _transform.SetWorldPosition(xform, mapPos + (mapRot - userXform.LocalRotation).RotateVec(localPos));
if (arcComponent.Fadeout) if (arcComponent.Fadeout)
_animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey); _animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey);
break; break;

View File

@@ -62,9 +62,8 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
return; return;
var entity = entityNull.Value; var entity = entityNull.Value;
var weapon = GetWeapon(entity);
if (weapon == null) if (!TryGetWeapon(entity, out var weaponUid, out var weapon))
return; return;
if (!CombatMode.IsInCombatMode(entity) || !Blocker.CanAttack(entity)) if (!CombatMode.IsInCombatMode(entity) || !Blocker.CanAttack(entity))
@@ -72,7 +71,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
weapon.Attacking = false; weapon.Attacking = false;
if (weapon.WindUpStart != null) if (weapon.WindUpStart != null)
{ {
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weapon.Owner)); EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weaponUid));
} }
return; return;
@@ -94,7 +93,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
} }
// If it's an unarmed attack then do a disarm // If it's an unarmed attack then do a disarm
if (weapon.Owner == entity) if (weaponUid == entity)
{ {
EntityUid? target = null; EntityUid? target = null;
@@ -103,11 +102,11 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
if (MapManager.TryFindGridAt(mousePos, out var grid)) if (MapManager.TryFindGridAt(mousePos, out var grid))
{ {
coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, _transform, EntityManager);
} }
else else
{ {
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, _transform, EntityManager);
} }
if (_stateManager.CurrentState is GameplayStateBase screen) if (_stateManager.CurrentState is GameplayStateBase screen)
@@ -124,7 +123,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
// Start a windup // Start a windup
if (weapon.WindUpStart == null) if (weapon.WindUpStart == null)
{ {
EntityManager.RaisePredictiveEvent(new StartHeavyAttackEvent(weapon.Owner)); EntityManager.RaisePredictiveEvent(new StartHeavyAttackEvent(weaponUid));
weapon.WindUpStart = currentTime; weapon.WindUpStart = currentTime;
} }
@@ -138,14 +137,14 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (MapManager.TryFindGridAt(mousePos, out var grid)) if (MapManager.TryFindGridAt(mousePos, out var grid))
{ {
coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, _transform, EntityManager);
} }
else else
{ {
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, _transform, EntityManager);
} }
EntityManager.RaisePredictiveEvent(new HeavyAttackEvent(weapon.Owner, coordinates)); EntityManager.RaisePredictiveEvent(new HeavyAttackEvent(weaponUid, coordinates));
} }
return; return;
@@ -153,7 +152,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
if (weapon.WindUpStart != null) if (weapon.WindUpStart != null)
{ {
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weapon.Owner)); EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weaponUid));
} }
// Light attack // Light attack
@@ -179,11 +178,11 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (MapManager.TryFindGridAt(mousePos, out var grid)) if (MapManager.TryFindGridAt(mousePos, out var grid))
{ {
coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(grid.Owner, mousePos, _transform, EntityManager);
} }
else else
{ {
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager); coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, _transform, EntityManager);
} }
EntityUid? target = null; EntityUid? target = null;
@@ -194,13 +193,13 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
target = screen.GetClickedEntity(mousePos); target = screen.GetClickedEntity(mousePos);
} }
RaisePredictiveEvent(new LightAttackEvent(target, weapon.Owner, coordinates)); RaisePredictiveEvent(new LightAttackEvent(target, weaponUid, coordinates));
return; return;
} }
if (weapon.Attacking) if (weapon.Attacking)
{ {
RaisePredictiveEvent(new StopAttackEvent(weapon.Owner)); RaisePredictiveEvent(new StopAttackEvent(weaponUid));
} }
} }

View File

@@ -44,9 +44,7 @@ public sealed class MeleeWindupOverlay : Overlay
return; return;
} }
var comp = _melee.GetWeapon(owner.Value); if (!_melee.TryGetWeapon(owner.Value, out var meleeUid, out var comp))
if (comp == null)
return; return;
var handle = args.WorldHandle; var handle = args.WorldHandle;
@@ -67,7 +65,7 @@ public sealed class MeleeWindupOverlay : Overlay
return; return;
} }
if (!xformQuery.TryGetComponent(comp.Owner, out var xform) || if (!xformQuery.TryGetComponent(meleeUid, out var xform) ||
xform.MapID != args.MapId) xform.MapID != args.MapId)
{ {
return; return;
@@ -84,7 +82,7 @@ public sealed class MeleeWindupOverlay : Overlay
// Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped // Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped
// by the bar. // by the bar.
float yOffset; float yOffset;
if (spriteQuery.TryGetComponent(comp.Owner, out var sprite)) if (spriteQuery.TryGetComponent(meleeUid, out var sprite))
{ {
yOffset = -sprite.Bounds.Height / 2f - 0.05f; yOffset = -sprite.Bounds.Height / 2f - 0.05f;
} }
@@ -106,11 +104,11 @@ public sealed class MeleeWindupOverlay : Overlay
const float endX = 22f; const float endX = 22f;
// Area marking where to release // Area marking where to release
var ReleaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) comp.WindupTime.TotalSeconds * EyeManager.PixelsPerMeter; var releaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) comp.WindupTime.TotalSeconds * EyeManager.PixelsPerMeter;
var releaseMiddle = (endX - startX) / 2f + startX; const float releaseMiddle = (endX - startX) / 2f + startX;
var releaseBox = new Box2(new Vector2(releaseMiddle - ReleaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter, var releaseBox = new Box2(new Vector2(releaseMiddle - releaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter,
new Vector2(releaseMiddle + ReleaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter); new Vector2(releaseMiddle + releaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter);
releaseBox = releaseBox.Translated(position); releaseBox = releaseBox.Translated(position);
handle.DrawRect(releaseBox, Color.LimeGreen); handle.DrawRect(releaseBox, Color.LimeGreen);
@@ -131,11 +129,11 @@ public sealed class MeleeWindupOverlay : Overlay
var xPos = (endX - startX) * fraction + startX; var xPos = (endX - startX) * fraction + startX;
// In pixels // In pixels
const float Width = 2f; const float width = 2f;
// If we hit the end we won't draw half the box so we need to subtract the end pos from it // If we hit the end we won't draw half the box so we need to subtract the end pos from it
var endPos = xPos + Width / 2f; var endPos = xPos + width / 2f;
var box = new Box2(new Vector2(Math.Max(startX, endPos - Width), 3f) / EyeManager.PixelsPerMeter, var box = new Box2(new Vector2(Math.Max(startX, endPos - width), 3f) / EyeManager.PixelsPerMeter,
new Vector2(Math.Min(endX, endPos), 4f) / EyeManager.PixelsPerMeter); new Vector2(Math.Min(endX, endPos), 4f) / EyeManager.PixelsPerMeter);
box = box.Translated(position); box = box.Translated(position);

View File

@@ -124,7 +124,7 @@ public sealed partial class NPCSteeringSystem
// Breaking behaviours and the likes. // Breaking behaviours and the likes.
lock (_obstacles) lock (_obstacles)
{ {
status = TryHandleFlags(steering, node, bodyQuery); status = TryHandleFlags(uid, steering, node, bodyQuery);
} }
// TODO: Need to handle re-pathing in case the target moves around. // TODO: Need to handle re-pathing in case the target moves around.

View File

@@ -32,7 +32,7 @@ public sealed partial class NPCSteeringSystem
*/ */
private SteeringObstacleStatus TryHandleFlags(NPCSteeringComponent component, PathPoly poly, EntityQuery<PhysicsComponent> bodyQuery) private SteeringObstacleStatus TryHandleFlags(EntityUid uid, NPCSteeringComponent component, PathPoly poly, EntityQuery<PhysicsComponent> bodyQuery)
{ {
DebugTools.Assert(!poly.Data.IsFreeSpace); DebugTools.Assert(!poly.Data.IsFreeSpace);
// TODO: Store PathFlags on the steering comp // TODO: Store PathFlags on the steering comp
@@ -41,9 +41,9 @@ public sealed partial class NPCSteeringSystem
var layer = 0; var layer = 0;
var mask = 0; var mask = 0;
if (TryComp<FixturesComponent>(component.Owner, out var manager)) if (TryComp<FixturesComponent>(uid, out var manager))
{ {
(layer, mask) = _physics.GetHardCollision(component.Owner, manager); (layer, mask) = _physics.GetHardCollision(uid, manager);
} }
else else
{ {
@@ -76,7 +76,7 @@ public sealed partial class NPCSteeringSystem
{ {
if (door.State != DoorState.Opening) if (door.State != DoorState.Opening)
{ {
_interaction.InteractionActivate(component.Owner, ent); _interaction.InteractionActivate(uid, ent);
return SteeringObstacleStatus.Continuing; return SteeringObstacleStatus.Continuing;
} }
} }
@@ -100,7 +100,7 @@ public sealed partial class NPCSteeringSystem
{ {
// TODO: Use the verb. // TODO: Use the verb.
if (door.State != DoorState.Opening && !door.BeingPried) if (door.State != DoorState.Opening && !door.BeingPried)
_doors.TryPryDoor(ent, component.Owner, component.Owner, door, true); _doors.TryPryDoor(ent, uid, uid, door, true);
return SteeringObstacleStatus.Continuing; return SteeringObstacleStatus.Continuing;
} }
@@ -112,9 +112,7 @@ public sealed partial class NPCSteeringSystem
// Try smashing obstacles. // Try smashing obstacles.
else if ((component.Flags & PathFlags.Smashing) != 0x0) else if ((component.Flags & PathFlags.Smashing) != 0x0)
{ {
var meleeWeapon = _melee.GetWeapon(component.Owner); if (_melee.TryGetWeapon(uid, out var meleeUid, out var meleeWeapon) && meleeWeapon.NextAttack <= _timing.CurTime && TryComp<CombatModeComponent>(uid, out var combatMode))
if (meleeWeapon != null && meleeWeapon.NextAttack <= _timing.CurTime && TryComp<CombatModeComponent>(component.Owner, out var combatMode))
{ {
combatMode.IsInCombatMode = true; combatMode.IsInCombatMode = true;
var destructibleQuery = GetEntityQuery<DestructibleComponent>(); var destructibleQuery = GetEntityQuery<DestructibleComponent>();
@@ -127,7 +125,7 @@ public sealed partial class NPCSteeringSystem
// TODO: Validate we can damage it // TODO: Validate we can damage it
if (destructibleQuery.HasComponent(ent)) if (destructibleQuery.HasComponent(ent))
{ {
_melee.AttemptLightAttack(component.Owner, component.Owner, meleeWeapon, ent); _melee.AttemptLightAttack(uid, uid, meleeWeapon, ent);
break; break;
} }
} }

View File

@@ -236,7 +236,7 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
return; return;
} }
var hitBloodstreams = new List<BloodstreamComponent>(); var hitBloodstreams = new List<(EntityUid Entity, BloodstreamComponent Component)>();
var bloodQuery = GetEntityQuery<BloodstreamComponent>(); var bloodQuery = GetEntityQuery<BloodstreamComponent>();
foreach (var entity in args.HitEntities) foreach (var entity in args.HitEntities)
@@ -245,7 +245,7 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
continue; continue;
if (bloodQuery.TryGetComponent(entity, out var bloodstream)) if (bloodQuery.TryGetComponent(entity, out var bloodstream))
hitBloodstreams.Add(bloodstream); hitBloodstreams.Add((entity, bloodstream));
} }
if (!hitBloodstreams.Any()) if (!hitBloodstreams.Any())
@@ -256,10 +256,10 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
var solutionToInject = removedSolution.SplitSolution(removedVol * comp.TransferEfficiency); var solutionToInject = removedSolution.SplitSolution(removedVol * comp.TransferEfficiency);
var volPerBloodstream = solutionToInject.Volume * (1 / hitBloodstreams.Count); var volPerBloodstream = solutionToInject.Volume * (1 / hitBloodstreams.Count);
foreach (var bloodstream in hitBloodstreams) foreach (var (ent, bloodstream) in hitBloodstreams)
{ {
var individualInjection = solutionToInject.SplitSolution(volPerBloodstream); var individualInjection = solutionToInject.SplitSolution(volPerBloodstream);
_bloodstream.TryAddToChemicals((bloodstream).Owner, individualInjection, bloodstream); _bloodstream.TryAddToChemicals(ent, individualInjection, bloodstream);
} }
} }
} }

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
@@ -34,13 +35,13 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!; [Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
[Dependency] protected readonly ActionBlockerSystem Blocker = default!; [Dependency] protected readonly ActionBlockerSystem Blocker = default!;
[Dependency] protected readonly DamageableSystem Damageable = default!; [Dependency] protected readonly DamageableSystem Damageable = default!;
[Dependency] protected readonly InventorySystem Inventory = default!; [Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!; [Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] protected readonly SharedCombatModeSystem CombatMode = default!; [Dependency] protected readonly SharedCombatModeSystem CombatMode = default!;
[Dependency] protected readonly SharedInteractionSystem Interaction = default!; [Dependency] protected readonly SharedInteractionSystem Interaction = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] protected readonly SharedPopupSystem PopupSystem = default!; [Dependency] protected readonly SharedPopupSystem PopupSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] protected readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly StaminaSystem _stamina = default!; [Dependency] private readonly StaminaSystem _stamina = default!;
protected ISawmill Sawmill = default!; protected ISawmill Sawmill = default!;
@@ -106,10 +107,11 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (user == null) if (user == null)
return; return;
var weapon = GetWeapon(user.Value); if (!TryGetWeapon(user.Value, out var weaponUid, out var weapon) ||
weaponUid != msg.Weapon)
if (weapon?.Owner != msg.Weapon) {
return; return;
}
if (!weapon.Attacking) if (!weapon.Attacking)
return; return;
@@ -125,10 +127,11 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (user == null) if (user == null)
return; return;
var weapon = GetWeapon(user.Value); if (!TryGetWeapon(user.Value, out var weaponUid, out var weapon) ||
weaponUid != msg.Weapon)
if (weapon?.Owner != msg.Weapon) {
return; return;
}
DebugTools.Assert(weapon.WindUpStart == null); DebugTools.Assert(weapon.WindUpStart == null);
weapon.WindUpStart = Timing.CurTime; weapon.WindUpStart = Timing.CurTime;
@@ -144,26 +147,27 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (user == null) if (user == null)
return; return;
var weapon = GetWeapon(user.Value); if (!TryGetWeapon(user.Value, out var weaponUid, out var weapon) ||
weaponUid != msg.Weapon)
if (weapon?.Owner != msg.Weapon) {
return; return;
}
AttemptAttack(args.SenderSession.AttachedEntity!.Value, msg.Weapon, weapon, msg, args.SenderSession); AttemptAttack(args.SenderSession.AttachedEntity!.Value, msg.Weapon, weapon, msg, args.SenderSession);
} }
private void OnStopHeavyAttack(StopHeavyAttackEvent msg, EntitySessionEventArgs args) private void OnStopHeavyAttack(StopHeavyAttackEvent msg, EntitySessionEventArgs args)
{ {
if (args.SenderSession.AttachedEntity == null || if (args.SenderSession.AttachedEntity == null)
!TryComp<MeleeWeaponComponent>(msg.Weapon, out var weapon))
{ {
return; return;
} }
var userWeapon = GetWeapon(args.SenderSession.AttachedEntity.Value); if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon) ||
weaponUid != msg.Weapon)
if (userWeapon != weapon) {
return; return;
}
if (weapon.WindUpStart.Equals(null)) if (weapon.WindUpStart.Equals(null))
{ {
@@ -176,16 +180,16 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
private void OnHeavyAttack(HeavyAttackEvent msg, EntitySessionEventArgs args) private void OnHeavyAttack(HeavyAttackEvent msg, EntitySessionEventArgs args)
{ {
if (args.SenderSession.AttachedEntity == null || if (args.SenderSession.AttachedEntity == null)
!TryComp<MeleeWeaponComponent>(msg.Weapon, out var weapon))
{ {
return; return;
} }
var userWeapon = GetWeapon(args.SenderSession.AttachedEntity.Value); if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon) ||
weaponUid != msg.Weapon)
if (userWeapon != weapon) {
return; return;
}
AttemptAttack(args.SenderSession.AttachedEntity.Value, msg.Weapon, weapon, msg, args.SenderSession); AttemptAttack(args.SenderSession.AttachedEntity.Value, msg.Weapon, weapon, msg, args.SenderSession);
} }
@@ -197,12 +201,12 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return; return;
} }
var userWeapon = GetWeapon(args.SenderSession.AttachedEntity.Value); if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon))
{
if (userWeapon == null)
return; return;
}
AttemptAttack(args.SenderSession.AttachedEntity.Value, userWeapon.Owner, userWeapon, msg, args.SenderSession); AttemptAttack(args.SenderSession.AttachedEntity.Value, weaponUid, weapon, msg, args.SenderSession);
} }
private void OnGetState(EntityUid uid, MeleeWeaponComponent component, ref ComponentGetState args) private void OnGetState(EntityUid uid, MeleeWeaponComponent component, ref ComponentGetState args)
@@ -226,15 +230,22 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
component.Range = state.Range; component.Range = state.Range;
} }
public MeleeWeaponComponent? GetWeapon(EntityUid entity) public bool TryGetWeapon(EntityUid entity, out EntityUid weaponUid, [NotNullWhen(true)] out MeleeWeaponComponent? melee)
{ {
MeleeWeaponComponent? melee; weaponUid = default;
melee = null;
var ev = new GetMeleeWeaponEvent(); var ev = new GetMeleeWeaponEvent();
RaiseLocalEvent(entity, ev); RaiseLocalEvent(entity, ev);
if (ev.Handled) if (ev.Handled)
{ {
return EntityManager.GetComponentOrNull<MeleeWeaponComponent>(ev.Weapon); if (TryComp(ev.Weapon, out melee))
{
weaponUid = ev.Weapon.Value;
return true;
}
return false;
} }
// Use inhands entity if we got one. // Use inhands entity if we got one.
@@ -243,26 +254,30 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
{ {
if (EntityManager.TryGetComponent(held, out melee)) if (EntityManager.TryGetComponent(held, out melee))
{ {
return melee; weaponUid = held;
return true;
} }
return null; return false;
} }
// Use hands clothing if applicable. // Use hands clothing if applicable.
if (Inventory.TryGetSlotEntity(entity, "gloves", out var gloves) && if (_inventory.TryGetSlotEntity(entity, "gloves", out var gloves) &&
TryComp<MeleeWeaponComponent>(gloves, out var glovesMelee)) TryComp<MeleeWeaponComponent>(gloves, out var glovesMelee))
{ {
return glovesMelee; weaponUid = gloves.Value;
melee = glovesMelee;
return true;
} }
// Use our own melee // Use our own melee
if (TryComp(entity, out melee)) if (TryComp(entity, out melee))
{ {
return melee; weaponUid = entity;
return true;
} }
return null; return false;
} }
public void AttemptLightAttackMiss(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, EntityCoordinates coordinates) public void AttemptLightAttackMiss(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, EntityCoordinates coordinates)
@@ -345,7 +360,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
throw new NotImplementedException(); throw new NotImplementedException();
} }
DoLungeAnimation(user, weapon.Angle, attack.Coordinates.ToMap(EntityManager), weapon.Range, animation); DoLungeAnimation(user, weapon.Angle, attack.Coordinates.ToMap(EntityManager, _transform), weapon.Range, animation);
weapon.Attacking = true; weapon.Attacking = true;
Dirty(weapon); Dirty(weapon);
} }
@@ -441,7 +456,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
// If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor // If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor
if (damageResult.DamageDict.TryGetValue("Blunt", out var bluntDamage)) if (damageResult.DamageDict.TryGetValue("Blunt", out var bluntDamage))
{ {
_stamina.TakeStaminaDamage(ev.Target.Value, (bluntDamage * component.BluntStaminaDamageFactor).Float(), source:user, with:(component.Owner == user ? null : component.Owner)); _stamina.TakeStaminaDamage(ev.Target.Value, (bluntDamage * component.BluntStaminaDamageFactor).Float(), source:user, with:meleeUid == user ? null : meleeUid);
} }
if (meleeUid == user) if (meleeUid == user)
@@ -452,7 +467,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
else else
{ {
AdminLogger.Add(LogType.MeleeHit, AdminLogger.Add(LogType.MeleeHit,
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(ev.Target.Value):target} using {ToPrettyString(component.Owner):used} and dealt {damageResult.Total:damage} damage"); $"{ToPrettyString(user):user} melee attacked {ToPrettyString(ev.Target.Value):target} using {ToPrettyString(meleeUid):used} and dealt {damageResult.Total:damage} damage");
} }
PlayHitSound(ev.Target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound); PlayHitSound(ev.Target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
@@ -489,7 +504,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return; return;
} }
var targetMap = ev.Coordinates.ToMap(EntityManager); var targetMap = ev.Coordinates.ToMap(EntityManager, _transform);
if (targetMap.MapId != userXform.MapID) if (targetMap.MapId != userXform.MapID)
{ {
@@ -570,7 +585,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
else else
{ {
AdminLogger.Add(LogType.MeleeHit, AdminLogger.Add(LogType.MeleeHit,
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(entity):target} using {ToPrettyString(component.Owner):used} and dealt {damageResult.Total:damage} damage"); $"{ToPrettyString(user):user} melee attacked {ToPrettyString(entity):target} using {ToPrettyString(meleeUid):used} and dealt {damageResult.Total:damage} damage");
} }
} }
} }
@@ -729,7 +744,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (!TryComp<TransformComponent>(user, out var userXform)) if (!TryComp<TransformComponent>(user, out var userXform))
return; return;
var invMatrix = userXform.InvWorldMatrix; var invMatrix = _transform.GetInvWorldMatrix(userXform);
var localPos = invMatrix.Transform(coordinates.Position); var localPos = invMatrix.Transform(coordinates.Position);
if (localPos.LengthSquared <= 0f) if (localPos.LengthSquared <= 0f)
@@ -738,8 +753,8 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
localPos = userXform.LocalRotation.RotateVec(localPos); localPos = userXform.LocalRotation.RotateVec(localPos);
// We'll play the effect just short visually so it doesn't look like we should be hitting but actually aren't. // We'll play the effect just short visually so it doesn't look like we should be hitting but actually aren't.
const float BufferLength = 0.2f; const float bufferLength = 0.2f;
var visualLength = length - BufferLength; var visualLength = length - bufferLength;
if (localPos.Length > visualLength) if (localPos.Length > visualLength)
localPos = localPos.Normalized * visualLength; localPos = localPos.Normalized * visualLength;