Adds false alarm and updates events code (#2577)
* oops accedentaly ports how ss13 deals with event randomness. Also renames FakeEvent to FalseAlarm! * thing * greytide but it's implemented badly * fixes&changies, also greytide! * rng actualy exists now * resync * Naming Schemes * Startup not init * areas are dead * very cool vsudio * this does not exist, wtf * Cleanup * Nullables, fixables, and timings Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,76 +1,135 @@
|
||||
#nullable enable
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.StationEvents
|
||||
{
|
||||
public abstract class StationEvent
|
||||
{
|
||||
public const float WeightVeryLow = 0.0f;
|
||||
public const float WeightLow = 5.0f;
|
||||
public const float WeightNormal = 10.0f;
|
||||
public const float WeightHigh = 15.0f;
|
||||
public const float WeightVeryHigh = 20.0f;
|
||||
|
||||
/// <summary>
|
||||
/// If the event has started and is currently running
|
||||
/// If the event has started and is currently running.
|
||||
/// </summary>
|
||||
public bool Running { get; protected set; }
|
||||
|
||||
public bool Running { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable name for the event
|
||||
/// Human-readable name for the event.
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
public virtual StationEventWeight Weight { get; } = StationEventWeight.Normal;
|
||||
/// <summary>
|
||||
/// The weight this event has in the random-selection process.
|
||||
/// </summary>
|
||||
public virtual float Weight => WeightNormal;
|
||||
|
||||
/// <summary>
|
||||
/// What should be said in chat when the event starts (if anything).
|
||||
/// What should be said in chat when the event starts (if anything).
|
||||
/// </summary>
|
||||
protected virtual string StartAnnouncement { get; } = null;
|
||||
public virtual string? StartAnnouncement { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// What should be said in chat when the event end (if anything).
|
||||
/// What should be said in chat when the event ends (if anything).
|
||||
/// </summary>
|
||||
protected virtual string EndAnnouncement { get; } = null;
|
||||
protected virtual string? EndAnnouncement { get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// In minutes, when is the first time this event can start
|
||||
/// Starting audio of the event.
|
||||
/// </summary>
|
||||
public virtual string? StartAudio { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Ending audio of the event.
|
||||
/// </summary>
|
||||
public virtual string? EndAudio { get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// In minutes, when is the first round time this event can start
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual int EarliestStart { get; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// How many players need to be present on station for the event to run
|
||||
/// When in the lifetime to call Start().
|
||||
/// </summary>
|
||||
/// To avoid running deadly events with low-pop
|
||||
protected virtual float StartAfter { get; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// When in the lifetime the event should end.
|
||||
/// </summary>
|
||||
protected virtual float EndAfter { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How long has the event existed. Do not change this.
|
||||
/// </summary>
|
||||
private float Elapsed { get; set; } = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How many players need to be present on station for the event to run
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To avoid running deadly events with low-pop
|
||||
/// </remarks>
|
||||
public virtual int MinimumPlayers { get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// How many times this event has run this round
|
||||
/// How many times this event has run this round
|
||||
/// </summary>
|
||||
public int Occurrences { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// How many times this even can occur in a single round
|
||||
/// How many times this even can occur in a single round
|
||||
/// </summary>
|
||||
public virtual int? MaxOccurrences { get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Called once when the station event starts
|
||||
/// Has the startup time elapsed?
|
||||
/// </summary>
|
||||
protected bool Started { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Has this event commenced (announcement may or may not be used)?
|
||||
/// </summary>
|
||||
private bool Announced { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Called once to setup the event after StartAfter has elapsed.
|
||||
/// </summary>
|
||||
public virtual void Startup()
|
||||
{
|
||||
Running = true;
|
||||
Started = true;
|
||||
Occurrences += 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called once as soon as an event is active.
|
||||
/// Can also be used for some initial setup.
|
||||
/// </summary>
|
||||
public virtual void Announce()
|
||||
{
|
||||
if (StartAnnouncement != null)
|
||||
{
|
||||
var chatManager = IoCManager.Resolve<IChatManager>();
|
||||
chatManager.DispatchStationAnnouncement(StartAnnouncement);
|
||||
}
|
||||
|
||||
if (StartAudio != null)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayGlobal(StartAudio, AudioParams.Default.WithVolume(-10f));
|
||||
}
|
||||
|
||||
Announced = true;
|
||||
Running = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every tick when this event is active
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
public abstract void Update(float frameTime);
|
||||
|
||||
/// <summary>
|
||||
/// Called once when the station event ends
|
||||
/// Called once when the station event ends for any reason.
|
||||
/// </summary>
|
||||
public virtual void Shutdown()
|
||||
{
|
||||
@@ -79,15 +138,34 @@ namespace Content.Server.StationEvents
|
||||
var chatManager = IoCManager.Resolve<IChatManager>();
|
||||
chatManager.DispatchStationAnnouncement(EndAnnouncement);
|
||||
}
|
||||
|
||||
if (EndAudio != null)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayGlobal(EndAudio, AudioParams.Default.WithVolume(-10f));
|
||||
}
|
||||
|
||||
Started = false;
|
||||
Announced = false;
|
||||
Elapsed = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every tick when this event is running.
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
public virtual void Update(float frameTime)
|
||||
{
|
||||
Elapsed += frameTime;
|
||||
|
||||
if (!Started && Elapsed >= StartAfter)
|
||||
{
|
||||
Startup();
|
||||
}
|
||||
|
||||
if (EndAfter <= Elapsed)
|
||||
{
|
||||
Running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum StationEventWeight
|
||||
{
|
||||
VeryLow = 0,
|
||||
Low = 5,
|
||||
Normal = 10,
|
||||
High = 15,
|
||||
VeryHigh = 20,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user