Add RGB staff (#13125)

This commit is contained in:
Leon Friedrich
2023-01-02 13:01:40 +13:00
committed by GitHub
parent f980c44aca
commit b33d1f003b
15 changed files with 274 additions and 16 deletions

View File

@@ -149,7 +149,7 @@ namespace Content.Client.Actions
/// <summary>
/// Execute convenience functionality for actions (pop-ups, sound, speech)
/// </summary>
protected override bool PerformBasicActions(EntityUid user, ActionType action)
protected override bool PerformBasicActions(EntityUid user, ActionType action, bool predicted)
{
var performedAction = action.Sound != null
|| !string.IsNullOrWhiteSpace(action.UserPopup)
@@ -233,7 +233,7 @@ namespace Content.Client.Actions
if (instantAction.Event != null)
instantAction.Event.Performer = user;
PerformAction(PlayerActions, instantAction, instantAction.Event, GameTiming.CurTime);
PerformAction(user, PlayerActions, instantAction, instantAction.Event, GameTiming.CurTime);
}
else
{

View File

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Runtime.InteropServices;
using Content.Client.Actions;
using Content.Client.Construction;
@@ -224,7 +224,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
action.Event.Performer = user;
}
_actionsSystem.PerformAction(actionComp, action, action.Event, _timing.CurTime);
_actionsSystem.PerformAction(user, actionComp, action, action.Event, _timing.CurTime);
}
else
_entities.RaisePredictiveEvent(new RequestPerformActionEvent(action, coords));
@@ -256,7 +256,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
action.Event.Performer = user;
}
_actionsSystem.PerformAction(actionComp, action, action.Event, _timing.CurTime);
_actionsSystem.PerformAction(user, actionComp, action, action.Event, _timing.CurTime);
}
else
_entities.RaisePredictiveEvent(new RequestPerformActionEvent(action, args.EntityUid));

View File

@@ -0,0 +1,30 @@
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Interaction;
namespace Content.Server.Actions;
/// <summary>
/// This component enables an entity to perform actions when used to interact with the world, without actually
/// granting that action to the entity that is using the item.
/// </summary>
/// <remarks>
/// If the entity is used in hand (<see cref="ActivateInWorldEvent"/>), it will perform a random available instant
/// action. If the entity is used to interact with another entity (<see cref="InteractUsingEvent"/>), it will
/// attempt to perform a random entity target action. Finally, if the entity is used to click somewhere in the world
/// and no other interaction takes place (<see cref="AfterInteractEvent"/>), then it will try to perform a random
/// available entity or world target action. This component does not bypass standard interaction checks.
///
/// This component mainly exists as a lazy way to add utility entities that can do things like cast "spells".
/// </remarks>
[RegisterComponent]
public sealed class ActionOnInteractComponent : Component
{
[DataField("activateActions")]
public List<InstantAction>? ActivateActions;
[DataField("entityActions")]
public List<EntityTargetAction>? EntityActions;
[DataField("worldActions")]
public List<WorldTargetAction>? WorldActions;
}

View File

@@ -0,0 +1,131 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Interaction;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.Actions;
/// <summary>
/// This System handled interactions for the <see cref="ActionOnInteractComponent"/>.
/// </summary>
public sealed class ActionOnInteractSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ActionOnInteractComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<ActionOnInteractComponent, AfterInteractEvent>(OnAfterInteract);
}
private void OnActivate(EntityUid uid, ActionOnInteractComponent component, ActivateInWorldEvent args)
{
if (args.Handled || component.ActivateActions == null)
return;
var options = new List<InstantAction>();
foreach (var action in component.ActivateActions)
{
if (ValidAction(action))
options.Add(action);
}
if (options.Count == 0)
return;
var act = _random.Pick(options);
if (act.Event != null)
act.Event.Performer = args.User;
act.Provider = uid;
_actions.PerformAction(args.User, null, act, act.Event, _timing.CurTime, false);
args.Handled = true;
}
private void OnAfterInteract(EntityUid uid, ActionOnInteractComponent component, AfterInteractEvent args)
{
if (args.Handled)
return;
// First, try entity target actions
if (args.Target != null && component.EntityActions != null)
{
var entOptions = new List<EntityTargetAction>();
foreach (var action in component.EntityActions)
{
if (!ValidAction(action, args.CanReach))
continue;
if (!_actions.ValidateEntityTarget(args.User, args.Target.Value, action))
continue;
entOptions.Add(action);
}
if (entOptions.Count > 0)
{
var entAct = _random.Pick(entOptions);
if (entAct.Event != null)
{
entAct.Event.Performer = args.User;
entAct.Event.Target = args.Target.Value;
}
entAct.Provider = uid;
_actions.PerformAction(args.User, null, entAct, entAct.Event, _timing.CurTime, false);
args.Handled = true;
return;
}
}
// else: try world target actions
if (component.WorldActions == null)
return;
var options = new List<WorldTargetAction>();
foreach (var action in component.WorldActions)
{
if (!ValidAction(action, args.CanReach))
continue;
if (!_actions.ValidateWorldTarget(args.User, args.ClickLocation, action))
continue;
options.Add(action);
}
if (options.Count == 0)
return;
var act = _random.Pick(options);
if (act.Event != null)
{
act.Event.Performer = args.User;
act.Event.Target = args.ClickLocation;
}
act.Provider = uid;
_actions.PerformAction(args.User, null, act, act.Event, _timing.CurTime, false);
args.Handled = true;
}
private bool ValidAction(ActionType act, bool canReach = true)
{
if (!act.Enabled)
return false;
if (act.Charges.HasValue && act.Charges <= 0)
return false;
var curTime = _timing.CurTime;
if (act.Cooldown.HasValue && act.Cooldown.Value.End > curTime)
return false;
return canReach || act is TargetedAction { CheckCanAccess: false };
}
}

