Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nerf dragon audio + do_after #8880

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Content.Server/Dragon/DragonComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Sound;
using Content.Shared.Storage;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

Expand Down Expand Up @@ -57,14 +58,23 @@ public sealed class DragonComponent : Component
public SoundSpecifier? SoundDeath = new SoundPathSpecifier("/Audio/Animals/space_dragon_roar.ogg");

[ViewVariables(VVAccess.ReadWrite), DataField("soundDevour")]
public SoundSpecifier? SoundDevour = new SoundPathSpecifier("/Audio/Effects/demon_consume.ogg");
public SoundSpecifier? SoundDevour = new SoundPathSpecifier("/Audio/Effects/demon_consume.ogg")
{
Params = AudioParams.Default.WithVolume(-3f),
};

[ViewVariables(VVAccess.ReadWrite), DataField("soundStructureDevour")]
public SoundSpecifier? SoundStructureDevour = new SoundPathSpecifier("/Audio/Machines/airlock_creaking.ogg");
public SoundSpecifier? SoundStructureDevour = new SoundPathSpecifier("/Audio/Machines/airlock_creaking.ogg")
{
Params = AudioParams.Default.WithVolume(-3f),
};

[ViewVariables(VVAccess.ReadWrite), DataField("soundRoar")]
public SoundSpecifier? SoundRoar =
new SoundPathSpecifier("/Audio/Animals/space_dragon_roar.ogg");
new SoundPathSpecifier("/Audio/Animals/space_dragon_roar.ogg")
{
Params = AudioParams.Default.WithVolume(-3f),
};

public CancellationTokenSource? CancelToken;

Expand Down
81 changes: 52 additions & 29 deletions Content.Server/Dragon/DragonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<DragonComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<DragonComponent, DragonDevourComplete>(OnDragonDevourComplete);
SubscribeLocalEvent<DragonComponent, DragonDevourActionEvent>(OnDevourAction);
SubscribeLocalEvent<DragonComponent, DragonSpawnActionEvent>(OnDragonSpawnAction);

SubscribeLocalEvent<DragonComponent, DragonDevourComplete>(OnDragonDevourComplete);
SubscribeLocalEvent<DragonComponent, DragonStructureDevourComplete>(OnDragonStructureDevourComplete);
SubscribeLocalEvent<DragonComponent, DragonDevourCancelledEvent>(OnDragonDevourCancelled);
SubscribeLocalEvent<DragonComponent, MobStateChangedEvent>(OnMobStateChanged);
}
Expand All @@ -46,7 +47,7 @@ private void OnMobStateChanged(EntityUid uid, DragonComponent component, MobStat
if (args.CurrentMobState.IsDead())
{
if (component.SoundDeath != null)
SoundSystem.Play(component.SoundDeath.GetSound(), Filter.Pvs(uid, entityManager: EntityManager));
SoundSystem.Play(component.SoundDeath.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, component.SoundDeath.Params);

component.DragonStomach.EmptyContainer();
}
Expand All @@ -58,13 +59,36 @@ private void OnDragonDevourCancelled(EntityUid uid, DragonComponent component, D
}

private void OnDragonDevourComplete(EntityUid uid, DragonComponent component, DragonDevourComplete args)
{
var ichorInjection = new Solution(component.DevourChem, component.DevourHealRate);

//Humanoid devours allow dragon to get eggs, corpses included
if (EntityManager.HasComponent<HumanoidAppearanceComponent>(args.Target))
{
// Add a spawn for a consumed humanoid
component.SpawnsLeft = Math.Min(component.SpawnsLeft + 1, component.MaxSpawns);
}
//Non-humanoid mobs can only heal dragon for half the normal amount, with no additional spawn tickets
else
{
ichorInjection.ScaleSolution(0.5f);
}

_bloodstreamSystem.TryAddToChemicals(uid, ichorInjection);
component.DragonStomach.Insert(args.Target);

if (component.SoundDevour != null)
SoundSystem.Play(component.SoundDevour.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), 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)
SoundSystem.Play(component.SoundDevour.GetSound(), Filter.Pvs(args.User, entityManager: EntityManager));
SoundSystem.Play(component.SoundDevour.GetSound(), Filter.Pvs(args.User, entityManager: EntityManager), uid, component.SoundDevour.Params);
}

