2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Actions;
|
|
|
|
|
using Content.Shared.Actions.ActionTypes;
|
|
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Targeting;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2019-09-26 22:32:32 +02:00
|
|
|
using Robust.Shared.Serialization;
|
2022-04-14 16:17:34 +12:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.CombatMode
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2019-09-26 22:32:32 +02:00
|
|
|
public abstract class SharedCombatModeComponent : Component
|
|
|
|
|
{
|
2020-03-25 11:16:57 +01:00
|
|
|
private bool _isInCombatMode;
|
|
|
|
|
private TargetingZone _activeZone;
|
|
|
|
|
|
2022-02-26 18:24:08 +13:00
|
|
|
[DataField("disarmFailChance")]
|
2022-06-17 01:37:07 -04:00
|
|
|
public readonly float BaseDisarmFailChance = 0.4f;
|
2022-02-26 18:24:08 +13:00
|
|
|
|
|
|
|
|
[DataField("pushChance")]
|
2022-06-17 01:37:07 -04:00
|
|
|
public readonly float BasePushFailChance = 0.4f;
|
2022-02-26 18:24:08 +13:00
|
|
|
|
|
|
|
|
[DataField("disarmFailSound")]
|
|
|
|
|
public readonly SoundSpecifier DisarmFailSound = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
|
|
|
|
|
|
|
|
|
|
[DataField("disarmSuccessSound")]
|
|
|
|
|
public readonly SoundSpecifier DisarmSuccessSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
|
|
|
|
|
|
2022-04-14 16:17:34 +12:00
|
|
|
[DataField("disarmActionId", customTypeSerializer:typeof(PrototypeIdSerializer<EntityTargetActionPrototype>))]
|
|
|
|
|
public readonly string DisarmActionId = "Disarm";
|
|
|
|
|
|
2022-04-30 18:29:13 -03:00
|
|
|
[DataField("canDisarm")]
|
|
|
|
|
public bool CanDisarm;
|
|
|
|
|
|
2022-04-14 16:17:34 +12:00
|
|
|
[DataField("disarmAction")] // must be a data-field to properly save cooldown when saving game state.
|
|
|
|
|
public EntityTargetAction? DisarmAction;
|
|
|
|
|
|
|
|
|
|
[DataField("combatToggleActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
|
|
|
|
public readonly string CombatToggleActionId = "CombatModeToggle";
|
2022-02-26 18:24:08 +13:00
|
|
|
|
|
|
|
|
[DataField("combatToggleAction")]
|
2022-04-14 16:17:34 +12:00
|
|
|
public InstantAction? CombatToggleAction;
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2020-03-25 11:16:57 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public virtual bool IsInCombatMode
|
|
|
|
|
{
|
|
|
|
|
get => _isInCombatMode;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (_isInCombatMode == value) return;
|
2020-03-25 11:16:57 +01:00
|
|
|
_isInCombatMode = value;
|
2022-04-14 16:17:34 +12:00
|
|
|
if (CombatToggleAction != null)
|
|
|
|
|
EntitySystem.Get<SharedActionsSystem>().SetToggled(CombatToggleAction, _isInCombatMode);
|
2020-03-25 11:16:57 +01:00
|
|
|
Dirty();
|
2021-03-08 04:09:59 +11:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
*/
|
2020-03-25 11:16:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public virtual TargetingZone ActiveZone
|
|
|
|
|
{
|
|
|
|
|
get => _activeZone;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (_activeZone == value) return;
|
2020-03-25 11:16:57 +01:00
|
|
|
_activeZone = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 04:12:09 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-03-25 11:16:57 +01:00
|
|
|
{
|
|
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
|
2020-11-26 14:33:31 +01:00
|
|
|
if (curState is not CombatModeComponentState state)
|
2020-03-25 11:16:57 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
IsInCombatMode = state.IsInCombatMode;
|
|
|
|
|
ActiveZone = state.TargetingZone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2020-03-25 11:16:57 +01:00
|
|
|
{
|
|
|
|
|
return new CombatModeComponentState(IsInCombatMode, ActiveZone);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 22:32:32 +02:00
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|