Antag preferences and antag prototype (#1264)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
ike709
2020-07-06 16:24:29 -05:00
committed by GitHub
parent cee8aaa84c
commit c019d428a7
42 changed files with 833 additions and 50 deletions

View File

@@ -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>();