View File

@@ -18,9 +18,9 @@ namespace Content.Server.Actions
base.Initialize();
}
protected override bool PerformBasicActions(EntityUid user, ActionType action)
protected override bool PerformBasicActions(EntityUid user, ActionType action, bool predicted)
{
var result = base.PerformBasicActions(user, action);
var result = base.PerformBasicActions(user, action, predicted);
if (!string.IsNullOrWhiteSpace(action.Speech))
{

View File

@@ -0,0 +1,21 @@
using Content.Shared.Actions;
using Robust.Shared.Prototypes;
namespace Content.Server.Magic.Events;
/// <summary>
/// Spell that uses the magic of ECS to add & remove components. Components are first removed, then added.
/// </summary>
public sealed class ChangeComponentsSpellEvent : EntityTargetActionEvent
{
// TODO allow it to set component data-fields?
// for now a Hackish way to do that is to remove & add, but that doesn't allow you to selectively set specific data fields.
[DataField("toAdd")]
[AlwaysPushInheritance]
public EntityPrototype.ComponentRegistry ToAdd = new();
[DataField("toRemove")]
[AlwaysPushInheritance]
public HashSet<string> ToRemove = new();
}

View File

@@ -18,11 +18,13 @@ using Content.Shared.Spawners.Components;
using Content.Shared.Storage;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
namespace Content.Server.Magic;
@@ -31,6 +33,8 @@ namespace Content.Server.Magic;
/// </summary>
public sealed class MagicSystem : EntitySystem
{
[Dependency] private readonly ISerializationManager _seriMan = default!;
[Dependency] private readonly IComponentFactory _compFact = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
@@ -58,6 +62,7 @@ public sealed class MagicSystem : EntitySystem
SubscribeLocalEvent<SmiteSpellEvent>(OnSmiteSpell);
SubscribeLocalEvent<WorldSpawnSpellEvent>(OnWorldSpawn);
SubscribeLocalEvent<ProjectileSpellEvent>(OnProjectileSpell);
SubscribeLocalEvent<ChangeComponentsSpellEvent>(OnChangeComponentsSpell);
}
private void OnInit(EntityUid uid, SpellbookComponent component, ComponentInit args)
@@ -173,6 +178,27 @@ public sealed class MagicSystem : EntitySystem
}
}
private void OnChangeComponentsSpell(ChangeComponentsSpellEvent ev)
{
foreach (var toRemove in ev.ToRemove)
{
if (_compFact.TryGetRegistration(toRemove, out var registration))
RemComp(ev.Target, registration.Type);
}
foreach (var (name, data) in ev.ToAdd)
{
if (HasComp(ev.Target, data.Component.GetType()))
continue;
var component = (Component) _compFact.GetComponent(name);
component.Owner = ev.Target;
var temp = (object) component;
_seriMan.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(ev.Target, (Component) temp!);
}
}
private List<EntityCoordinates> GetSpawnPositions(TransformComponent casterXform, MagicSpawnData data)
{
switch (data)

View File

@@ -34,7 +34,7 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
/// <summary>
/// Name to show in UI.
/// </summary>
[DataField("name", required: true)]
[DataField("name")]
public string DisplayName = string.Empty;
/// <summary>

View File

@@ -202,7 +202,7 @@ public abstract class SharedActionsSystem : EntitySystem
performEvent.Performer = user;
// All checks passed. Perform the action!
PerformAction(component, act, performEvent, curTime);
PerformAction(user, component, act, performEvent, curTime);
}
public bool ValidateEntityTarget(EntityUid user, EntityUid target, EntityTargetAction action)
@@ -265,7 +265,7 @@ public abstract class SharedActionsSystem : EntitySystem
return _interactionSystem.InRangeUnobstructed(user, coords, range: action.Range);
}
public void PerformAction(ActionsComponent component, ActionType action, BaseActionEvent? actionEvent, TimeSpan curTime)
public void PerformAction(EntityUid performer, ActionsComponent? component, ActionType action, BaseActionEvent? actionEvent, TimeSpan curTime, bool predicted = true)
{
var handled = false;
@@ -277,7 +277,7 @@ public abstract class SharedActionsSystem : EntitySystem
actionEvent.Handled = false;
if (action.Provider == null)
RaiseLocalEvent(component.Owner, (object) actionEvent, broadcast: true);
RaiseLocalEvent(performer, (object) actionEvent, broadcast: true);
else
RaiseLocalEvent(action.Provider.Value, (object) actionEvent, broadcast: true);
@@ -285,7 +285,7 @@ public abstract class SharedActionsSystem : EntitySystem
}
// Execute convenience functionality (pop-ups, sound, speech)
handled |= PerformBasicActions(component.Owner, action);
handled |= PerformBasicActions(performer, action, predicted);
if (!handled)
return; // no interaction occurred.
@@ -309,19 +309,19 @@ public abstract class SharedActionsSystem : EntitySystem
action.Cooldown = (curTime, curTime + action.UseDelay.Value);
}
if (dirty)
if (dirty && component != null)
Dirty(component);
}
/// <summary>
/// Execute convenience functionality for actions (pop-ups, sound, speech)
/// </summary>
protected virtual bool PerformBasicActions(EntityUid performer, ActionType action)
protected virtual bool PerformBasicActions(EntityUid performer, ActionType action, bool predicted)
{
if (action.Sound == null && string.IsNullOrWhiteSpace(action.Popup))
return false;
var filter = Filter.PvsExcept(performer);
var filter = predicted ? Filter.PvsExcept(performer) : Filter.Pvs(performer);
_audio.Play(action.Sound, filter, performer, true, action.AudioParams);

View File

@@ -352,6 +352,8 @@
- id: WeaponPulseCarbine
prob: .001
orGroup: GiftPool
- id: RGBStaff
orGroup: GiftPool
sound:
path: /Audio/Effects/unwrap.ogg

View File

@@ -0,0 +1,37 @@
# non-projectile / "gun" staves
# wand that gives lights an RGB effect.
- type: entity
id: RGBStaff
parent: BaseItem
name: RGB Staff
description: Helps fix the underabundance of RGB gear on the station.
components:
- type: Sprite
sprite: Objects/Weapons/Guns/Basic/staves.rsi
layers:
- state: nothing
- state: nothing-unshaded
shader: unshaded
- type: ActionOnInteract
entityActions:
- whitelist: { components: [ PointLight ] }
charges: 25
sound: /Audio/Magic/blink.ogg
event: !type:ChangeComponentsSpellEvent
toAdd:
- type: RgbLightController
- type: Item
inhandVisuals:
left:
- state: staff-inhand-left
- state: staff-inhand-left-unshaded
shader: unshaded
right:
- state: staff-inhand-right
- state: staff-inhand-right-unshaded
shader: unshaded
- type: RgbLightController
- type: PointLight
enabled: true
radius: 2

View File

@@ -1,7 +1,7 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "/tg/station at https://github.com/tgstation/tgstation/commit/270acce4f551253d8ac75de19236b8b4be598f7f. edited by mirrorcult to allow layering",
"copyright": "/tg/station at https://github.com/tgstation/tgstation/commit/270acce4f551253d8ac75de19236b8b4be598f7f. edited by mirrorcult to allow layering. Generic unshaded layers added by electro.",
"size": {
"x": 32,
"y": 32
@@ -517,6 +517,17 @@
0.5
]
]
},
{
"name": "staff-inhand-right-unshaded",
"directions": 4
},
{
"name": "staff-inhand-left-unshaded",
"directions": 4
},
{
"name": "nothing-unshaded"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB