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

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