using Content.Server.Explosion.EntitySystems;
using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Explosion.Components;
+/// <summary>
+/// Spawns a protoype when triggered.
+/// </summary>
[RegisterComponent, Access(typeof(TriggerSystem))]
public sealed partial class SpawnOnTriggerComponent : Component
{
- [ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
- public string Proto = string.Empty;
+ /// <summary>
+ /// The prototype to spawn.
+ /// </summary>
+ [DataField(required: true)]
+ public EntProtoId Proto = string.Empty;
+
+ /// <summary>
+ /// Use MapCoordinates for spawning?
+ /// Set to true if you don't want the new entity parented to the spawner.
+ /// </summary>
+ [DataField]
+ public bool mapCoords;
}
-namespace Content.Server.Explosion.Components
+namespace Content.Server.Explosion.Components;
+
+/// <summary>
+/// Triggers when colliding with another entity.
+/// </summary>
+[RegisterComponent]
+public sealed partial class TriggerOnCollideComponent : Component
{
- [RegisterComponent]
- public sealed partial class TriggerOnCollideComponent : Component
- {
- [DataField("fixtureID", required: true)]
- public string FixtureID = String.Empty;
+ /// <summary>
+ /// The fixture with which to collide.
+ /// </summary>
+ [DataField(required: true)]
+ public string FixtureID = string.Empty;
- /// <summary>
- /// Doesn't trigger if the other colliding fixture is nonhard.
- /// </summary>
- [DataField("ignoreOtherNonHard")]
- public bool IgnoreOtherNonHard = true;
- }
+ /// <summary>
+ /// Doesn't trigger if the other colliding fixture is nonhard.
+ /// </summary>
+ [DataField]
+ public bool IgnoreOtherNonHard = true;
}
--- /dev/null
+namespace Content.Server.Explosion.Components;
+
+/// <summary>
+/// Triggers on use in hand.
+/// </summary>
+[RegisterComponent]
+public sealed partial class TriggerOnUseComponent : Component { }
--- /dev/null
+using Content.Shared.Whitelist;
+
+namespace Content.Server.Explosion.Components;
+
+/// <summary>
+/// Checks if the user of a Trigger satisfies a whitelist and blacklist condition.
+/// Cancels the trigger otherwise.
+/// </summary>
+[RegisterComponent]
+public sealed partial class TriggerWhitelistComponent : Component
+{
+ /// <summary>
+ /// Whitelist for what entites can cause this trigger.
+ /// </summary>
+ [DataField]
+ public EntityWhitelist? Whitelist;
+
+ /// <summary>
+ /// Blacklist for what entites can cause this trigger.
+ /// </summary>
+ [DataField]
+ public EntityWhitelist? Blacklist;
+}
using Content.Shared.Explosion.Components.OnTrigger;
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
+using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.StepTrigger.Systems;
using Content.Shared.Trigger;
using Content.Shared.Weapons.Ranged.Events;
+using Content.Shared.Whitelist;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
-using Robust.Shared.Player;
-using Content.Shared.Coordinates;
using Robust.Shared.Utility;
-using Robust.Shared.Timing;
namespace Content.Server.Explosion.EntitySystems
{
}
}
+ /// <summary>
+ /// Raised before a trigger is activated.
+ /// </summary>
+ [ByRefEvent]
+ public record struct BeforeTriggerEvent(EntityUid Triggered, EntityUid? User, bool Cancelled = false);
+
/// <summary>
/// Raised when timer trigger becomes active.
/// </summary>
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
+ [Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
public override void Initialize()
{
SubscribeLocalEvent<TriggerOnSpawnComponent, MapInitEvent>(OnSpawnTriggered);
SubscribeLocalEvent<TriggerOnCollideComponent, StartCollideEvent>(OnTriggerCollide);
SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
+ SubscribeLocalEvent<TriggerOnUseComponent, UseInHandEvent>(OnUse);
SubscribeLocalEvent<TriggerImplantActionComponent, ActivateImplantEvent>(OnImplantTrigger);
SubscribeLocalEvent<TriggerOnStepTriggerComponent, StepTriggeredOffEvent>(OnStepTriggered);
SubscribeLocalEvent<TriggerOnSlipComponent, SlipEvent>(OnSlipTriggered);
SubscribeLocalEvent<SoundOnTriggerComponent, TriggerEvent>(OnSoundTrigger);
SubscribeLocalEvent<ShockOnTriggerComponent, TriggerEvent>(HandleShockTrigger);
SubscribeLocalEvent<RattleComponent, TriggerEvent>(HandleRattleTrigger);
+
+ SubscribeLocalEvent<TriggerWhitelistComponent, BeforeTriggerEvent>(HandleWhitelist);
+ }
+
+ private void HandleWhitelist(Entity<TriggerWhitelistComponent> ent, ref BeforeTriggerEvent args)
+ {
+ args.Cancelled = !_whitelist.CheckBoth(args.User, ent.Comp.Blacklist, ent.Comp.Whitelist);
}
private void OnSoundTrigger(EntityUid uid, SoundOnTriggerComponent component, TriggerEvent args)
RemCompDeferred<AnchorOnTriggerComponent>(uid);
}
- private void OnSpawnTrigger(EntityUid uid, SpawnOnTriggerComponent component, TriggerEvent args)
+ private void OnSpawnTrigger(Entity<SpawnOnTriggerComponent> ent, ref TriggerEvent args)
{
- var xform = Transform(uid);
+ var xform = Transform(ent);
- var coords = xform.Coordinates;
-
- if (!coords.IsValid(EntityManager))
- return;
+ if (ent.Comp.mapCoords)
+ {
+ var mapCoords = _transformSystem.GetMapCoordinates(ent, xform);
+ Spawn(ent.Comp.Proto, mapCoords);
+ }
+ else
+ {
+ var coords = xform.Coordinates;
+ if (!coords.IsValid(EntityManager))
+ return;
+ Spawn(ent.Comp.Proto, coords);
- Spawn(component.Proto, coords);
+ }
}
private void HandleExplodeTrigger(EntityUid uid, ExplodeOnTriggerComponent component, TriggerEvent args)
args.Handled = true;
}
+ private void OnUse(Entity<TriggerOnUseComponent> ent, ref UseInHandEvent args)
+ {
+ if (args.Handled)
+ return;
+
+ Trigger(ent.Owner, args.User);
+ args.Handled = true;
+ }
+
private void OnImplantTrigger(EntityUid uid, TriggerImplantActionComponent component, ActivateImplantEvent args)
{
args.Handled = Trigger(uid);
public bool Trigger(EntityUid trigger, EntityUid? user = null)
{
+ var beforeTriggerEvent = new BeforeTriggerEvent(trigger, user);
+ RaiseLocalEvent(trigger, ref beforeTriggerEvent);
+ if (beforeTriggerEvent.Cancelled)
+ return false;
+
var triggerEvent = new TriggerEvent(trigger, user);
EntityManager.EventBus.RaiseLocalEvent(trigger, triggerEvent, true);
return triggerEvent.Handled;
--- /dev/null
+using Content.Shared.Polymorph;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Polymorph.Components;
+
+/// <summary>
+/// Intended for use with the trigger system.
+/// Polymorphs the user of the trigger.
+/// </summary>
+[RegisterComponent]
+public sealed partial class PolymorphOnTriggerComponent : Component
+{
+ /// <summary>
+ /// Polymorph settings.
+ /// </summary>
+ [DataField(required: true)]
+ public ProtoId<PolymorphPrototype> Polymorph;
+}
+++ /dev/null
-using Content.Server.Polymorph.Components;
-using Content.Shared.Polymorph;
-using Content.Shared.Projectiles;
-using Content.Shared.Whitelist;
-using Robust.Shared.Audio;
-using Robust.Shared.Physics.Events;
-using Robust.Shared.Prototypes;
-
-namespace Content.Server.Polymorph.Systems;
-
-public partial class PolymorphSystem
-{
- [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
-
- /// <summary>
- /// Need to do this so we don't get a collection enumeration error in physics by polymorphing
- /// an entity we're colliding with
- /// </summary>
- private Queue<PolymorphQueuedData> _queuedPolymorphUpdates = new();
-
- private void InitializeCollide()
- {
- SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
- }
-
- public void UpdateCollide()
- {
- while (_queuedPolymorphUpdates.TryDequeue(out var data))
- {
- if (Deleted(data.Ent))
- continue;
-
- var ent = PolymorphEntity(data.Ent, data.Polymorph);
- if (ent != null)
- _audio.PlayPvs(data.Sound, ent.Value);
- }
- }
-
- private void OnPolymorphCollide(EntityUid uid, PolymorphOnCollideComponent component, ref StartCollideEvent args)
- {
- if (args.OurFixtureId != SharedProjectileSystem.ProjectileFixture)
- return;
-
- var other = args.OtherEntity;
- if (_whitelistSystem.IsWhitelistFail(component.Whitelist, other) ||
- _whitelistSystem.IsBlacklistPass(component.Blacklist, other))
- return;
-
- _queuedPolymorphUpdates.Enqueue(new (other, component.Sound, component.Polymorph));
- }
-}
-
-public struct PolymorphQueuedData
-{
- public EntityUid Ent;
- public SoundSpecifier Sound;
- public ProtoId<PolymorphPrototype> Polymorph;
-
- public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, ProtoId<PolymorphPrototype> polymorph)
- {
- Ent = ent;
- Sound = sound;
- Polymorph = polymorph;
- }
-}
--- /dev/null
+using Content.Shared.Polymorph;
+using Content.Server.Polymorph.Components;
+using Content.Server.Explosion.EntitySystems;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Polymorph.Systems;
+
+public sealed partial class PolymorphSystem
+{
+ /// <summary>
+ /// Need to do this so we don't get a collection enumeration error in physics by polymorphing
+ /// an entity we're colliding with in case of TriggerOnCollide.
+ /// Also makes sure other trigger effects don't activate in nullspace after we have polymorphed.
+ /// </summary>
+ private Queue<(EntityUid Ent, ProtoId<PolymorphPrototype> Polymorph)> _queuedPolymorphUpdates = new();
+
+ private void InitializeTrigger()
+ {
+ SubscribeLocalEvent<PolymorphOnTriggerComponent, TriggerEvent>(OnTrigger);
+ }
+
+ private void OnTrigger(Entity<PolymorphOnTriggerComponent> ent, ref TriggerEvent args)
+ {
+ if (args.User == null)
+ return;
+
+ _queuedPolymorphUpdates.Enqueue((args.User.Value, ent.Comp.Polymorph));
+ args.Handled = true;
+ }
+
+ public void UpdateTrigger()
+ {
+ while (_queuedPolymorphUpdates.TryDequeue(out var data))
+ {
+ if (TerminatingOrDeleted(data.Item1))
+ continue;
+
+ PolymorphEntity(data.Item1, data.Item2);
+ }
+ }
+}
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
- InitializeCollide();
InitializeMap();
+ InitializeTrigger();
}
public override void Update(float frameTime)
}
}
- UpdateCollide();
+ UpdateTrigger();
}
private void OnComponentStartup(Entity<PolymorphableComponent> ent, ref ComponentStartup args)
damage:
types:
Poison: 5
+ - type: TriggerOnCollide
+ fixtureID: projectile
- type: entity
id: ProjectilePolyboltCarp
description: Nooo, I don't wanna be fish!
categories: [ HideSpawnMenu ]
components:
- - type: PolymorphOnCollide
+ - type: PolymorphOnTrigger
polymorph: WizardForcedCarp
+ - type: TriggerWhitelist
whitelist:
components:
- Body
description: Nooo, I don't wanna be monkey!
categories: [ HideSpawnMenu ]
components:
- - type: PolymorphOnCollide
+ - type: PolymorphOnTrigger
polymorph: WizardForcedMonkey
+ - type: TriggerWhitelist
whitelist:
components:
- Body
layers:
- state: spell
color: brown
- - type: PolymorphOnCollide
+ - type: PolymorphOnTrigger
polymorph: WizardWallDoor
+ - type: TriggerWhitelist
whitelist:
components:
- Airlock
description: KnoH KnoH!
categories: [ HideSpawnMenu ]
components:
- - type: PolymorphOnCollide
+ - type: PolymorphOnTrigger
polymorph: WizardForcedCluwne
+ - type: TriggerWhitelist
whitelist:
components:
- Body
description: Nooo, I don't wanna be bread!
categories: [ HideSpawnMenu ]
components:
- - type: PolymorphOnCollide
+ - type: PolymorphOnTrigger
polymorph: BreadMorph
+ - type: TriggerWhitelist
whitelist:
components:
- Body
transferDamage: true
revertOnCrit: false
revertOnDeath: true
+ polymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
+ exitPolymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
- type: polymorph
id: WizardForcedSkeleton
transferDamage: true
revertOnCrit: false
revertOnDeath: false
+ polymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
+ exitPolymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
- type: polymorph
id: WizardForcedMonkey
transferDamage: true
revertOnCrit: false
revertOnDeath: true
+ polymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
+ exitPolymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
- type: polymorph
id: WizardWallDoor
transferDamage: false
revertOnCrit: false
revertOnDeath: false
+ polymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
+ exitPolymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
- type: polymorph
id: WizardForcedCluwne
transferHumanoidAppearance: true
inventory: Transfer
revertOnDeath: true
+ polymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
+ exitPolymorphSound: !type:SoundPathSpecifier
+ path: /Audio/Magic/forcewall.ogg
# this is a test for transferring some visual appearance stuff
- type: polymorph