ECS guns (#6229)
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,6 @@ using Content.Client.IoC;
|
||||
using Content.Client.Items.Components;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Weapons.Ranged;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.Graphics;
|
||||
@@ -13,8 +12,6 @@ using Robust.Shared.Animations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
@@ -104,18 +101,9 @@ namespace Content.Client.Weapons.Ranged.Barrels.Components
|
||||
_statusControl?.Update();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||
public void PlayAlarmAnimation()
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
|
||||
case MagazineAutoEjectMessage _:
|
||||
_statusControl?.PlayAlarmAnimation();
|
||||
return;
|
||||
}
|
||||
_statusControl?.PlayAlarmAnimation();
|
||||
}
|
||||
|
||||
public Control MakeControl()
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Content.Client.Weapons.Ranged
|
||||
[RegisterComponent]
|
||||
public sealed class ClientRangedWeaponComponent : SharedRangedWeaponComponent
|
||||
{
|
||||
public FireRateSelector FireRateSelector { get; private set; } = FireRateSelector.Safety;
|
||||
public FireRateSelector FireRateSelector { get; private set; } = FireRateSelector.Automatic;
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
@@ -30,12 +30,5 @@ namespace Content.Client.Weapons.Ranged
|
||||
|
||||
FireRateSelector = rangedState.FireRateSelector;
|
||||
}
|
||||
|
||||
public void SyncFirePos(GridId targetGrid, Vector2 targetPosition)
|
||||
{
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new FirePosComponentMessage(targetGrid, targetPosition));
|
||||
#pragma warning restore 618
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
Content.Client/Weapons/Ranged/GunSystem.AmmoCounter.cs
Normal file
31
Content.Client/Weapons/Ranged/GunSystem.AmmoCounter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Content.Client.Weapons.Ranged.Barrels.Components;
|
||||
using Content.Shared.Weapons.Ranged;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Weapons.Ranged;
|
||||
|
||||
public sealed class GunSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<MagazineAutoEjectEvent>(OnMagAutoEject);
|
||||
}
|
||||
|
||||
private void OnMagAutoEject(MagazineAutoEjectEvent ev)
|
||||
{
|
||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (!TryComp(ev.Uid, out ClientMagazineBarrelComponent? mag) ||
|
||||
!_container.TryGetContainingContainer(ev.Uid, out var container) ||
|
||||
container.Owner != player) return;
|
||||
|
||||
mag.PlayAlarmAnimation();
|
||||
}
|
||||
}
|
||||
@@ -85,20 +85,26 @@ namespace Content.Client.Weapons.Ranged
|
||||
}
|
||||
|
||||
if (_blocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
var mapCoordinates = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
EntityCoordinates coordinates;
|
||||
|
||||
if (!_mapManager.TryFindGridAt(worldPos, out var grid))
|
||||
if (_mapManager.TryFindGridAt(mapCoordinates, out var grid))
|
||||
{
|
||||
weapon.SyncFirePos(GridId.Invalid, worldPos.Position);
|
||||
coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mapCoordinates);
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.SyncFirePos(grid.Index, grid.MapToGrid(worldPos).Position);
|
||||
coordinates = EntityCoordinates.FromMap(_mapManager.GetMapEntityId(mapCoordinates.MapId), mapCoordinates);
|
||||
}
|
||||
|
||||
SyncFirePos(coordinates);
|
||||
}
|
||||
|
||||
private void SyncFirePos(EntityCoordinates coordinates)
|
||||
{
|
||||
RaiseNetworkEvent(new FirePosEvent(coordinates));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user