Zombie Mode 𝓡𝓮𝓭𝓾𝔁 (#18199)
* zombie mode redux * the great zombie changes * fix this * 65 down to 50 * empty * Changes to address stalling * make zombie nukies no longer nukies * actually work
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Content.Server.Actions;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Mind.Components;
|
||||
@@ -10,7 +11,8 @@ using Content.Server.Popups;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.RoundEnd;
|
||||
using Content.Server.Traitor;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Server.Zombies;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.CCVar;
|
||||
@@ -21,11 +23,12 @@ using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Zombies;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules;
|
||||
|
||||
@@ -35,25 +38,25 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IServerPreferencesManager _prefs = default!;
|
||||
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
[Dependency] private readonly RoundEndSystem _roundEnd = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly ActionsSystem _action = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly ZombifyOnDeathSystem _zombify = default!;
|
||||
[Dependency] private readonly ZombieSystem _zombie = default!;
|
||||
[Dependency] private readonly MindSystem _mindSystem = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoundStartAttemptEvent>(OnStartAttempt);
|
||||
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||
SubscribeLocalEvent<RulePlayerJobsAssignedEvent>(OnJobAssigned);
|
||||
|
||||
SubscribeLocalEvent<EntityZombifiedEvent>(OnEntityZombified);
|
||||
SubscribeLocalEvent<ZombifyOnDeathComponent, ZombifySelfActionEvent>(OnZombifySelf);
|
||||
}
|
||||
|
||||
@@ -62,7 +65,7 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
|
||||
foreach (var zombie in EntityQuery<ZombieRuleComponent>())
|
||||
{
|
||||
// This is just the general condition thing used for determining the win/lose text
|
||||
var fraction = GetInfectedFraction();
|
||||
var fraction = GetInfectedFraction(true, true);
|
||||
|
||||
if (fraction <= 0)
|
||||
ev.AddLine(Loc.GetString("zombie-round-end-amount-none"));
|
||||
@@ -86,80 +89,63 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
|
||||
var healthy = GetHealthyHumans();
|
||||
// Gets a bunch of the living players and displays them if they're under a threshold.
|
||||
// InitialInfected is used for the threshold because it scales with the player count well.
|
||||
if (healthy.Count > 0 && healthy.Count <= 2 * zombie.InitialInfectedNames.Count)
|
||||
if (healthy.Count <= 0 || healthy.Count > 2 * zombie.InitialInfectedNames.Count)
|
||||
continue;
|
||||
ev.AddLine("");
|
||||
ev.AddLine(Loc.GetString("zombie-round-end-survivor-count", ("count", healthy.Count)));
|
||||
foreach (var survivor in healthy)
|
||||
{
|
||||
ev.AddLine("");
|
||||
ev.AddLine(Loc.GetString("zombie-round-end-survivor-count", ("count", healthy.Count)));
|
||||
foreach (var survivor in healthy)
|
||||
var meta = MetaData(survivor);
|
||||
var username = string.Empty;
|
||||
if (TryComp<MindContainerComponent>(survivor, out var mindcomp))
|
||||
{
|
||||
var meta = MetaData(survivor);
|
||||
var username = string.Empty;
|
||||
if (TryComp<MindContainerComponent>(survivor, out var mindcomp))
|
||||
if (mindcomp.Mind != null && mindcomp.Mind.Session != null)
|
||||
username = mindcomp.Mind.Session.Name;
|
||||
|
||||
ev.AddLine(Loc.GetString("zombie-round-end-user-was-survivor",
|
||||
("name", meta.EntityName),
|
||||
("username", username)));
|
||||
if (mindcomp.Mind != null && mindcomp.Mind.Session != null)
|
||||
username = mindcomp.Mind.Session.Name;
|
||||
}
|
||||
|
||||
ev.AddLine(Loc.GetString("zombie-round-end-user-was-survivor",
|
||||
("name", meta.EntityName),
|
||||
("username", username)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJobAssigned(RulePlayerJobsAssignedEvent ev)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ZombieRuleComponent, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var zombies, out var gameRule))
|
||||
{
|
||||
if (!GameTicker.IsGameRuleAdded(uid, gameRule))
|
||||
continue;
|
||||
InfectInitialPlayers(zombies);
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// This is just checked if the last human somehow dies
|
||||
/// by starving or flying off into space.
|
||||
/// </remarks>
|
||||
private void OnMobStateChanged(MobStateChangedEvent ev)
|
||||
{
|
||||
CheckRoundEnd(ev.Target);
|
||||
}
|
||||
|
||||
private void OnEntityZombified(EntityZombifiedEvent ev)
|
||||
{
|
||||
CheckRoundEnd(ev.Target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The big kahoona function for checking if the round is gonna end
|
||||
/// </summary>
|
||||
/// <param name="target">depending on this uid, we should care about the round ending</param>
|
||||
private void CheckRoundEnd(EntityUid target)
|
||||
private void CheckRoundEnd()
|
||||
{
|
||||
var query = EntityQueryEnumerator<ZombieRuleComponent, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var zombies, out var gameRule))
|
||||
while (query.MoveNext(out var uid, out var comp, out var gameRule))
|
||||
{
|
||||
if (GameTicker.IsGameRuleActive(uid, gameRule))
|
||||
if (!GameTicker.IsGameRuleActive(uid, gameRule))
|
||||
continue;
|
||||
|
||||
// We only care about players, not monkeys and such.
|
||||
if (!HasComp<HumanoidAppearanceComponent>(target))
|
||||
continue;
|
||||
|
||||
var fraction = GetInfectedFraction();
|
||||
var healthy = GetHealthyHumans();
|
||||
if (healthy.Count == 1) // Only one human left. spooky
|
||||
_popup.PopupEntity(Loc.GetString("zombie-alone"), healthy[0], healthy[0]);
|
||||
if (fraction >= 1) // Oops, all zombies
|
||||
_roundEndSystem.EndRound();
|
||||
|
||||
if (!comp.ShuttleCalled && GetInfectedFraction(false) >= comp.ZombieShuttleCallPercentage)
|
||||
{
|
||||
comp.ShuttleCalled = true;
|
||||
foreach (var station in _station.GetStations())
|
||||
{
|
||||
_chat.DispatchStationAnnouncement(station, Loc.GetString("zombie-shuttle-call"), colorOverride: Color.Crimson);
|
||||
}
|
||||
_roundEnd.RequestRoundEnd(null, false);
|
||||
}
|
||||
|
||||
// we include dead for this count because we don't want to end the round
|
||||
// when everyone gets on the shuttle.
|
||||
if (GetInfectedFraction() >= 1) // Oops, all zombies
|
||||
_roundEnd.EndRound();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartAttempt(RoundStartAttemptEvent ev)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ZombieRuleComponent, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var zombies, out var gameRule))
|
||||
while (query.MoveNext(out var uid, out _, out var gameRule))
|
||||
{
|
||||
if (!GameTicker.IsGameRuleAdded(uid, gameRule))
|
||||
continue;
|
||||
@@ -185,37 +171,86 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
|
||||
protected override void Started(EntityUid uid, ZombieRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
component.StartTime = _timing.CurTime + _random.Next(component.MinStartDelay, component.MaxStartDelay);
|
||||
}
|
||||
|
||||
protected override void ActiveTick(EntityUid uid, ZombieRuleComponent component, GameRuleComponent gameRule, float frameTime)
|
||||
{
|
||||
base.ActiveTick(uid, component, gameRule, frameTime);
|
||||
|
||||
if (component.InfectedChosen)
|
||||
{
|
||||
if (_timing.CurTime >= component.NextRoundEndCheck)
|
||||
{
|
||||
component.NextRoundEndCheck += component.EndCheckDelay;
|
||||
CheckRoundEnd();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.StartTime == null || _timing.CurTime < component.StartTime)
|
||||
return;
|
||||
|
||||
InfectInitialPlayers(component);
|
||||
}
|
||||
|
||||
private void OnZombifySelf(EntityUid uid, ZombifyOnDeathComponent component, ZombifySelfActionEvent args)
|
||||
{
|
||||
_zombify.ZombifyEntity(uid);
|
||||
_zombie.ZombifyEntity(uid);
|
||||
|
||||
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(ZombieRuleComponent.ZombifySelfActionPrototype));
|
||||
_action.RemoveAction(uid, action);
|
||||
}
|
||||
|
||||
private float GetInfectedFraction()
|
||||
private float GetInfectedFraction(bool includeOffStation = true, bool includeDead = false)
|
||||
{
|
||||
var players = EntityQuery<HumanoidAppearanceComponent>(true);
|
||||
var zombers = EntityQuery<HumanoidAppearanceComponent, ZombieComponent>(true);
|
||||
var players = GetHealthyHumans(includeOffStation);
|
||||
var zombieCount = 0;
|
||||
var query = EntityQueryEnumerator<HumanoidAppearanceComponent, ZombieComponent, MobStateComponent>();
|
||||
while (query.MoveNext(out _, out _, out _, out var mob))
|
||||
{
|
||||
if (!includeDead && mob.CurrentState == MobState.Dead)
|
||||
continue;
|
||||
zombieCount++;
|
||||
}
|
||||
|
||||
return zombers.Count() / (float) players.Count();
|
||||
return zombieCount / (float) (players.Count + zombieCount);
|
||||
}
|
||||
|
||||
private List<EntityUid> GetHealthyHumans()
|
||||
/// <summary>
|
||||
/// Gets the list of humans who are alive, not zombies, and are on a station.
|
||||
/// Flying off via a shuttle disqualifies you.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<EntityUid> GetHealthyHumans(bool includeOffStation = true)
|
||||
{
|
||||
var healthy = new List<EntityUid>();
|
||||
var players = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent>();
|
||||
var zombers = GetEntityQuery<ZombieComponent>();
|
||||
while (players.MoveNext(out var uid, out _, out var mob))
|
||||
|
||||
var stationGrids = new HashSet<EntityUid>();
|
||||
if (!includeOffStation)
|
||||
{
|
||||
if (_mobState.IsAlive(uid, mob) && !zombers.HasComponent(uid))
|
||||
foreach (var station in _station.GetStationsSet())
|
||||
{
|
||||
healthy.Add(uid);
|
||||
if (TryComp<StationDataComponent>(station, out var data) && _station.GetLargestGrid(data) is { } grid)
|
||||
stationGrids.Add(grid);
|
||||
}
|
||||
}
|
||||
|
||||
var players = AllEntityQuery<HumanoidAppearanceComponent, ActorComponent, MobStateComponent, TransformComponent>();
|
||||
var zombers = GetEntityQuery<ZombieComponent>();
|
||||
while (players.MoveNext(out var uid, out _, out _, out var mob, out var xform))
|
||||
{
|
||||
if (!_mobState.IsAlive(uid, mob))
|
||||
continue;
|
||||
|
||||
if (zombers.HasComponent(uid))
|
||||
continue;
|
||||
|
||||
if (!includeOffStation && !stationGrids.Contains(xform.GridUid ?? EntityUid.Invalid))
|
||||
continue;
|
||||
|
||||
healthy.Add(uid);
|
||||
}
|
||||
return healthy;
|
||||
}
|
||||
|
||||
@@ -230,95 +265,80 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
|
||||
/// </remarks>
|
||||
private void InfectInitialPlayers(ZombieRuleComponent component)
|
||||
{
|
||||
if (component.InfectedChosen)
|
||||
return;
|
||||
component.InfectedChosen = true;
|
||||
|
||||
var allPlayers = _playerManager.ServerSessions.ToList();
|
||||
var playerList = new List<IPlayerSession>();
|
||||
var prefList = new List<IPlayerSession>();
|
||||
foreach (var player in allPlayers)
|
||||
{
|
||||
// TODO: A
|
||||
if (player.AttachedEntity != null && HasComp<HumanoidAppearanceComponent>(player.AttachedEntity))
|
||||
{
|
||||
playerList.Add(player);
|
||||
if (player.AttachedEntity == null || !HasComp<HumanoidAppearanceComponent>(player.AttachedEntity))
|
||||
continue;
|
||||
playerList.Add(player);
|
||||
|
||||
var pref = (HumanoidCharacterProfile) _prefs.GetPreferences(player.UserId).SelectedCharacter;
|
||||
if (pref.AntagPreferences.Contains(component.PatientZeroPrototypeID))
|
||||
prefList.Add(player);
|
||||
}
|
||||
var pref = (HumanoidCharacterProfile) _prefs.GetPreferences(player.UserId).SelectedCharacter;
|
||||
if (pref.AntagPreferences.Contains(component.PatientZeroPrototypeId))
|
||||
prefList.Add(player);
|
||||
}
|
||||
|
||||
if (playerList.Count == 0)
|
||||
return;
|
||||
|
||||
var playersPerInfected = _cfg.GetCVar(CCVars.ZombiePlayersPerInfected);
|
||||
var maxInfected = _cfg.GetCVar(CCVars.ZombieMaxInitialInfected);
|
||||
|
||||
var numInfected = Math.Max(1,
|
||||
(int) Math.Min(
|
||||
Math.Floor((double) playerList.Count / playersPerInfected), maxInfected));
|
||||
Math.Floor((double) playerList.Count / component.PlayersPerInfected), component.MaxInitialInfected));
|
||||
|
||||
// How long the zombies have as a group to decide to begin their attack.
|
||||
// Varies randomly from 20 to 30 minutes. After this the virus begins and they start
|
||||
// taking zombie virus damage.
|
||||
var groupTimelimit = _random.NextFloat(component.MinZombieForceSecs, component.MaxZombieForceSecs);
|
||||
for (var i = 0; i < numInfected; i++)
|
||||
var totalInfected = 0;
|
||||
while (totalInfected < numInfected)
|
||||
{
|
||||
IPlayerSession zombie;
|
||||
if (prefList.Count == 0)
|
||||
{
|
||||
if (playerList.Count == 0)
|
||||
{
|
||||
Logger.InfoS("preset", "Insufficient number of players. stopping selection.");
|
||||
Log.Info("Insufficient number of players. stopping selection.");
|
||||
break;
|
||||
}
|
||||
zombie = _random.PickAndTake(playerList);
|
||||
Logger.InfoS("preset", "Insufficient preferred patient 0, picking at random.");
|
||||
zombie = _random.Pick(playerList);
|
||||
Log.Info("Insufficient preferred patient 0, picking at random.");
|
||||
}
|
||||
else
|
||||
{
|
||||
zombie = _random.PickAndTake(prefList);
|
||||
playerList.Remove(zombie);
|
||||
Logger.InfoS("preset", "Selected a patient 0.");
|
||||
zombie = _random.Pick(prefList);
|
||||
Log.Info("Selected a patient 0.");
|
||||
}
|
||||
|
||||
var mind = zombie.Data.ContentData()?.Mind;
|
||||
if (mind == null)
|
||||
{
|
||||
Logger.ErrorS("preset", "Failed getting mind for picked patient 0.");
|
||||
prefList.Remove(zombie);
|
||||
playerList.Remove(zombie);
|
||||
if (zombie.Data.ContentData()?.Mind is not { } mind || mind.OwnedEntity is not { } ownedEntity)
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugTools.AssertNotNull(mind.OwnedEntity);
|
||||
_mindSystem.AddRole(mind, new ZombieRole(mind, _prototypeManager.Index<AntagPrototype>(component.PatientZeroPrototypeID)));
|
||||
totalInfected++;
|
||||
|
||||
var inCharacterName = string.Empty;
|
||||
// Create some variation between the times of each zombie, relative to the time of the group as a whole.
|
||||
var personalDelay = _random.NextFloat(0.0f, component.PlayerZombieForceVariationSecs);
|
||||
if (mind.OwnedEntity != null)
|
||||
{
|
||||
var pending = EnsureComp<PendingZombieComponent>(mind.OwnedEntity.Value);
|
||||
// Only take damage after this many seconds
|
||||
pending.InfectedSecs = -(int)(groupTimelimit + personalDelay);
|
||||
EnsureComp<ZombifyOnDeathComponent>(mind.OwnedEntity.Value);
|
||||
inCharacterName = MetaData(mind.OwnedEntity.Value).EntityName;
|
||||
_mindSystem.AddRole(mind, new ZombieRole(mind, _prototypeManager.Index<AntagPrototype>(component.PatientZeroPrototypeId)));
|
||||
|
||||
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(ZombieRuleComponent.ZombifySelfActionPrototype));
|
||||
_action.AddAction(mind.OwnedEntity.Value, action, null);
|
||||
}
|
||||
var pending = EnsureComp<PendingZombieComponent>(ownedEntity);
|
||||
pending.GracePeriod = _random.Next(component.MinInitialInfectedGrace, component.MaxInitialInfectedGrace);
|
||||
EnsureComp<ZombifyOnDeathComponent>(ownedEntity);
|
||||
EnsureComp<IncurableZombieComponent>(ownedEntity);
|
||||
var inCharacterName = MetaData(ownedEntity).EntityName;
|
||||
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(ZombieRuleComponent.ZombifySelfActionPrototype));
|
||||
_action.AddAction(mind.OwnedEntity.Value, action, null);
|
||||
|
||||
if (mind.Session != null)
|
||||
{
|
||||
var message = Loc.GetString("zombie-patientzero-role-greeting");
|
||||
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
|
||||
var message = Loc.GetString("zombie-patientzero-role-greeting");
|
||||
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
|
||||
|
||||
//gets the names now in case the players leave.
|
||||
//this gets unhappy if people with the same name get chose. Probably shouldn't happen.
|
||||
component.InitialInfectedNames.Add(inCharacterName, mind.Session.Name);
|
||||
//gets the names now in case the players leave.
|
||||
//this gets unhappy if people with the same name get chosen. Probably shouldn't happen.
|
||||
component.InitialInfectedNames.Add(inCharacterName, zombie.Name);
|
||||
|
||||
// I went all the way to ChatManager.cs and all i got was this lousy T-shirt
|
||||
// You got a free T-shirt!?!?
|
||||
_chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
|
||||
wrappedMessage, default, false, mind.Session.ConnectedClient, Color.Plum);
|
||||
}
|
||||
// I went all the way to ChatManager.cs and all i got was this lousy T-shirt
|
||||
// You got a free T-shirt!?!?
|
||||
_chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
|
||||
wrappedMessage, default, false, zombie.ConnectedClient, Color.Plum);
|
||||
_audio.PlayGlobal(component.InitialInfectedSound, ownedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user