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
+1 -1
View File
@@ -183,7 +183,7 @@
<Compile Include="Source\GameSession\HireManager.cs" /> <Compile Include="Source\GameSession\HireManager.cs" />
<Compile Include="Source\Characters\Animation\HumanoidAnimController.cs" /> <Compile Include="Source\Characters\Animation\HumanoidAnimController.cs" />
<Compile Include="Source\GameSession\GameModes\SinglePlayerMode.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\ComponentStyle.cs" />
<Compile Include="Source\GUI\GUIImage.cs" /> <Compile Include="Source\GUI\GUIImage.cs" />
<Compile Include="Source\GUI\GUIMessageBox.cs" /> <Compile Include="Source\GUI\GUIMessageBox.cs" />
@@ -5,6 +5,16 @@ namespace Barotrauma
{ {
class TraitorManager class TraitorManager
{ {
public Character TraitorCharacter
{
get { return traitorCharacter; }
}
public Character TargetCharacter
{
get { return targetCharacter; }
}
private Character traitorCharacter, targetCharacter; private Character traitorCharacter, targetCharacter;
public TraitorManager(GameServer server) public TraitorManager(GameServer server)
@@ -19,8 +29,8 @@ namespace Barotrauma
List<Character> characters = new List<Character>(); List<Character> characters = new List<Character>();
foreach (Client client in server.ConnectedClients) foreach (Client client in server.ConnectedClients)
{ {
if (!client.inGame || client.Character==null) continue; if (client.Character != null)
characters.Add(client.Character); characters.Add(client.Character);
} }
if (server.Character!= null) characters.Add(server.Character); if (server.Character!= null) characters.Add(server.Character);
@@ -52,8 +62,6 @@ namespace Barotrauma
CreateStartPopUp(traitorCharacter.Name); CreateStartPopUp(traitorCharacter.Name);
return; return;
} }
server.NewTraitor(traitorCharacter, targetCharacter);
} }
public static void CreateStartPopUp(string targetName) public static void CreateStartPopUp(string targetName)
+7 -11
View File
@@ -590,6 +590,9 @@ namespace Barotrauma.Networking
bool respawnAllowed = inc.ReadBoolean(); bool respawnAllowed = inc.ReadBoolean();
bool loadSecondSub = 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); GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName);
if (gameMode == null) if (gameMode == null)
@@ -615,16 +618,10 @@ namespace Barotrauma.Networking
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle); if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle);
//int characterCount = inc.ReadByte(); if (isTraitor)
//for (int i = 0; i < characterCount; i++) {
//{ TraitorManager.CreateStartPopUp(traitorTargetName);
// var character = Character.ReadSpawnData(inc); }
// if (inc.ReadBoolean())
// {
// myCharacter = character;
// Character.Controlled = character;
// }
//}
gameStarted = true; gameStarted = true;
@@ -678,7 +675,6 @@ namespace Barotrauma.Networking
List<Submarine> submarines = new List<Submarine>(); List<Submarine> submarines = new List<Submarine>();
for (int i = 0; i < subListCount; i++) for (int i = 0; i < subListCount; i++)
{ {
string subName = inc.ReadString(); string subName = inc.ReadString();
string subHash = inc.ReadString(); string subHash = inc.ReadString();
+25 -13
View File
@@ -1026,6 +1026,18 @@ namespace Barotrauma.Networking
Entity.Spawner.AddToSpawnedList(c.SpawnItems); 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); SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients);
//var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset); //var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
//server.SendMessage(startMessage, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0); //server.SendMessage(startMessage, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
@@ -1081,6 +1093,19 @@ namespace Barotrauma.Networking
msg.Write(AllowRespawn && missionAllowRespawn); msg.Write(AllowRespawn && missionAllowRespawn);
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub 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); 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> /// <summary>
/// Add the message to the chatbox and pass it to all clients who can receive it /// Add the message to the chatbox and pass it to all clients who can receive it
/// </summary> /// </summary>