make dragons breathe fire (#26746)
* add ActionGun system * add RepeatingTrigger * dragons breath projectile, repeatedly explodes * give dragon fire breathing action, fireproof it * oop * oop 2 * prevent troll * proper repeating thing * pro * webedit ops * realops --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -81,6 +81,13 @@ public sealed partial class ExplosiveComponent : Component
|
||||
[DataField("deleteAfterExplosion")]
|
||||
public bool? DeleteAfterExplosion;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to not set <see cref="Exploded"/> to true, allowing it to explode multiple times.
|
||||
/// This should never be used if it is damageable.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Repeatable;
|
||||
|
||||
/// <summary>
|
||||
/// Avoid somehow double-triggering this explosion (e.g. by damaging this entity from its own explosion.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.Explosion.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Constantly triggers after being added to an entity.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(TriggerSystem))]
|
||||
[AutoGenerateComponentPause]
|
||||
public sealed partial class RepeatingTriggerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How long to wait between triggers.
|
||||
/// The first trigger starts this long after the component is added.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Delay = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>
|
||||
/// When the next trigger will be.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
|
||||
public TimeSpan NextTrigger;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (explosive.Exploded)
|
||||
return;
|
||||
|
||||
explosive.Exploded = true;
|
||||
explosive.Exploded = !explosive.Repeatable;
|
||||
|
||||
// Override the explosion intensity if optional arguments were provided.
|
||||
if (radius != null)
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
SubscribeLocalEvent<TriggerOnStepTriggerComponent, StepTriggeredOffEvent>(OnStepTriggered);
|
||||
SubscribeLocalEvent<TriggerOnSlipComponent, SlipEvent>(OnSlipTriggered);
|
||||
SubscribeLocalEvent<TriggerWhenEmptyComponent, OnEmptyGunShotEvent>(OnEmptyTriggered);
|
||||
SubscribeLocalEvent<RepeatingTriggerComponent, MapInitEvent>(OnRepeatInit);
|
||||
|
||||
SubscribeLocalEvent<SpawnOnTriggerComponent, TriggerEvent>(OnSpawnTrigger);
|
||||
SubscribeLocalEvent<DeleteOnTriggerComponent, TriggerEvent>(HandleDeleteTrigger);
|
||||
@@ -241,6 +242,11 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
Trigger(uid, args.EmptyGun);
|
||||
}
|
||||
|
||||
private void OnRepeatInit(Entity<RepeatingTriggerComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.NextTrigger = _timing.CurTime + ent.Comp.Delay;
|
||||
}
|
||||
|
||||
public bool Trigger(EntityUid trigger, EntityUid? user = null)
|
||||
{
|
||||
var triggerEvent = new TriggerEvent(trigger, user);
|
||||
@@ -323,6 +329,7 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
UpdateProximity();
|
||||
UpdateTimer(frameTime);
|
||||
UpdateTimedCollide(frameTime);
|
||||
UpdateRepeat();
|
||||
}
|
||||
|
||||
private void UpdateTimer(float frameTime)
|
||||
@@ -357,5 +364,19 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
_appearance.SetData(uid, TriggerVisuals.VisualState, TriggerVisualState.Unprimed, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRepeat()
|
||||
{
|
||||
var now = _timing.CurTime;
|
||||
var query = EntityQueryEnumerator<RepeatingTriggerComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
if (comp.NextTrigger > now)
|
||||
continue;
|
||||
|
||||
comp.NextTrigger = now + comp.Delay;
|
||||
Trigger(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user