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;
}
var weapon = _melee.GetWeapon(player.Value);
if (weapon == null)
if (!_melee.TryGetWeapon(player.Value, out _, out var weapon))
return;
var mousePos = _inputManager.MouseScreenPosition;

View File

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

View File

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

View File

@@ -44,9 +44,7 @@ public sealed class MeleeWindupOverlay : Overlay
return;
}
var comp = _melee.GetWeapon(owner.Value);
if (comp == null)
if (!_melee.TryGetWeapon(owner.Value, out var meleeUid, out var comp))
return;
var handle = args.WorldHandle;
@@ -67,7 +65,7 @@ public sealed class MeleeWindupOverlay : Overlay
return;
}
if (!xformQuery.TryGetComponent(comp.Owner, out var xform) ||
if (!xformQuery.TryGetComponent(meleeUid, out var xform) ||
xform.MapID != args.MapId)
{
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
// by the bar.
float yOffset;
if (spriteQuery.TryGetComponent(comp.Owner, out var sprite))
if (spriteQuery.TryGetComponent(meleeUid, out var sprite))
{
yOffset = -sprite.Bounds.Height / 2f - 0.05f;
}
@@ -106,11 +104,11 @@ public sealed class MeleeWindupOverlay : Overlay
const float endX = 22f;
// Area marking where to release
var ReleaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) comp.WindupTime.TotalSeconds * EyeManager.PixelsPerMeter;
var releaseMiddle = (endX - startX) / 2f + startX;
var releaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) comp.WindupTime.TotalSeconds * EyeManager.PixelsPerMeter;
const float releaseMiddle = (endX - startX) / 2f + startX;
var releaseBox = new Box2(new Vector2(releaseMiddle - ReleaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter,
new Vector2(releaseMiddle + ReleaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter);
var releaseBox = new Box2(new Vector2(releaseMiddle - releaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter,
new Vector2(releaseMiddle + releaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter);
releaseBox = releaseBox.Translated(position);
handle.DrawRect(releaseBox, Color.LimeGreen);
@@ -131,11 +129,11 @@ public sealed class MeleeWindupOverlay : Overlay
var xPos = (endX - startX) * fraction + startX;
// 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
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);
box = box.Translated(position);