Traitor (#2566)
* basic implementation * minor fixes * objectives temp commit * proper onstart bind * changes all conditions to be bound to a mind-instance * oops * oops v2 * adds possiblity to enable duplicate assignment of objective equal objectives are unable to be added * minor fixes, adds greentext * refactors incompatability to be defined by requirements * fixes a wrong whitespace * minor fix * addressed reviews v1 * address reviews v2 Co-authored-by: Exp <theexp111@gmail.com> * final sweep * adds/refactors traitor&sss cvars * Update Content.Server/Mobs/Mind.cs * never trust github web * adds datasets & makes codewords use them * addresses exp's reviews * addressed zumos reviews Co-authored-by: Paul <ritter.paul1+git@googlemail.com> Co-authored-by: Exp <theexp111@gmail.com>
This commit is contained in:
@@ -15,5 +15,9 @@ namespace Content.Server.GameTicking
|
||||
public virtual string Description => "Secret!";
|
||||
public virtual bool DisallowLateJoin => false;
|
||||
public Dictionary<NetUserId, HumanoidCharacterProfile> readyProfiles;
|
||||
|
||||
public virtual void OnGameStarted() { }
|
||||
|
||||
public virtual string GetRoundEndDescription() => "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
|
||||
public override bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false)
|
||||
{
|
||||
MinPlayers = _cfg.GetCVar(CCVars.GameSuspicionMinPlayers);
|
||||
MinTraitors = _cfg.GetCVar(CCVars.GameSuspicionMinTraitors);
|
||||
PlayersPerTraitor = _cfg.GetCVar(CCVars.GameSuspicionPlayersPerTraitor);
|
||||
TraitorStartingBalance = _cfg.GetCVar(CCVars.GameSuspicionStartingBalance);
|
||||
MinPlayers = _cfg.GetCVar(CCVars.SuspicionMinPlayers);
|
||||
MinTraitors = _cfg.GetCVar(CCVars.SuspicionMinTraitors);
|
||||
PlayersPerTraitor = _cfg.GetCVar(CCVars.SuspicionPlayersPerTraitor);
|
||||
TraitorStartingBalance = _cfg.GetCVar(CCVars.SuspicionStartingBalance);
|
||||
|
||||
if (!force && readyPlayers.Count < MinPlayers)
|
||||
{
|
||||
|
||||
213
Content.Server/GameTicking/GamePresets/PresetTraitor.cs
Normal file
213
Content.Server/GameTicking/GamePresets/PresetTraitor.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.PDA;
|
||||
using Content.Server.GameTicking.GameRules;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Mobs.Roles.Traitor;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Prototypes;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.Components.PDA;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
public class PresetTraitor : GamePreset
|
||||
{
|
||||
[Dependency] private readonly IGameTicker _gameticker = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public override string ModeTitle => "Traitor";
|
||||
|
||||
private int MinPlayers { get; set; }
|
||||
private int PlayersPerTraitor { get; set; }
|
||||
private int MaxTraitors { get; set; }
|
||||
private int CodewordCount { get; set; }
|
||||
private int StartingBalance { get; set; }
|
||||
private float MaxDifficulty { get; set; }
|
||||
private int MaxPicks { get; set; }
|
||||
|
||||
private readonly List<TraitorRole> _traitors = new ();
|
||||
|
||||
public override bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false)
|
||||
{
|
||||
MinPlayers = _cfg.GetCVar(CCVars.TraitorMinPlayers);
|
||||
PlayersPerTraitor = _cfg.GetCVar(CCVars.TraitorPlayersPerTraitor);
|
||||
MaxTraitors = _cfg.GetCVar(CCVars.TraitorMaxTraitors);
|
||||
CodewordCount = _cfg.GetCVar(CCVars.TraitorCodewordCount);
|
||||
StartingBalance = _cfg.GetCVar(CCVars.TraitorStartingBalance);
|
||||
MaxDifficulty = _cfg.GetCVar(CCVars.TraitorMaxDifficulty);
|
||||
MaxPicks = _cfg.GetCVar(CCVars.TraitorMaxPicks);
|
||||
|
||||
if (!force && readyPlayers.Count < MinPlayers)
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement($"Not enough players readied up for the game! There were {readyPlayers.Count} players readied up out of {MinPlayers} needed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readyPlayers.Count == 0)
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement("No players readied up! Can't start Traitor.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var list = new List<IPlayerSession>(readyPlayers);
|
||||
var prefList = new List<IPlayerSession>();
|
||||
|
||||
foreach (var player in list)
|
||||
{
|
||||
if (!readyProfiles.ContainsKey(player.UserId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var profile = readyProfiles[player.UserId];
|
||||
if (profile.AntagPreferences.Contains("Traitor"))
|
||||
{
|
||||
prefList.Add(player);
|
||||
}
|
||||
}
|
||||
|
||||
var numTraitors = MathHelper.Clamp(readyPlayers.Count / PlayersPerTraitor,
|
||||
1, MaxTraitors);
|
||||
|
||||
for (var i = 0; i < numTraitors; i++)
|
||||
{
|
||||
IPlayerSession traitor;
|
||||
if(prefList.Count < numTraitors)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
Logger.InfoS("preset", "Insufficient ready players to fill up with traitors, stopping the selection.");
|
||||
break;
|
||||
}
|
||||
traitor = _random.PickAndTake(list);
|
||||
Logger.InfoS("preset", "Insufficient preferred traitors, picking at random.");
|
||||
}
|
||||
else
|
||||
{
|
||||
traitor = _random.PickAndTake(prefList);
|
||||
list.Remove(traitor);
|
||||
Logger.InfoS("preset", "Selected a preferred traitor.");
|
||||
}
|
||||
var mind = traitor.Data.ContentData()?.Mind;
|
||||
var traitorRole = new TraitorRole(mind);
|
||||
if (mind == null)
|
||||
{
|
||||
Logger.ErrorS("preset", "Failed getting mind for picked traitor.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// creadth: we need to create uplink for the antag.
|
||||
// PDA should be in place already, so we just need to
|
||||
// initiate uplink account.
|
||||
var uplinkAccount = new UplinkAccount(mind.OwnedEntity.Uid, StartingBalance);
|
||||
var inventory = mind.OwnedEntity.GetComponent<InventoryComponent>();
|
||||
if (!inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent pdaItem))
|
||||
{
|
||||
Logger.ErrorS("preset", "Failed getting pda for picked traitor.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var pda = pdaItem.Owner;
|
||||
|
||||
var pdaComponent = pda.GetComponent<PDAComponent>();
|
||||
if (pdaComponent.IdSlotEmpty)
|
||||
{
|
||||
Logger.ErrorS("preset","PDA had no id for picked traitor");
|
||||
continue;
|
||||
}
|
||||
|
||||
mind.AddRole(traitorRole);
|
||||
_traitors.Add(traitorRole);
|
||||
pdaComponent.InitUplinkAccount(uplinkAccount);
|
||||
}
|
||||
|
||||
var adjectives = _prototypeManager.Index<DatasetPrototype>("adjectives").Values;
|
||||
var verbs = _prototypeManager.Index<DatasetPrototype>("verbs").Values;
|
||||
|
||||
var codewordPool = adjectives.Concat(verbs).ToList();
|
||||
var finalCodewordCount = Math.Min(CodewordCount, codewordPool.Count);
|
||||
var codewords = new string[finalCodewordCount];
|
||||
for (var i = 0; i < finalCodewordCount; i++)
|
||||
{
|
||||
codewords[i] = _random.PickAndTake(codewordPool);
|
||||
}
|
||||
|
||||
foreach (var traitor in _traitors)
|
||||
{
|
||||
traitor.GreetTraitor(codewords);
|
||||
}
|
||||
|
||||
_gameticker.AddGameRule<RuleTraitor>();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnGameStarted()
|
||||
{
|
||||
var objectivesMgr = IoCManager.Resolve<IObjectivesManager>();
|
||||
foreach (var traitor in _traitors)
|
||||
{
|
||||
//give traitors their objectives
|
||||
var difficulty = 0f;
|
||||
for (var pick = 0; pick < MaxPicks && MaxDifficulty > difficulty; pick++)
|
||||
{
|
||||
var objective = objectivesMgr.GetRandomObjective(traitor.Mind);
|
||||
if (objective == null) continue;
|
||||
if (traitor.Mind.TryAddObjective(objective))
|
||||
difficulty += objective.Difficulty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetRoundEndDescription()
|
||||
{
|
||||
var traitorCount = _traitors.Count;
|
||||
var result = Loc.GetString("There {0} {1} {2}.", Loc.GetPluralString("was", "were", traitorCount),
|
||||
traitorCount, Loc.GetPluralString("traitor", "traitors", traitorCount));
|
||||
foreach (var traitor in _traitors)
|
||||
{
|
||||
result += Loc.GetString("\n{0} was a traitor",traitor.Mind.Session.Name);
|
||||
var objectives = traitor.Mind.AllObjectives.ToArray();
|
||||
if (objectives.Length == 0)
|
||||
{
|
||||
result += ".\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
result += Loc.GetString(" and had the following objectives:");
|
||||
foreach (var objectiveGroup in objectives.GroupBy(o => o.Prototype.Issuer))
|
||||
{
|
||||
result += $"\n[color=#87cefa]{Loc.GetString(objectiveGroup.Key)}[/color]";
|
||||
foreach (var objective in objectiveGroup)
|
||||
{
|
||||
foreach (var condition in objective.Conditions)
|
||||
{
|
||||
var progress = condition.Progress;
|
||||
result +=
|
||||
Loc.GetString("\n- {0} | {1}", condition.Title, (progress > 0.99f ? $"[color=green]{Loc.GetString("Success!")}[/color]" : $"[color=red]{Loc.GetString("Failed!")}[/color] ({(int) (progress * 100)}%)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Content.Server/GameTicking/GameRules/RuleTraitor.cs
Normal file
36
Content.Server/GameTicking/GameRules/RuleTraitor.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Mobs.Roles.Traitor;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
|
||||
namespace Content.Server.GameTicking.GameRules
|
||||
{
|
||||
public class RuleTraitor : GameRule
|
||||
{
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public override void Added()
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("Hello crew! Have a good shift!"));
|
||||
|
||||
bool Predicate(IPlayerSession session) => session.ContentData()?.Mind?.HasRole<TraitorRole>() ?? false;
|
||||
|
||||
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Misc/tatoralert.ogg", AudioParams.Default, Predicate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,15 @@ namespace Content.Server.GameTicking
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public GamePreset Preset
|
||||
{
|
||||
get => _preset == null ? MakeGamePreset(null) : _preset;
|
||||
set => _preset = value;
|
||||
}
|
||||
|
||||
private GamePreset _preset;
|
||||
|
||||
public event Action<GameRunLevelChangedEventArgs> OnRunLevelChanged;
|
||||
public event Action<GameRuleAddedEventArgs> OnRuleAdded;
|
||||
|
||||
@@ -278,18 +287,18 @@ namespace Content.Server.GameTicking
|
||||
}
|
||||
|
||||
// Time to start the preset.
|
||||
var preset = MakeGamePreset(profiles);
|
||||
Preset = MakeGamePreset(profiles);
|
||||
|
||||
DisallowLateJoin |= preset.DisallowLateJoin;
|
||||
DisallowLateJoin |= Preset.DisallowLateJoin;
|
||||
|
||||
if (!preset.Start(assignedJobs.Keys.ToList(), force))
|
||||
if (!Preset.Start(assignedJobs.Keys.ToList(), force))
|
||||
{
|
||||
if (_configurationManager.GetCVar(CCVars.GameLobbyFallbackEnabled))
|
||||
{
|
||||
SetStartPreset(_configurationManager.GetCVar(CCVars.GameLobbyFallbackPreset));
|
||||
var newPreset = MakeGamePreset(profiles);
|
||||
_chatManager.DispatchServerAnnouncement(
|
||||
$"Failed to start {preset.ModeTitle} mode! Defaulting to {newPreset.ModeTitle}...");
|
||||
$"Failed to start {Preset.ModeTitle} mode! Defaulting to {newPreset.ModeTitle}...");
|
||||
if (!newPreset.Start(readyPlayers, force))
|
||||
{
|
||||
throw new ApplicationException("Fallback preset failed to start!");
|
||||
@@ -297,15 +306,17 @@ namespace Content.Server.GameTicking
|
||||
|
||||
DisallowLateJoin = false;
|
||||
DisallowLateJoin |= newPreset.DisallowLateJoin;
|
||||
Preset = newPreset;
|
||||
}
|
||||
else
|
||||
{
|
||||
SendServerMessage($"Failed to start {preset.ModeTitle} mode! Restarting round...");
|
||||
SendServerMessage($"Failed to start {Preset.ModeTitle} mode! Restarting round...");
|
||||
RestartRound();
|
||||
DelayStart(TimeSpan.FromSeconds(PresetFailedCooldownIncrease));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Preset.OnGameStarted();
|
||||
|
||||
_roundStartTimeSpan = IoCManager.Resolve<IGameTiming>().RealTime;
|
||||
_sendStatusToAll();
|
||||
@@ -342,8 +353,8 @@ namespace Content.Server.GameTicking
|
||||
|
||||
//Tell every client the round has ended.
|
||||
var roundEndMessage = _netManager.CreateNetMessage<MsgRoundEndMessage>();
|
||||
roundEndMessage.GamemodeTitle = MakeGamePreset(null).ModeTitle;
|
||||
roundEndMessage.RoundEndText = roundEndText;
|
||||
roundEndMessage.GamemodeTitle = Preset.ModeTitle;
|
||||
roundEndMessage.RoundEndText = roundEndText + $"\n{Preset.GetRoundEndDescription()}";
|
||||
|
||||
//Get the timespan of the round.
|
||||
roundEndMessage.RoundDuration = IoCManager.Resolve<IGameTiming>().RealTime.Subtract(_roundStartTimeSpan);
|
||||
@@ -472,6 +483,7 @@ namespace Content.Server.GameTicking
|
||||
"sandbox" => typeof(PresetSandbox),
|
||||
"deathmatch" => typeof(PresetDeathMatch),
|
||||
"suspicion" => typeof(PresetSuspicion),
|
||||
"traitor" => typeof(PresetTraitor),
|
||||
_ => default
|
||||
};
|
||||
|
||||
@@ -1003,8 +1015,8 @@ namespace Content.Server.GameTicking
|
||||
|
||||
private string GetInfoText()
|
||||
{
|
||||
var gmTitle = MakeGamePreset(null).ModeTitle;
|
||||
var desc = MakeGamePreset(null).Description;
|
||||
var gmTitle = Preset.ModeTitle;
|
||||
var desc = Preset.Description;
|
||||
return Loc.GetString(@"Hi and welcome to [color=white]Space Station 14![/color]
|
||||
|
||||
The current game mode is: [color=white]{0}[/color].
|
||||
|
||||
Reference in New Issue
Block a user