Melee refactor (#10897)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -15,16 +15,5 @@ namespace Content.Shared.CombatMode
|
||||
|
||||
public TargetingZone TargetZone { get; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class SetCombatModeActiveMessage : EntityEventArgs
|
||||
{
|
||||
public SetCombatModeActiveMessage(bool active)
|
||||
{
|
||||
Active = active;
|
||||
}
|
||||
|
||||
public bool Active { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Content.Shared.Actions;
|
||||
|
||||
namespace Content.Shared.CombatMode;
|
||||
|
||||
public sealed class TogglePrecisionModeEvent : InstantActionEvent
|
||||
{
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Actions;
|
||||
|
||||
namespace Content.Shared.CombatMode.Pacification
|
||||
@@ -18,11 +17,9 @@ namespace Content.Shared.CombatMode.Pacification
|
||||
if (!TryComp<SharedCombatModeComponent>(uid, out var combatMode))
|
||||
return;
|
||||
|
||||
if (combatMode.DisarmAction != null)
|
||||
{
|
||||
_actionsSystem.SetToggled(combatMode.DisarmAction, false);
|
||||
_actionsSystem.SetEnabled(combatMode.DisarmAction, false);
|
||||
}
|
||||
if (combatMode.CanDisarm != null)
|
||||
combatMode.CanDisarm = false;
|
||||
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
{
|
||||
combatMode.IsInCombatMode = false;
|
||||
@@ -35,8 +32,8 @@ namespace Content.Shared.CombatMode.Pacification
|
||||
if (!TryComp<SharedCombatModeComponent>(uid, out var combatMode))
|
||||
return;
|
||||
|
||||
if (combatMode.DisarmAction != null)
|
||||
_actionsSystem.SetEnabled(combatMode.DisarmAction, true);
|
||||
if (combatMode.CanDisarm != null)
|
||||
combatMode.CanDisarm = true;
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleAction, true);
|
||||
}
|
||||
|
||||
@@ -5,17 +5,21 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.CombatMode
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedCombatModeComponent : Component
|
||||
{
|
||||
private bool _isInCombatMode;
|
||||
private TargetingZone _activeZone;
|
||||
#region Disarm
|
||||
|
||||
[DataField("disarmFailChance")]
|
||||
public readonly float BaseDisarmFailChance = 0.75f;
|
||||
/// <summary>
|
||||
/// Whether we are able to disarm. This requires our active hand to be free.
|
||||
/// False if it's toggled off for whatever reason, null if it's not possible.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("disarm")]
|
||||
public bool? CanDisarm;
|
||||
|
||||
[DataField("disarmFailSound")]
|
||||
public readonly SoundSpecifier DisarmFailSound = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
|
||||
@@ -23,14 +27,13 @@ namespace Content.Shared.CombatMode
|
||||
[DataField("disarmSuccessSound")]
|
||||
public readonly SoundSpecifier DisarmSuccessSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
|
||||
|
||||
[DataField("disarmActionId", customTypeSerializer:typeof(PrototypeIdSerializer<EntityTargetActionPrototype>))]
|
||||
public readonly string DisarmActionId = "Disarm";
|
||||
[DataField("disarmFailChance")]
|
||||
public readonly float BaseDisarmFailChance = 0.75f;
|
||||
|
||||
[DataField("canDisarm")]
|
||||
public bool CanDisarm;
|
||||
#endregion
|
||||
|
||||
[DataField("disarmAction")] // must be a data-field to properly save cooldown when saving game state.
|
||||
public EntityTargetAction? DisarmAction;
|
||||
private bool _isInCombatMode;
|
||||
private TargetingZone _activeZone;
|
||||
|
||||
[DataField("combatToggleActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public readonly string CombatToggleActionId = "CombatModeToggle";
|
||||
@@ -49,19 +52,6 @@ namespace Content.Shared.CombatMode
|
||||
if (CombatToggleAction != null)
|
||||
EntitySystem.Get<SharedActionsSystem>().SetToggled(CombatToggleAction, _isInCombatMode);
|
||||
Dirty();
|
||||
|
||||
// Regenerate physics contacts -> Can probably just selectively check
|
||||
/* Still a bit jank so left disabled for now.
|
||||
if (Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
physicsComponent.WakeBody();
|
||||
}
|
||||
|
||||
physicsComponent.RegenerateContacts();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,35 +66,5 @@ namespace Content.Shared.CombatMode
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not CombatModeComponentState state)
|
||||
return;
|
||||
|
||||
IsInCombatMode = state.IsInCombatMode;
|
||||
ActiveZone = state.TargetingZone;
|
||||
}
|
||||
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new CombatModeComponentState(IsInCombatMode, ActiveZone);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class CombatModeComponentState : ComponentState
|
||||
{
|
||||
public bool IsInCombatMode { get; }
|
||||
public TargetingZone TargetingZone { get; }
|
||||
|
||||
public CombatModeComponentState(bool isInCombatMode, TargetingZone targetingZone)
|
||||
{
|
||||
IsInCombatMode = isInCombatMode;
|
||||
TargetingZone = targetingZone;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Targeting;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.CombatMode
|
||||
{
|
||||
public abstract class SharedCombatModeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<CombatModeSystemMessages.SetCombatModeActiveMessage>(CombatModeActiveHandler);
|
||||
SubscribeLocalEvent<CombatModeSystemMessages.SetCombatModeActiveMessage>(CombatModeActiveHandler);
|
||||
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
|
||||
@@ -31,30 +30,17 @@ namespace Content.Shared.CombatMode
|
||||
|
||||
if (component.CombatToggleAction != null)
|
||||
_actionsSystem.AddAction(uid, component.CombatToggleAction, null);
|
||||
|
||||
if (component.DisarmAction == null
|
||||
&& component.CanDisarm
|
||||
&& _protoMan.TryIndex(component.DisarmActionId, out EntityTargetActionPrototype? disarmProto))
|
||||
{
|
||||
component.DisarmAction = new(disarmProto);
|
||||
}
|
||||
|
||||
if (component.DisarmAction != null && component.CanDisarm)
|
||||
_actionsSystem.AddAction(uid, component.DisarmAction, null);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, SharedCombatModeComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (component.CombatToggleAction != null)
|
||||
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
|
||||
|
||||
if (component.DisarmAction != null)
|
||||
_actionsSystem.RemoveAction(uid, component.DisarmAction);
|
||||
}
|
||||
|
||||
public bool IsInCombatMode(EntityUid entity)
|
||||
public bool IsInCombatMode(EntityUid? entity, SharedCombatModeComponent? component = null)
|
||||
{
|
||||
return TryComp<SharedCombatModeComponent>(entity, out var combatMode) && combatMode.IsInCombatMode;
|
||||
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInCombatMode;
|
||||
}
|
||||
|
||||
private void OnActionPerform(EntityUid uid, SharedCombatModeComponent component, ToggleCombatActionEvent args)
|
||||
@@ -66,17 +52,19 @@ namespace Content.Shared.CombatMode
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void CombatModeActiveHandler(CombatModeSystemMessages.SetCombatModeActiveMessage ev, EntitySessionEventArgs eventArgs)
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class CombatModeComponentState : ComponentState
|
||||
{
|
||||
var entity = eventArgs.SenderSession.AttachedEntity;
|
||||
public bool IsInCombatMode { get; }
|
||||
public TargetingZone TargetingZone { get; }
|
||||
|
||||
if (entity == null || !EntityManager.TryGetComponent(entity, out SharedCombatModeComponent? combatModeComponent))
|
||||
return;
|
||||
|
||||
combatModeComponent.IsInCombatMode = ev.Active;
|
||||
public CombatModeComponentState(bool isInCombatMode, TargetingZone targetingZone)
|
||||
{
|
||||
IsInCombatMode = isInCombatMode;
|
||||
TargetingZone = targetingZone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ToggleCombatActionEvent : InstantActionEvent { }
|
||||
public sealed class DisarmActionEvent : EntityTargetActionEvent { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user