Melee refactor (#10897)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-09-29 15:51:59 +10:00
committed by GitHub
parent c583b7b361
commit f51248ecaa
140 changed files with 2440 additions and 1824 deletions

View File

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