2020-07-06 16:24:29 -05:00
using Content.Server.GameTicking.GameRules ;
using Content.Server.Interfaces ;
2020-05-03 11:25:39 +02:00
using Content.Server.Interfaces.Chat ;
using Content.Server.Interfaces.GameTicking ;
using Content.Server.Mobs.Roles ;
using Content.Server.Players ;
2020-07-06 16:24:29 -05:00
using Content.Shared.Antags ;
2020-05-03 11:25:39 +02:00
using Robust.Server.Interfaces.Player ;
using Robust.Shared.Interfaces.Random ;
using Robust.Shared.IoC ;
2020-07-06 16:24:29 -05:00
using Robust.Shared.Prototypes ;
2020-05-03 11:25:39 +02:00
using Robust.Shared.Random ;
2020-07-06 16:24:29 -05:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using Robust.Shared.Log ;
using System.Threading.Tasks ;
using Content.Shared.Preferences ;
2020-05-03 11:25:39 +02:00
namespace Content.Server.GameTicking.GamePresets
{
public class PresetSuspicion : GamePreset
{
#pragma warning disable 649
[Dependency] private readonly IChatManager _chatManager ;
[Dependency] private readonly IGameTicker _gameTicker ;
[Dependency] private readonly IRobustRandom _random ;
2020-07-06 16:24:29 -05:00
[Dependency] private IPrototypeManager _prototypeManager ;
2020-05-03 11:25:39 +02:00
#pragma warning restore 649
public int MinPlayers { get ; set ; } = 5 ;
public int MinTraitors { get ; set ; } = 2 ;
public int PlayersPerTraitor { get ; set ; } = 5 ;
2020-07-06 16:24:29 -05:00
private static string TraitorID = "SuspicionTraitor" ;
private static string InnocentID = "SuspicionInnocent" ;
2020-05-03 11:25:39 +02:00
2020-06-21 22:05:47 +02:00
public override bool Start ( IReadOnlyList < IPlayerSession > readyPlayers , bool force = false )
2020-05-03 11:25:39 +02:00
{
2020-06-21 22:05:47 +02:00
if ( ! force & & readyPlayers . Count < MinPlayers )
2020-05-03 11:25:39 +02:00
{
_chatManager . DispatchServerAnnouncement ( $"Not enough players readied up for the game! There were {readyPlayers.Count} players readied up out of {MinPlayers} needed." ) ;
return false ;
}
var list = new List < IPlayerSession > ( readyPlayers ) ;
2020-07-06 16:24:29 -05:00
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 ) ;
}
}
2020-06-21 22:05:47 +02:00
var numTraitors = Math . Clamp ( readyPlayers . Count % PlayersPerTraitor ,
MinTraitors , readyPlayers . Count ) ;
2020-05-03 11:25:39 +02:00
for ( var i = 0 ; i < numTraitors ; i + + )
{
2020-07-06 16:24:29 -05:00
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." ) ;
}
2020-05-03 11:25:39 +02:00
var mind = traitor . Data . ContentData ( ) . Mind ;
2020-07-06 16:24:29 -05:00
var antagPrototype = _prototypeManager . Index < AntagPrototype > ( TraitorID ) ;
mind . AddRole ( new SuspicionTraitorRole ( mind , antagPrototype ) ) ;
2020-05-03 11:25:39 +02:00
}
foreach ( var player in list )
{
var mind = player . Data . ContentData ( ) . Mind ;
2020-07-06 16:24:29 -05:00
var antagPrototype = _prototypeManager . Index < AntagPrototype > ( InnocentID ) ;
mind . AddRole ( new SuspicionInnocentRole ( mind , antagPrototype ) ) ;
2020-05-03 11:25:39 +02:00
}
_gameTicker . AddGameRule < RuleSuspicion > ( ) ;
return true ;
}
public override string ModeTitle = > "Suspicion" ;
public override string Description = > "Suspicion on the Space Station. There are traitors on board... Can you kill them before they kill you?" ;
}
}