Readded traitors

This commit is contained in:
Regalis
2017-01-30 19:49:13 +02:00
parent 6bbd11630d
commit 0cd2d7a0b9
4 changed files with 46 additions and 30 deletions

View File

@@ -183,7 +183,7 @@
<Compile Include="Source\GameSession\HireManager.cs" />
<Compile Include="Source\Characters\Animation\HumanoidAnimController.cs" />
<Compile Include="Source\GameSession\GameModes\SinglePlayerMode.cs" />
<Compile Include="Source\GameSession\GameModes\TraitorMode.cs" />
<Compile Include="Source\GameSession\GameModes\TraitorManager.cs" />
<Compile Include="Source\GUI\ComponentStyle.cs" />
<Compile Include="Source\GUI\GUIImage.cs" />
<Compile Include="Source\GUI\GUIMessageBox.cs" />

View File

@@ -5,8 +5,18 @@ namespace Barotrauma
{
class TraitorManager
{
private Character traitorCharacter, targetCharacter;
public Character TraitorCharacter
{
get { return traitorCharacter; }
}
public Character TargetCharacter
{
get { return targetCharacter; }
}
private Character traitorCharacter, targetCharacter;
public TraitorManager(GameServer server)
{
Start(server);
@@ -19,8 +29,8 @@ namespace Barotrauma
List<Character> characters = new List<Character>();
foreach (Client client in server.ConnectedClients)
{
if (!client.inGame || client.Character==null) continue;
characters.Add(client.Character);
if (client.Character != null)
characters.Add(client.Character);
}
if (server.Character!= null) characters.Add(server.Character);
@@ -52,8 +62,6 @@ namespace Barotrauma
CreateStartPopUp(traitorCharacter.Name);
return;
}
server.NewTraitor(traitorCharacter, targetCharacter);
}
public static void CreateStartPopUp(string targetName)

View File

@@ -589,6 +589,9 @@ namespace Barotrauma.Networking
bool respawnAllowed = inc.ReadBoolean();
bool loadSecondSub = inc.ReadBoolean();
bool isTraitor = inc.ReadBoolean();
string traitorTargetName = isTraitor ? inc.ReadString() : null;
GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName);
@@ -615,16 +618,10 @@ namespace Barotrauma.Networking
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle);
//int characterCount = inc.ReadByte();
//for (int i = 0; i < characterCount; i++)
//{
// var character = Character.ReadSpawnData(inc);
// if (inc.ReadBoolean())
// {
// myCharacter = character;
// Character.Controlled = character;
// }
//}
if (isTraitor)
{
TraitorManager.CreateStartPopUp(traitorTargetName);
}
gameStarted = true;
@@ -678,7 +675,6 @@ namespace Barotrauma.Networking
List<Submarine> submarines = new List<Submarine>();
for (int i = 0; i < subListCount; i++)
{
string subName = inc.ReadString();
string subHash = inc.ReadString();

View File

@@ -1025,6 +1025,18 @@ namespace Barotrauma.Networking
Entity.Spawner.AddToSpawnedList(c);
Entity.Spawner.AddToSpawnedList(c.SpawnItems);
}
TraitorManager = null;
if (TraitorsEnabled == YesNoMaybe.Yes ||
(TraitorsEnabled == YesNoMaybe.Maybe && Rand.Range(0.0f, 1.0f) < 0.5f))
{
TraitorManager = new TraitorManager(this);
if (TraitorManager.TraitorCharacter!=null && TraitorManager.TargetCharacter != null)
{
Log(TraitorManager.TraitorCharacter.Name + " is the traitor and the target is " + TraitorManager.TargetCharacter.Name, Color.Cyan);
}
}
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients);
//var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
@@ -1080,6 +1092,19 @@ namespace Barotrauma.Networking
msg.Write(AllowRespawn && missionAllowRespawn);
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub
if (TraitorManager != null &&
TraitorManager.TraitorCharacter != null &&
TraitorManager.TargetCharacter != null &&
TraitorManager.TraitorCharacter == client.Character)
{
msg.Write(true);
msg.Write(TraitorManager.TargetCharacter.Name);
}
else
{
msg.Write(false);
}
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
}
@@ -1263,19 +1288,6 @@ namespace Barotrauma.Networking
}
}
public void NewTraitor(Character traitor, Character target)
{
Log(traitor.Name + " is the traitor and the target is " + target.Name, Color.Cyan);
Client traitorClient = null;
foreach (Client c in connectedClients)
{
if (c.Character != traitor) continue;
traitorClient = c;
break;
}
}
/// <summary>
/// Add the message to the chatbox and pass it to all clients who can receive it
/// </summary>