Antag preferences and antag prototype (#1264)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Content.Shared.Preferences;
|
||||
|
||||
namespace Content.Server.GameTicking
|
||||
{
|
||||
@@ -11,5 +12,6 @@ namespace Content.Server.GameTicking
|
||||
public abstract bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false);
|
||||
public virtual string ModeTitle => "Sandbox";
|
||||
public virtual string Description => "Secret!";
|
||||
public Dictionary<string, HumanoidCharacterProfile> readyProfiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameTicking.GameRules;
|
||||
using Content.Server.GameTicking.GameRules;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Mobs.Roles;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Sandbox;
|
||||
using NFluidsynth;
|
||||
using Content.Shared.Antags;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Log;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Preferences;
|
||||
|
||||
|
||||
|
||||
namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
@@ -21,11 +27,14 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
[Dependency] private readonly IChatManager _chatManager;
|
||||
[Dependency] private readonly IGameTicker _gameTicker;
|
||||
[Dependency] private readonly IRobustRandom _random;
|
||||
[Dependency] private IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public int MinPlayers { get; set; } = 5;
|
||||
public int MinTraitors { get; set; } = 2;
|
||||
public int PlayersPerTraitor { get; set; } = 5;
|
||||
private static string TraitorID = "SuspicionTraitor";
|
||||
private static string InnocentID = "SuspicionInnocent";
|
||||
|
||||
public override bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false)
|
||||
{
|
||||
@@ -36,20 +45,48 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
}
|
||||
|
||||
var list = new List<IPlayerSession>(readyPlayers);
|
||||
var prefList = new List<IPlayerSession>();
|
||||
|
||||
foreach (var player in list)
|
||||
{
|
||||
if (!readyProfiles.ContainsKey(player.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var profile = readyProfiles[player.Name];
|
||||
if (profile.AntagPreferences.Contains(_prototypeManager.Index<AntagPrototype>(TraitorID).Name))
|
||||
{
|
||||
prefList.Add(player);
|
||||
}
|
||||
}
|
||||
|
||||
var numTraitors = Math.Clamp(readyPlayers.Count % PlayersPerTraitor,
|
||||
MinTraitors, readyPlayers.Count);
|
||||
|
||||
for (var i = 0; i < numTraitors; i++)
|
||||
{
|
||||
var traitor = _random.PickAndTake(list);
|
||||
IPlayerSession traitor;
|
||||
if(prefList.Count() == 0)
|
||||
{
|
||||
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;
|
||||
mind.AddRole(new SuspicionTraitorRole(mind));
|
||||
var antagPrototype = _prototypeManager.Index<AntagPrototype>(TraitorID);
|
||||
mind.AddRole(new SuspicionTraitorRole(mind, antagPrototype));
|
||||
}
|
||||
|
||||
foreach (var player in list)
|
||||
{
|
||||
var mind = player.Data.ContentData().Mind;
|
||||
mind.AddRole(new SuspicionInnocentRole(mind));
|
||||
var antagPrototype = _prototypeManager.Index<AntagPrototype>(InnocentID);
|
||||
mind.AddRole(new SuspicionInnocentRole(mind, antagPrototype));
|
||||
}
|
||||
|
||||
_gameTicker.AddGameRule<RuleSuspicion>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
@@ -38,8 +39,6 @@ namespace Content.Server.GameTicking.GameRules
|
||||
|
||||
public override void Added()
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement("There are traitors on the station! Find them, and kill them!");
|
||||
|
||||
_entityManager.EventBus.SubscribeEvent<MobDamageStateChangedMessage>(EventSource.Local, this, _onMobDamageStateChanged);
|
||||
|
||||
Timer.SpawnRepeating(DeadCheckDelay, _checkWinConditions, _checkTimerCancel.Token);
|
||||
@@ -86,7 +85,6 @@ namespace Content.Server.GameTicking.GameRules
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (playerSession.ContentData().Mind.HasRole<SuspicionTraitorRole>())
|
||||
traitorsAlive++;
|
||||
else
|
||||
|
||||
@@ -267,12 +267,12 @@ namespace Content.Server.GameTicking
|
||||
}
|
||||
|
||||
// Time to start the preset.
|
||||
var preset = MakeGamePreset();
|
||||
var preset = MakeGamePreset(profiles);
|
||||
|
||||
if (!preset.Start(assignedJobs.Keys.ToList(), force))
|
||||
{
|
||||
SetStartPreset(_configurationManager.GetCVar<string>("game.fallbackpreset"));
|
||||
var newPreset = MakeGamePreset();
|
||||
var newPreset = MakeGamePreset(profiles);
|
||||
_chatManager.DispatchServerAnnouncement(
|
||||
$"Failed to start {preset.ModeTitle} mode! Defaulting to {newPreset.ModeTitle}...");
|
||||
if (!newPreset.Start(readyPlayers, force))
|
||||
@@ -306,7 +306,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
//Tell every client the round has ended.
|
||||
var roundEndMessage = _netManager.CreateNetMessage<MsgRoundEndMessage>();
|
||||
roundEndMessage.GamemodeTitle = MakeGamePreset().ModeTitle;
|
||||
roundEndMessage.GamemodeTitle = MakeGamePreset(null).ModeTitle;
|
||||
|
||||
//Get the timespan of the round.
|
||||
roundEndMessage.RoundDuration = IoCManager.Resolve<IGameTiming>().RealTime.Subtract(_roundStartTimeSpan);
|
||||
@@ -318,13 +318,13 @@ namespace Content.Server.GameTicking
|
||||
var mind = ply.ContentData().Mind;
|
||||
if (mind != null)
|
||||
{
|
||||
var antag = mind.AllRoles.Any(role => role.Antag);
|
||||
var antag = mind.AllRoles.Any(role => role.Antagonist);
|
||||
var playerEndRoundInfo = new RoundEndPlayerInfo()
|
||||
{
|
||||
PlayerOOCName = ply.Name,
|
||||
PlayerICName = mind.CurrentEntity.Name,
|
||||
Role = antag
|
||||
? mind.AllRoles.First(role => role.Antag).Name
|
||||
? mind.AllRoles.First(role => role.Antagonist).Name
|
||||
: mind.AllRoles.FirstOrDefault()?.Name ?? Loc.GetString("Unknown"),
|
||||
Antag = antag
|
||||
};
|
||||
@@ -805,7 +805,7 @@ namespace Content.Server.GameTicking
|
||||
var mindComponent = mob.GetComponent<MindComponent>();
|
||||
if (mindComponent.HasMind) //Redundancy checks.
|
||||
{
|
||||
if (mindComponent.Mind.AllRoles.Any(role => role.Antag)) //Give antags a new uplinkaccount.
|
||||
if (mindComponent.Mind.AllRoles.Any(role => role.Antagonist)) //Give antags a new uplinkaccount.
|
||||
{
|
||||
var uplinkAccount =
|
||||
new UplinkAccount(mob.Uid,
|
||||
@@ -883,8 +883,8 @@ namespace Content.Server.GameTicking
|
||||
|
||||
private string GetInfoText()
|
||||
{
|
||||
var gmTitle = MakeGamePreset().ModeTitle;
|
||||
var desc = MakeGamePreset().Description;
|
||||
var gmTitle = MakeGamePreset(null).ModeTitle;
|
||||
var desc = MakeGamePreset(null).Description;
|
||||
return _localization.GetString(@"Hi and welcome to [color=white]Space Station 14![/color]
|
||||
|
||||
The current game mode is: [color=white]{0}[/color].
|
||||
@@ -898,9 +898,11 @@ The current game mode is: [color=white]{0}[/color].
|
||||
_netManager.ServerSendToMany(infoMsg, _playersInLobby.Keys.Select(p => p.ConnectedClient).ToList());
|
||||
}
|
||||
|
||||
private GamePreset MakeGamePreset()
|
||||
private GamePreset MakeGamePreset(Dictionary<string, HumanoidCharacterProfile> readyProfiles)
|
||||
{
|
||||
return _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||
var preset = _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||
preset.readyProfiles = readyProfiles;
|
||||
return preset;
|
||||
}
|
||||
|
||||
#pragma warning disable 649
|
||||
|
||||
Reference in New Issue
Block a user