Merge branch 'master' into buckle-locker-fix-1262

This commit is contained in:
DrSmugleaf
2020-07-07 00:20:07 +02:00
267 changed files with 3520 additions and 1075 deletions

View File

@@ -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;
}
}

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

View File

@@ -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

View File

@@ -10,6 +10,7 @@ using Content.Server.GameObjects.Components.Markers;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
using Content.Server.GameObjects.Components.PDA;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding;
using Content.Server.GameTicking.GamePresets;
@@ -23,6 +24,7 @@ using Content.Shared;
using Content.Shared.Chat;
using Content.Shared.GameObjects.Components.PDA;
using Content.Shared.Jobs;
using Content.Shared.Physics;
using Content.Shared.Preferences;
using Prometheus;
using Robust.Server.Interfaces;
@@ -33,6 +35,7 @@ using Robust.Server.ServerStatus;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.GameObjects;
@@ -266,12 +269,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))
@@ -305,7 +308,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);
@@ -317,13 +320,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
};
@@ -804,7 +807,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,
@@ -882,8 +885,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].
@@ -897,9 +900,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