Round end zombie percentage changes (#15620)

This commit is contained in:
Slava0135
2023-05-02 17:31:14 +03:00
committed by GitHub
parent 16bf09a1ac
commit 28c560431a

View File

@@ -61,17 +61,17 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
{ {
foreach (var zombie in EntityQuery<ZombieRuleComponent>()) foreach (var zombie in EntityQuery<ZombieRuleComponent>())
{ {
//this is just the general condition thing used for determining the win/lose text // This is just the general condition thing used for determining the win/lose text
var percent = GetInfectedPercentage(out var livingHumans); var fraction = GetInfectedFraction();
if (percent <= 0) if (fraction <= 0)
ev.AddLine(Loc.GetString("zombie-round-end-amount-none")); ev.AddLine(Loc.GetString("zombie-round-end-amount-none"));
else if (percent <= 0.25) else if (fraction <= 0.25)
ev.AddLine(Loc.GetString("zombie-round-end-amount-low")); ev.AddLine(Loc.GetString("zombie-round-end-amount-low"));
else if (percent <= 0.5) else if (fraction <= 0.5)
ev.AddLine(Loc.GetString("zombie-round-end-amount-medium", ("percent", Math.Round((percent * 100), 2).ToString(CultureInfo.InvariantCulture)))); ev.AddLine(Loc.GetString("zombie-round-end-amount-medium", ("percent", Math.Round((fraction * 100), 2).ToString(CultureInfo.InvariantCulture))));
else if (percent < 1) else if (fraction < 1)
ev.AddLine(Loc.GetString("zombie-round-end-amount-high", ("percent", Math.Round((percent * 100), 2).ToString(CultureInfo.InvariantCulture)))); ev.AddLine(Loc.GetString("zombie-round-end-amount-high", ("percent", Math.Round((fraction * 100), 2).ToString(CultureInfo.InvariantCulture))));
else else
ev.AddLine(Loc.GetString("zombie-round-end-amount-all")); ev.AddLine(Loc.GetString("zombie-round-end-amount-all"));
@@ -83,13 +83,14 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
("username", player.Value))); ("username", player.Value)));
} }
//Gets a bunch of the living players and displays them if they're under a threshold. var healthy = GetHealthyHumans();
//InitialInfected is used for the threshold because it scales with the player count well. // Gets a bunch of the living players and displays them if they're under a threshold.
if (livingHumans.Count > 0 && livingHumans.Count <= zombie.InitialInfectedNames.Count) // InitialInfected is used for the threshold because it scales with the player count well.
if (healthy.Count > 0 && healthy.Count <= 2 * zombie.InitialInfectedNames.Count)
{ {
ev.AddLine(""); ev.AddLine("");
ev.AddLine(Loc.GetString("zombie-round-end-survivor-count", ("count", livingHumans.Count))); ev.AddLine(Loc.GetString("zombie-round-end-survivor-count", ("count", healthy.Count)));
foreach (var survivor in livingHumans) foreach (var survivor in healthy)
{ {
var meta = MetaData(survivor); var meta = MetaData(survivor);
var username = string.Empty; var username = string.Empty;
@@ -142,14 +143,15 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
if (GameTicker.IsGameRuleActive(uid, gameRule)) if (GameTicker.IsGameRuleActive(uid, gameRule))
continue; continue;
//we only care about players, not monkeys and such. // We only care about players, not monkeys and such.
if (!HasComp<HumanoidAppearanceComponent>(target)) if (!HasComp<HumanoidAppearanceComponent>(target))
continue; continue;
var percent = GetInfectedPercentage(out var num); var fraction = GetInfectedFraction();
if (num.Count == 1) //only one human left. spooky var healthy = GetHealthyHumans();
_popup.PopupEntity(Loc.GetString("zombie-alone"), num[0], num[0]); if (healthy.Count == 1) // Only one human left. spooky
if (percent >= 1) //oops, all zombies _popup.PopupEntity(Loc.GetString("zombie-alone"), healthy[0], healthy[0]);
if (fraction >= 1) // Oops, all zombies
_roundEndSystem.EndRound(); _roundEndSystem.EndRound();
} }
} }
@@ -192,29 +194,27 @@ public sealed class ZombieRuleSystem : GameRuleSystem<ZombieRuleComponent>
_action.RemoveAction(uid, action); _action.RemoveAction(uid, action);
} }
private float GetInfectedPercentage(out List<EntityUid> livingHumans) private float GetInfectedFraction()
{ {
var allPlayers = EntityQuery<HumanoidAppearanceComponent, MobStateComponent>(true); var players = EntityQuery<HumanoidAppearanceComponent>(true);
var allZombers = GetEntityQuery<ZombieComponent>(); var zombers = EntityQuery<HumanoidAppearanceComponent, ZombieComponent>(true);
var totalPlayers = new List<EntityUid>(); return zombers.Count() / (float) players.Count();
var livingZombies = new List<EntityUid>(); }
livingHumans = new(); private List<EntityUid> GetHealthyHumans()
{
foreach (var (_, mob) in allPlayers) var healthy = new List<EntityUid>();
var players = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent>();
var zombers = GetEntityQuery<ZombieComponent>();
while (players.MoveNext(out var uid, out _, out var mob))
{ {
if (_mobState.IsAlive(mob.Owner, mob)) if (_mobState.IsAlive(uid, mob) && !zombers.HasComponent(uid))
{ {
totalPlayers.Add(mob.Owner); healthy.Add(uid);
if (allZombers.HasComponent(mob.Owner))
livingZombies.Add(mob.Owner);
else
livingHumans.Add(mob.Owner);
} }
} }
return livingZombies.Count / (float) totalPlayers.Count; return healthy;
} }
/// <summary> /// <summary>