Re-add action prototypes (#7508)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-04-14 16:17:34 +12:00
committed by GitHub
parent c30b38a476
commit ba75934512
34 changed files with 291 additions and 189 deletions

View File

@@ -20,7 +20,7 @@ namespace Content.Server.Atmos.EntitySystems
{
base.Initialize();
SubscribeLocalEvent<GasTankComponent, BeforeActivatableUIOpenEvent>(BeforeUiOpen);
SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions);
SubscribeLocalEvent<GasTankComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<GasTankComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
SubscribeLocalEvent<GasTankComponent, DroppedEvent>(OnDropped);
@@ -37,7 +37,7 @@ namespace Content.Server.Atmos.EntitySystems
component.DisconnectFromInternals(args.User);
}
private void OnGetActions(EntityUid uid, GasTankComponent component, GetActionsEvent args)
private void OnGetActions(EntityUid uid, GasTankComponent component, GetItemActionsEvent args)
{
args.Actions.Add(component.ToggleAction);
}

View File

@@ -29,5 +29,5 @@ namespace Content.Server.Ghost.Components
};
}
public sealed class BooActionEvent : PerformActionEvent { }
public sealed class BooActionEvent : InstantActionEvent { }
}

View File

@@ -36,5 +36,5 @@ namespace Content.Server.Guardian
};
}
public sealed class GuardianToggleActionEvent : PerformActionEvent { };
public sealed class GuardianToggleActionEvent : InstantActionEvent { };
}

View File

@@ -3,6 +3,7 @@ using Content.Server.Light.Components;
using Content.Server.Popups;
using Content.Server.PowerCell;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Light.Component;
@@ -14,6 +15,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Light.EntitySystems
@@ -24,6 +26,7 @@ namespace Content.Server.Light.EntitySystems
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly ActionsSystem _actionSystem = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
// TODO: Ideally you'd be able to subscribe to power stuff to get events at certain percentages.. or something?
// But for now this will be better anyway.
@@ -42,13 +45,20 @@ namespace Content.Server.Light.EntitySystems
SubscribeLocalEvent<HandheldLightComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<HandheldLightComponent, GetActionsEvent>(OnGetActions);
SubscribeLocalEvent<HandheldLightComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<HandheldLightComponent, ToggleActionEvent>(OnToggleAction);
}
private void OnGetActions(EntityUid uid, HandheldLightComponent component, GetActionsEvent args)
private void OnGetActions(EntityUid uid, HandheldLightComponent component, GetItemActionsEvent args)
{
args.Actions.Add(component.ToggleAction);
if (component.ToggleAction == null
&& _proto.TryIndex(component.ToggleActionId, out InstantActionPrototype? act))
{
component.ToggleAction = new(act);
}
if (component.ToggleAction != null)
args.Actions.Add(component.ToggleAction);
}
private void OnToggleAction(EntityUid uid, HandheldLightComponent component, ToggleActionEvent args)
@@ -169,7 +179,8 @@ namespace Content.Server.Light.EntitySystems
if (!component.Activated) return false;
component.Activated = false;
_actionSystem.SetToggled(component.ToggleAction, false);
if (component.ToggleAction != null)
_actionSystem.SetToggled(component.ToggleAction, false);
_activeLights.Remove(component);
component.LastLevel = null;
component.Dirty(EntityManager);
@@ -202,7 +213,8 @@ namespace Content.Server.Light.EntitySystems
}
component.Activated = true;
_actionSystem.SetToggled(component.ToggleAction, true);
if (component.ToggleAction != null)
_actionSystem.SetToggled(component.ToggleAction, true);
_activeLights.Add(component);
component.LastLevel = GetLevel(component);
Dirty(component);

View File

@@ -19,7 +19,7 @@ namespace Content.Server.Light.EntitySystems
base.Initialize();
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetActionsEvent>(OnGetActions);
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
}
@@ -33,7 +33,7 @@ namespace Content.Server.Light.EntitySystems
args.Handled = true;
}
private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetActionsEvent args)
private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetItemActionsEvent args)
{
args.Actions.Add(component.ToggleAction);
}

View File

@@ -2,8 +2,7 @@ using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.Utility;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Speech.Components;
@@ -25,19 +24,16 @@ public sealed class VocalComponent : Component
[DataField("audioParams")]
public AudioParams AudioParams = AudioParams.Default.WithVolume(4f);
[DataField("wilhelmProbability")]
public float WilhelmProbability = 0.01f;
public const float Variation = 0.125f;
// Not using the in-build sound support for actions, given that the sound is modified non-prototype specific factors like gender.
[DataField("action")]
public InstantAction Action = new()
{
UseDelay = TimeSpan.FromSeconds(10),
Icon = new SpriteSpecifier.Texture(new ResourcePath("Interface/Actions/scream.png")),
Name = "action-name-scream",
Description = "AAAAAAAAAAAAAAAAAAAAAAAAA",
Event = new ScreamActionEvent(),
CheckCanInteract = false, // system checks a speech related action blocker.
};
[DataField("actionId", customTypeSerializer:typeof(PrototypeIdSerializer<InstantActionPrototype>))]
public string ActionId = "Scream";
[DataField("action")] // must be a data-field to properly save cooldown when saving game state.
public InstantAction? ScreamAction = null;
}
public sealed class ScreamActionEvent : PerformActionEvent { };
public sealed class ScreamActionEvent : InstantActionEvent { };

View File

@@ -1,10 +1,12 @@
using Content.Server.Speech.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.CharacterAppearance;
using Content.Shared.CharacterAppearance.Components;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Speech;
@@ -18,6 +20,7 @@ namespace Content.Server.Speech;
public sealed class VocalSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
@@ -32,12 +35,20 @@ public sealed class VocalSystem : EntitySystem
private void OnStartup(EntityUid uid, VocalComponent component, ComponentStartup args)
{
_actions.AddAction(uid, component.Action, null);
if (component.ScreamAction == null
&& _proto.TryIndex(component.ActionId, out InstantActionPrototype? act))
{
component.ScreamAction = new(act);
}
if (component.ScreamAction != null)
_actions.AddAction(uid, component.ScreamAction, null);
}
private void OnShutdown(EntityUid uid, VocalComponent component, ComponentShutdown args)
{
_actions.RemoveAction(uid, component.Action);
if (component.ScreamAction != null)
_actions.RemoveAction(uid, component.ScreamAction);
}
private void OnActionPerform(EntityUid uid, VocalComponent component, ScreamActionEvent args)
@@ -60,7 +71,7 @@ public sealed class VocalSystem : EntitySystem
if (!TryComp(uid, out HumanoidAppearanceComponent? humanoid))
return false;
if (_random.Prob(.01f))
if (_random.Prob(component.WilhelmProbability))
{
SoundSystem.Play(Filter.Pvs(uid), component.Wilhelm.GetSound(), uid, component.AudioParams);
return true;

View File

@@ -70,7 +70,7 @@ public sealed class IntrinsicUISystem : EntitySystem
}
[UsedImplicitly]
public sealed class ToggleIntrinsicUIEvent : PerformActionEvent
public sealed class ToggleIntrinsicUIEvent : InstantActionEvent
{
[ViewVariables]
public Enum? Key { get; set; }

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Serialization;
namespace Content.Server.UserInterface;
public sealed class OpenUiActionEvent : PerformActionEvent, ISerializationHooks
public sealed class OpenUiActionEvent : InstantActionEvent, ISerializationHooks
{
[ViewVariables]
public Enum? Key { get; set; }