DoAfter Refactor (#13225)
Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
@@ -9,7 +9,6 @@ using System.Threading;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Humanoid;
|
||||
using Content.Server.NPC;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Dragon;
|
||||
@@ -20,6 +19,7 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Server.NPC.Systems;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
@@ -59,13 +59,12 @@ namespace Content.Server.Dragon
|
||||
|
||||
SubscribeLocalEvent<DragonComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<DragonComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourComplete>(OnDragonDevourComplete);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourActionEvent>(OnDevourAction);
|
||||
SubscribeLocalEvent<DragonComponent, DragonSpawnRiftActionEvent>(OnDragonRift);
|
||||
SubscribeLocalEvent<DragonComponent, RefreshMovementSpeedModifiersEvent>(OnDragonMove);
|
||||
|
||||
SubscribeLocalEvent<DragonComponent, DragonStructureDevourComplete>(OnDragonStructureDevourComplete);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourCancelledEvent>(OnDragonDevourCancelled);
|
||||
SubscribeLocalEvent<DragonComponent, DoAfterEvent>(OnDoAfter);
|
||||
|
||||
SubscribeLocalEvent<DragonComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
|
||||
SubscribeLocalEvent<DragonRiftComponent, ComponentShutdown>(OnRiftShutdown);
|
||||
@@ -76,6 +75,30 @@ namespace Content.Server.Dragon
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRiftRoundEnd);
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, DragonComponent component, DoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled)
|
||||
return;
|
||||
|
||||
var ichorInjection = new Solution(component.DevourChem, component.DevourHealRate);
|
||||
|
||||
//Humanoid devours allow dragon to get eggs, corpses included
|
||||
if (HasComp<HumanoidAppearanceComponent>(args.Args.Target))
|
||||
{
|
||||
ichorInjection.ScaleSolution(0.5f);
|
||||
component.DragonStomach.Insert(args.Args.Target.Value);
|
||||
_bloodstreamSystem.TryAddToChemicals(uid, ichorInjection);
|
||||
}
|
||||
|
||||
//TODO: Figure out a better way of removing structures via devour that still entails standing still and waiting for a DoAfter. Somehow.
|
||||
//If it's not human, it must be a structure
|
||||
else if (args.Args.Target != null)
|
||||
EntityManager.QueueDeleteEntity(args.Args.Target.Value);
|
||||
|
||||
if (component.SoundDevour != null)
|
||||
_audioSystem.PlayPvs(component.SoundDevour, uid, component.SoundDevour.Params);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -292,39 +315,6 @@ namespace Content.Server.Dragon
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDragonDevourCancelled(EntityUid uid, DragonComponent component, DragonDevourCancelledEvent args)
|
||||
{
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
private void OnDragonDevourComplete(EntityUid uid, DragonComponent component, DragonDevourComplete args)
|
||||
{
|
||||
component.CancelToken = null;
|
||||
var ichorInjection = new Solution(component.DevourChem, component.DevourHealRate);
|
||||
|
||||
//Humanoid devours allow dragon to get eggs, corpses included
|
||||
if (!EntityManager.HasComponent<HumanoidAppearanceComponent>(args.Target))
|
||||
{
|
||||
ichorInjection.ScaleSolution(0.5f);
|
||||
}
|
||||
|
||||
_bloodstreamSystem.TryAddToChemicals(uid, ichorInjection);
|
||||
component.DragonStomach.Insert(args.Target);
|
||||
|
||||
if (component.SoundDevour != null)
|
||||
_audioSystem.PlayPvs(component.SoundDevour, uid, component.SoundDevour.Params);
|
||||
}
|
||||
|
||||
private void OnDragonStructureDevourComplete(EntityUid uid, DragonComponent component, DragonStructureDevourComplete args)
|
||||
{
|
||||
component.CancelToken = null;
|
||||
//TODO: Figure out a better way of removing structures via devour that still entails standing still and waiting for a DoAfter. Somehow.
|
||||
EntityManager.QueueDeleteEntity(args.Target);
|
||||
|
||||
if (component.SoundDevour != null)
|
||||
_audioSystem.PlayPvs(component.SoundDevour, uid, component.SoundDevour.Params);
|
||||
}
|
||||
|
||||
private void Roar(DragonComponent component)
|
||||
{
|
||||
if (component.SoundRoar != null)
|
||||
@@ -351,12 +341,8 @@ namespace Content.Server.Dragon
|
||||
/// </summary>
|
||||
private void OnDevourAction(EntityUid uid, DragonComponent component, DragonDevourActionEvent args)
|
||||
{
|
||||
if (component.CancelToken != null ||
|
||||
args.Handled ||
|
||||
component.DevourWhitelist?.IsValid(args.Target, EntityManager) != true)
|
||||
{
|
||||
if (args.Handled || component.DevourWhitelist?.IsValid(args.Target, EntityManager) != true)
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
var target = args.Target;
|
||||
@@ -368,12 +354,9 @@ namespace Content.Server.Dragon
|
||||
{
|
||||
case MobState.Critical:
|
||||
case MobState.Dead:
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.DevourTime, component.CancelToken.Token, target)
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.DevourTime, target:target)
|
||||
{
|
||||
UserFinishedEvent = new DragonDevourComplete(uid, target),
|
||||
UserCancelledEvent = new DragonDevourCancelledEvent(),
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
@@ -392,42 +375,12 @@ namespace Content.Server.Dragon
|
||||
if (component.SoundStructureDevour != null)
|
||||
_audioSystem.PlayPvs(component.SoundStructureDevour, uid, component.SoundStructureDevour.Params);
|
||||
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.StructureDevourTime, component.CancelToken.Token, target)
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.StructureDevourTime, target:target)
|
||||
{
|
||||
UserFinishedEvent = new DragonStructureDevourComplete(uid, target),
|
||||
UserCancelledEvent = new DragonDevourCancelledEvent(),
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
});
|
||||
}
|
||||
|
||||
private sealed class DragonDevourComplete : EntityEventArgs
|
||||
{
|
||||
public EntityUid User { get; }
|
||||
public EntityUid Target { get; }
|
||||
|
||||
public DragonDevourComplete(EntityUid user, EntityUid target)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DragonStructureDevourComplete : EntityEventArgs
|
||||
{
|
||||
public EntityUid User { get; }
|
||||
public EntityUid Target { get; }
|
||||
|
||||
public DragonStructureDevourComplete(EntityUid user, EntityUid target)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DragonDevourCancelledEvent : EntityEventArgs {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user