private void OnStartup(EntityUid uid, DragonComponent component, ComponentStartup args)
Expand All @@ -82,7 +106,7 @@ private void OnStartup(EntityUid uid, DragonComponent component, ComponentStartu
_actionsSystem.AddAction(uid, component.SpawnAction, null);

if (component.SoundRoar != null)
SoundSystem.Play(component.SoundRoar.GetSound(), Filter.Pvs(uid, 4f, EntityManager));
SoundSystem.Play(component.SoundRoar.GetSound(), Filter.Pvs(uid, 4f, EntityManager), uid, component.SoundRoar.Params);
}

/// <summary>
Expand All @@ -94,38 +118,25 @@ private void OnDevourAction(EntityUid dragonuid, DragonComponent component, Drag

args.Handled = true;
var target = args.Target;
var ichorInjection = new Solution(component.DevourChem, component.DevourHealRate);

//Check if the target is valid. The effects should be possible to accomplish on either a wall or a body.
//Eating bodies is instant, the wall requires a doAfter.

// Structure and mob devours handled differently.
if (EntityManager.TryGetComponent(target, out MobStateComponent? targetState))
{
switch (targetState.CurrentState)
{
case SharedCriticalMobState:
case SharedDeadMobState:
if (!EntityManager.HasComponent<DamageableComponent>(dragonuid)) return;
component.CancelToken = new CancellationTokenSource();

//Humanoid devours allow dragon to get eggs, corpses included
if (EntityManager.HasComponent<HumanoidAppearanceComponent>(target))
{
// Add a spawn for a consumed humanoid
component.SpawnsLeft = Math.Min(component.SpawnsLeft + 1, component.MaxSpawns);
}
//Non-humanoid mobs can only heal dragon for half the normal amount, with no additional spawn tickets
else
_doAfterSystem.DoAfter(new DoAfterEventArgs(dragonuid, component.DevourTime, component.CancelToken.Token, target)
{
ichorInjection.ScaleSolution(0.5f);
}

_bloodstreamSystem.TryAddToChemicals(dragonuid, ichorInjection);
component.DragonStomach.Insert(target);

if (component.SoundDevour != null)
SoundSystem.Play(component.SoundDevour.GetSound(), Filter.Pvs(dragonuid, entityManager: EntityManager));

return;
UserFinishedEvent = new DragonStructureDevourComplete(dragonuid, target),
UserCancelledEvent = new DragonDevourCancelledEvent(),
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnStun = true,
});
break;
default:
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-fail-target-alive"), dragonuid, Filter.Entities(dragonuid));
break;
Expand All @@ -141,13 +152,13 @@ private void OnDevourAction(EntityUid dragonuid, DragonComponent component, Drag
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-structure"), dragonuid, Filter.Entities(dragonuid));

if (component.SoundStructureDevour != null)
SoundSystem.Play(component.SoundStructureDevour.GetSound(), Filter.Pvs(dragonuid, entityManager: EntityManager));
SoundSystem.Play(component.SoundStructureDevour.GetSound(), Filter.Pvs(dragonuid, entityManager: EntityManager), dragonuid, component.SoundStructureDevour.Params);

component.CancelToken = new CancellationTokenSource();

_doAfterSystem.DoAfter(new DoAfterEventArgs(dragonuid, component.DevourTime, component.CancelToken.Token, target)
{
UserFinishedEvent = new DragonDevourComplete(dragonuid, target),
UserFinishedEvent = new DragonStructureDevourComplete(dragonuid, target),
UserCancelledEvent = new DragonDevourCancelledEvent(),
BreakOnTargetMove = true,
BreakOnUserMove = true,
Expand Down Expand Up @@ -177,6 +188,18 @@ private sealed class DragonDevourComplete : EntityEventArgs
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;
Expand Down
Binary file modified Resources/Audio/Animals/space_dragon_roar.ogg
Binary file not shown.