Carp wave spawner and dragons as an actual event (#10254)
This commit is contained in:
@@ -9,15 +9,27 @@ using Content.Shared.MobState.Components;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using System.Threading;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Dragon;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Dragon
|
||||
{
|
||||
public sealed class DragonSystem : EntitySystem
|
||||
public sealed partial class DragonSystem : GameRuleSystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
|
||||
@@ -26,13 +38,200 @@ namespace Content.Server.Dragon
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DragonComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<DragonComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourComplete>(OnDragonDevourComplete);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourActionEvent>(OnDevourAction);
|
||||
SubscribeLocalEvent<DragonComponent, DragonSpawnActionEvent>(OnDragonSpawnAction);
|
||||
SubscribeLocalEvent<DragonComponent, DragonSpawnRiftActionEvent>(OnDragonRift);
|
||||
SubscribeLocalEvent<DragonComponent, RefreshMovementSpeedModifiersEvent>(OnDragonMove);
|
||||
|
||||
SubscribeLocalEvent<DragonComponent, DragonStructureDevourComplete>(OnDragonStructureDevourComplete);
|
||||
SubscribeLocalEvent<DragonComponent, DragonDevourCancelledEvent>(OnDragonDevourCancelled);
|
||||
SubscribeLocalEvent<DragonComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
|
||||
SubscribeLocalEvent<DragonRiftComponent, ComponentShutdown>(OnRiftShutdown);
|
||||
SubscribeLocalEvent<DragonRiftComponent, ComponentGetState>(OnRiftGetState);
|
||||
SubscribeLocalEvent<DragonRiftComponent, AnchorStateChangedEvent>(OnAnchorChange);
|
||||
SubscribeLocalEvent<DragonRiftComponent, ExaminedEvent>(OnRiftExamined);
|
||||
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRiftRoundEnd);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var comp in EntityQuery<DragonComponent>())
|
||||
{
|
||||
if (comp.WeakenedAccumulator > 0f)
|
||||
{
|
||||
comp.WeakenedAccumulator -= frameTime;
|
||||
|
||||
// No longer weakened.
|
||||
if (comp.WeakenedAccumulator < 0f)
|
||||
{
|
||||
comp.WeakenedAccumulator = 0f;
|
||||
_movement.RefreshMovementSpeedModifiers(comp.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
// At max rifts
|
||||
if (comp.Rifts.Count >= 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If there's an active rift don't accumulate.
|
||||
if (comp.Rifts.Count > 0)
|
||||
{
|
||||
var lastRift = comp.Rifts[^1];
|
||||
|
||||
if (TryComp<DragonRiftComponent>(lastRift, out var rift) && rift.State != DragonRiftState.Finished)
|
||||
{
|
||||
comp.RiftAccumulator = 0f;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
comp.RiftAccumulator += frameTime;
|
||||
|
||||
// Delete it, naughty dragon!
|
||||
if (comp.RiftAccumulator >= comp.RiftMaxAccumulator)
|
||||
{
|
||||
Roar(comp);
|
||||
QueueDel(comp.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var comp in EntityQuery<DragonRiftComponent>())
|
||||
{
|
||||
if (comp.State != DragonRiftState.Finished && comp.Accumulator >= comp.MaxAccumulator)
|
||||
{
|
||||
// TODO: When we get autocall you can buff if the rift finishes / 3 rifts are up
|
||||
// for now they just keep 3 rifts up.
|
||||
|
||||
comp.Accumulator = comp.MaxAccumulator;
|
||||
RemComp<DamageableComponent>(comp.Owner);
|
||||
comp.State = DragonRiftState.Finished;
|
||||
Dirty(comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
comp.Accumulator += frameTime;
|
||||
}
|
||||
|
||||
comp.SpawnAccumulator += frameTime;
|
||||
|
||||
if (comp.State < DragonRiftState.AlmostFinished && comp.SpawnAccumulator > comp.MaxAccumulator / 2f)
|
||||
{
|
||||
comp.State = DragonRiftState.AlmostFinished;
|
||||
Dirty(comp);
|
||||
var location = Transform(comp.Owner).LocalPosition;
|
||||
|
||||
_chat.DispatchGlobalAnnouncement(Loc.GetString("carp-rift-warning", ("location", location)), playSound: false, colorOverride: Color.Red);
|
||||
_audioSystem.PlayGlobal("/Audio/Misc/notice1.ogg", Filter.Broadcast());
|
||||
}
|
||||
|
||||
if (comp.SpawnAccumulator > comp.SpawnCooldown)
|
||||
{
|
||||
comp.SpawnAccumulator -= comp.SpawnCooldown;
|
||||
Spawn(comp.SpawnPrototype, Transform(comp.Owner).MapPosition);
|
||||
// TODO: When NPC refactor make it guard the rift.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Rift
|
||||
|
||||
private void OnRiftExamined(EntityUid uid, DragonRiftComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("carp-rift-examine", ("percentage", MathF.Round(component.Accumulator / component.MaxAccumulator * 100))));
|
||||
}
|
||||
|
||||
private void OnAnchorChange(EntityUid uid, DragonRiftComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored && component.State == DragonRiftState.Charging)
|
||||
{
|
||||
QueueDel(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRiftShutdown(EntityUid uid, DragonRiftComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (TryComp<DragonComponent>(component.Dragon, out var dragon) && !dragon.Weakened)
|
||||
{
|
||||
foreach (var rift in dragon.Rifts)
|
||||
{
|
||||
QueueDel(rift);
|
||||
}
|
||||
|
||||
dragon.Rifts.Clear();
|
||||
|
||||
// We can't predict the rift being destroyed anyway so no point adding weakened to shared.
|
||||
dragon.WeakenedAccumulator = dragon.WeakenedDuration;
|
||||
_movement.RefreshMovementSpeedModifiers(component.Dragon);
|
||||
_popupSystem.PopupEntity(Loc.GetString("carp-rift-destroyed"), component.Dragon, Filter.Entities(component.Dragon));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRiftGetState(EntityUid uid, DragonRiftComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new DragonRiftComponentState()
|
||||
{
|
||||
State = component.State
|
||||
};
|
||||
}
|
||||
|
||||
private void OnDragonMove(EntityUid uid, DragonComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||
{
|
||||
if (component.Weakened)
|
||||
{
|
||||
args.ModifySpeed(0.5f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDragonRift(EntityUid uid, DragonComponent component, DragonSpawnRiftActionEvent args)
|
||||
{
|
||||
if (component.Weakened)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("carp-rift-weakened"), uid, Filter.Entities(uid));
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Rifts.Count >= 3)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("carp-rift-max"), uid, Filter.Entities(uid));
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Rifts.Count > 0 && TryComp<DragonRiftComponent>(component.Rifts[^1], out var rift) && rift.State != DragonRiftState.Finished)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("carp-rift-duplicate"), uid, Filter.Entities(uid));
|
||||
return;
|
||||
}
|
||||
|
||||
var xform = Transform(uid);
|
||||
|
||||
// Have to be on a grid fam
|
||||
if (xform.GridUid == null)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("carp-rift-anchor"), uid, Filter.Entities(uid));
|
||||
return;
|
||||
}
|
||||
|
||||
var carpUid = Spawn(component.RiftPrototype, xform.MapPosition);
|
||||
component.Rifts.Add(carpUid);
|
||||
Comp<DragonRiftComponent>(carpUid).Dragon = uid;
|
||||
_audioSystem.Play("/Audio/Weapons/Guns/Gunshots/rocket_launcher.ogg", Filter.Pvs(carpUid, entityManager: EntityManager), carpUid);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnShutdown(EntityUid uid, DragonComponent component, ComponentShutdown args)
|
||||
{
|
||||
foreach (var rift in component.Rifts)
|
||||
{
|
||||
QueueDel(rift);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, DragonComponent component, MobStateChangedEvent args)
|
||||
@@ -59,13 +258,7 @@ namespace Content.Server.Dragon
|
||||
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
|
||||
if (!EntityManager.HasComponent<HumanoidAppearanceComponent>(args.Target))
|
||||
{
|
||||
ichorInjection.ScaleSolution(0.5f);
|
||||
}
|
||||
@@ -87,10 +280,14 @@ namespace Content.Server.Dragon
|
||||
_audioSystem.PlayPvs(component.SoundDevour, uid, component.SoundDevour.Params);
|
||||
}
|
||||
|
||||
private void Roar(DragonComponent component)
|
||||
{
|
||||
if (component.SoundRoar != null)
|
||||
_audioSystem.Play(component.SoundRoar, Filter.Pvs(component.Owner, 4f, EntityManager), component.Owner, component.SoundRoar.Params);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, DragonComponent component, ComponentStartup args)
|
||||
{
|
||||
component.SpawnsLeft = Math.Min(component.SpawnsLeft, component.MaxSpawns);
|
||||
|
||||
//Dragon doesn't actually chew, since he sends targets right into his stomach.
|
||||
//I did it mom, I added ERP content into upstream. Legally!
|
||||
component.DragonStomach = _containerSystem.EnsureContainer<Container>(uid, "dragon_stomach");
|
||||
@@ -98,11 +295,10 @@ namespace Content.Server.Dragon
|
||||
if (component.DevourAction != null)
|
||||
_actionsSystem.AddAction(uid, component.DevourAction, null);
|
||||
|
||||
if (component.SpawnAction != null)
|
||||
_actionsSystem.AddAction(uid, component.SpawnAction, null);
|
||||
if (component.SpawnRiftAction != null)
|
||||
_actionsSystem.AddAction(uid, component.SpawnRiftAction, null);
|
||||
|
||||
if (component.SoundRoar != null)
|
||||
_audioSystem.Play(component.SoundRoar, Filter.Pvs(uid, 4f, EntityManager), uid, component.SoundRoar.Params);
|
||||
Roar(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,7 +313,6 @@ namespace Content.Server.Dragon
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
args.Handled = true;
|
||||
var target = args.Target;
|
||||
|
||||
@@ -164,22 +359,6 @@ namespace Content.Server.Dragon
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDragonSpawnAction(EntityUid dragonuid, DragonComponent component, DragonSpawnActionEvent args)
|
||||
{
|
||||
if (component.SpawnPrototype == null)
|
||||
return;
|
||||
|
||||
// If dragon has spawns then add one.
|
||||
if (component.SpawnsLeft > 0)
|
||||
{
|
||||
Spawn(component.SpawnPrototype, Transform(dragonuid).Coordinates);
|
||||
component.SpawnsLeft--;
|
||||
return;
|
||||
}
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("dragon-spawn-action-popup-message-fail-no-eggs"), dragonuid, Filter.Entities(dragonuid));
|
||||
}
|
||||
|
||||
private sealed class DragonDevourComplete : EntityEventArgs
|
||||
{
|
||||
public EntityUid User { get; }
|
||||
|
||||
Reference in New Issue
Block a user