Carp wave spawner and dragons as an actual event (#10254)

This commit is contained in:
metalgearsloth
2022-08-08 10:18:14 +10:00
committed by GitHub
parent 3d850c6592
commit a29d8b9fa2
60 changed files with 1264 additions and 569 deletions

View File

@@ -32,11 +32,42 @@ namespace Content.Server.Dragon
[DataField("devourAction")]
public EntityTargetAction? DevourAction;
[DataField("spawnActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
public string SpawnActionId = "DragonSpawn";
/// <summary>
/// If we have active rifts.
/// </summary>
[ViewVariables, DataField("rifts")]
public List<EntityUid> Rifts = new();
[DataField("spawnAction")]
public InstantAction? SpawnAction;
public bool Weakened => WeakenedAccumulator > 0f;
/// <summary>
/// When any rift is destroyed how long is the dragon weakened for
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("weakenedDuration")]
public float WeakenedDuration = 120f;
/// <summary>
/// Has a rift been destroyed and the dragon in a temporary weakened state?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("weakenedAccumulator")]
public float WeakenedAccumulator = 0f;
[ViewVariables(VVAccess.ReadWrite), DataField("riftAccumulator")]
public float RiftAccumulator = 0f;
/// <summary>
/// Maximum time the dragon can go without spawning a rift before they die.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxAccumulator")] public float RiftMaxAccumulator = 300f;
/// <summary>
/// Spawns a rift which can summon more mobs.
/// </summary>
[ViewVariables, DataField("spawnRiftAction")]
public InstantAction? SpawnRiftAction;
[ViewVariables(VVAccess.ReadWrite), DataField("riftPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string RiftPrototype = "CarpRift";
/// <summary>
/// The amount of time it takes to devour something
@@ -48,14 +79,7 @@ namespace Content.Server.Dragon
public float StructureDevourTime = 10f;
[DataField("devourTime")]
public float DevourTime = 2f;
[DataField("spawnCount")] public int SpawnsLeft = 2;
[DataField("maxSpawnCount")] public int MaxSpawns = 2;
[DataField("spawnProto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? SpawnPrototype = "MobCarpDragon";
public float DevourTime = 3f;
[ViewVariables(VVAccess.ReadWrite), DataField("soundDeath")]
public SoundSpecifier? SoundDeath = new SoundPathSpecifier("/Audio/Animals/space_dragon_roar.ogg");
@@ -76,7 +100,7 @@ namespace Content.Server.Dragon
public SoundSpecifier? SoundRoar =
new SoundPathSpecifier("/Audio/Animals/space_dragon_roar.ogg")
{
Params = AudioParams.Default.WithVolume(-3f),
Params = AudioParams.Default.WithVolume(3f),
};
public CancellationTokenSource? CancelToken;
@@ -103,5 +127,5 @@ namespace Content.Server.Dragon
public sealed class DragonDevourActionEvent : EntityTargetActionEvent {}
public sealed class DragonSpawnActionEvent : InstantActionEvent {}
public sealed class DragonSpawnRiftActionEvent : InstantActionEvent {}
}

View File

@@ -0,0 +1,40 @@
using Content.Shared.Dragon;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Dragon;
[RegisterComponent]
public sealed class DragonRiftComponent : SharedDragonRiftComponent
{
/// <summary>
/// Dragon that spawned this rift.
/// </summary>
[ViewVariables, DataField("dragon")] public EntityUid Dragon;
/// <summary>
/// How long the rift has been active.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("accumulator")]
public float Accumulator = 0f;
/// <summary>
/// The maximum amount we can accumulate before becoming impervious.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxAccumuluator")] public float MaxAccumulator = 300f;
/// <summary>
/// Accumulation of the spawn timer.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("spawnAccumulator")]
public float SpawnAccumulator = 60f;
/// <summary>
/// How long it takes for a new spawn to be added.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("spawnCooldown")]
public float SpawnCooldown = 60f;
[ViewVariables(VVAccess.ReadWrite), DataField("spawn", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string SpawnPrototype = "MobCarpDragon";
}

View File

@@ -0,0 +1,67 @@
using System.Linq;
using Content.Server.GameTicking;
using Content.Server.StationEvents.Components;
using Content.Shared.Dragon;
using Robust.Server.GameObjects;
using Robust.Shared.Random;
namespace Content.Server.Dragon;
public sealed partial class DragonSystem
{
public override string Prototype => "Dragon";
private int RiftsMet(DragonComponent component)
{
var finished = 0;
foreach (var rift in component.Rifts)
{
if (!TryComp<DragonRiftComponent>(rift, out var drift) ||
drift.State != DragonRiftState.Finished)
continue;
finished++;
}
return finished;
}
public override void Started()
{
var spawnLocations = EntityManager.EntityQuery<IMapGridComponent, TransformComponent>().ToList();
if (spawnLocations.Count == 0)
return;
var location = _random.Pick(spawnLocations);
Spawn("MobDragon", location.Item2.MapPosition);
}
public override void Ended()
{
return;
}
private void OnRiftRoundEnd(RoundEndTextAppendEvent args)
{
if (!RuleAdded)
return;
args.AddLine(Loc.GetString("dragon-round-end-summary"));
foreach (var dragon in EntityQuery<DragonComponent>(true))
{
var met = RiftsMet(dragon);
if (TryComp<ActorComponent>(dragon.Owner, out var actor))
{
args.AddLine(Loc.GetString("dragon-round-end-dragon-player", ("name", dragon.Owner), ("rifts", met), ("player", actor.PlayerSession)));
}
else
{
args.AddLine(Loc.GetString("dragon-round-end-dragon", ("name", dragon.Owner), ("rifts", met)));
}
}
}
}

View File

@@ -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; }

View File

@@ -15,8 +15,6 @@ namespace Content.Server.RatKing
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly ActionsSystem _action = default!;
[Dependency] private readonly DiseaseSystem _disease = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly AtmosphereSystem _atmos = default!;
[Dependency] private readonly TransformSystem _xform = default!;

View File

@@ -1,13 +0,0 @@
namespace Content.Server.Sprite.Components
{
[RegisterComponent]
public sealed class RandomSpriteColorComponent : Component
{
// This should handle random states + colors for layers.
// Saame with RandomSpriteState
[DataField("selected")] public string? SelectedColor;
[DataField("state")] public string BaseState = "error";
[DataField("colors")] public readonly Dictionary<string, Color> Colors = new();
}
}

View File

@@ -1,10 +0,0 @@
namespace Content.Server.Sprite.Components
{
[RegisterComponent]
public sealed class RandomSpriteStateComponent : Component
{
[DataField("spriteStates")] public List<string>? SpriteStates;
[DataField("spriteLayer")] public int SpriteLayer;
}
}

View File

@@ -1,46 +1,53 @@
using Content.Server.Sprite.Components;
using Content.Shared.Random.Helpers;
using Robust.Server.GameObjects;
using System.Linq;
using Content.Shared.Decals;
using Content.Shared.Sprite;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Sprite;
public sealed class RandomSpriteSystem: EntitySystem
public sealed class RandomSpriteSystem: SharedRandomSpriteSystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RandomSpriteColorComponent, ComponentStartup>(OnSpriteColorStartup);
SubscribeLocalEvent<RandomSpriteColorComponent, MapInitEvent>(OnSpriteColorMapInit);
SubscribeLocalEvent<RandomSpriteStateComponent, MapInitEvent>(OnSpriteStateMapInit);
SubscribeLocalEvent<RandomSpriteComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<RandomSpriteComponent, MapInitEvent>(OnMapInit);
}
private void OnSpriteColorStartup(EntityUid uid, RandomSpriteColorComponent component, ComponentStartup args)
private void OnMapInit(EntityUid uid, RandomSpriteComponent component, MapInitEvent args)
{
UpdateColor(component);
if (component.Selected.Count > 0)
return;
if (component.Available.Count == 0)
return;
var group = _random.Pick(component.Available);
component.Selected.EnsureCapacity(group.Count);
foreach (var layer in group)
{
Color? color = null;
if (!string.IsNullOrEmpty(layer.Value.Color))
color = _random.Pick(_prototype.Index<ColorPalettePrototype>(layer.Value.Color).Colors.Values);
component.Selected.Add(layer.Key, (layer.Value.State, color));
}
Dirty(component);
}
private void OnSpriteColorMapInit(EntityUid uid, RandomSpriteColorComponent component, MapInitEvent args)
private void OnGetState(EntityUid uid, RandomSpriteComponent component, ref ComponentGetState args)
{
component.SelectedColor = _random.Pick(component.Colors.Keys);
UpdateColor(component);
}
private void OnSpriteStateMapInit(EntityUid uid, RandomSpriteStateComponent component, MapInitEvent args)
{
if (component.SpriteStates == null) return;
if (!TryComp<SpriteComponent>(uid, out var spriteComponent)) return;
spriteComponent.LayerSetState(component.SpriteLayer, _random.Pick(component.SpriteStates));
}
private void UpdateColor(RandomSpriteColorComponent component)
{
if (!TryComp<SpriteComponent>(component.Owner, out var spriteComponent) || component.SelectedColor == null) return;
spriteComponent.LayerSetState(0, component.BaseState);
spriteComponent.LayerSetColor(0, component.Colors[component.SelectedColor]);
args.State = new RandomSpriteColorComponentState()
{
Selected = component.Selected,
};
}
}