commit e6715d605db9bb1d608e4a4990ac41f6214f61d1 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Mar 5 17:22:31 2019 +0200 Fixed the "control" console command not being usable by clients, changed the way arguments are given to the "setclientcharacter" command (no semicolon to separate the names, quotation marks have to be used for multi-word names just like with any other command). Closes #1224 commit acb7c1e0dc05bf619e7ec4875196cc45647d3fb4 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Mar 5 16:30:38 2019 +0200 Steam Workshop fixes: - Install content packages for items that only contain a sub. Otherwise the system can't determine if the item has been updated (and might also be useful for toggling off incompatible subs when switching from mod to another). - Log an error instead of crashing the game if CheckWorkshopItemEnabled or CheckWorkshopItemUpToDate fails due to a missing filelist.xml. - Show a messagebox when a workshop item is updated succesfully. commit b2e8ed565bc03f466930799268c13b2fca4bb9c9 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Mar 5 14:43:42 2019 +0200 Fixed nullref exception when disabling a workshop item that doesn't have an update button (or when enabling the item fails) commit 26f1f285cd80ca6f023b12e6dd80dc71e87ee9c3 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Mar 5 14:15:14 2019 +0200 Fixed console command aliases not being taken into account in GameClient.HasConsoleCommandPermission (meaning that the client needed a permission for each name variant of a command, making it impossible to for example use "fixwalls" instead of "fixhulls"). Closes #1225 commit dee02de681a212efd0e0a82c14619f3fe4839cc4 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Mar 5 13:35:48 2019 +0200 Fixed traitor rounds failing to start if there's no owner client, fixed occasional "traitorCount somehow ended up less than 1" errors due to Rand.Int using 0 as the minimum value. Closes #1217
180 lines
7.1 KiB
C#
180 lines
7.1 KiB
C#
using Barotrauma.Networking;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
partial class Traitor
|
|
{
|
|
public readonly Character Character;
|
|
public Character TargetCharacter; //TODO: make a modular objective system (similar to crew missions) that allows for things OTHER than assasinations.
|
|
|
|
public Traitor(Character character)
|
|
{
|
|
Character = character;
|
|
}
|
|
|
|
public void Greet(GameServer server, string codeWords, string codeResponse)
|
|
{
|
|
string greetingMessage = TextManager.Get("TraitorStartMessage").Replace("[targetname]", TargetCharacter.Name);
|
|
string moreAgentsMessage = TextManager.Get("TraitorMoreAgentsMessage")
|
|
.Replace("[codewords]", codeWords)
|
|
.Replace("[coderesponse]", codeResponse);
|
|
|
|
var greetingChatMsg = ChatMessage.Create(null, greetingMessage, ChatMessageType.Server, null);
|
|
var moreAgentsChatMsg = ChatMessage.Create(null, moreAgentsMessage, ChatMessageType.Server, null);
|
|
|
|
var greetingMsgBox = ChatMessage.Create(null, greetingMessage, ChatMessageType.MessageBox, null);
|
|
var moreAgentsMsgBox = ChatMessage.Create(null, moreAgentsMessage, ChatMessageType.MessageBox, null);
|
|
|
|
Client traitorClient = server.ConnectedClients.Find(c => c.Character == Character);
|
|
GameMain.Server.SendDirectChatMessage(greetingChatMsg, traitorClient);
|
|
GameMain.Server.SendDirectChatMessage(moreAgentsChatMsg, traitorClient);
|
|
GameMain.Server.SendDirectChatMessage(greetingMsgBox, traitorClient);
|
|
GameMain.Server.SendDirectChatMessage(moreAgentsMsgBox, traitorClient);
|
|
|
|
Client ownerClient = server.ConnectedClients.Find(c => c.Connection == server.OwnerConnection);
|
|
if (traitorClient != ownerClient && ownerClient != null && ownerClient.Character == null)
|
|
{
|
|
var ownerMsg = ChatMessage.Create(
|
|
null,//TextManager.Get("NewTraitor"),
|
|
TextManager.Get("TraitorStartMessageServer").Replace("[targetname]", TargetCharacter.Name).Replace("[traitorname]", Character.Name),
|
|
ChatMessageType.MessageBox,
|
|
null
|
|
);
|
|
GameMain.Server.SendDirectChatMessage(ownerMsg, ownerClient);
|
|
}
|
|
}
|
|
}
|
|
|
|
partial class TraitorManager
|
|
{
|
|
private static string wordsTxt = Path.Combine("Content", "CodeWords.txt");
|
|
|
|
public List<Traitor> TraitorList
|
|
{
|
|
get { return traitorList; }
|
|
}
|
|
|
|
private List<Traitor> traitorList = new List<Traitor>();
|
|
|
|
public string codeWords, codeResponse;
|
|
|
|
public TraitorManager(GameServer server, int traitorCount)
|
|
{
|
|
if (traitorCount < 1) //what why how
|
|
{
|
|
traitorCount = 1;
|
|
DebugConsole.ThrowError("Traitor Manager: TraitorCount somehow ended up less than 1, setting it to 1.");
|
|
}
|
|
Start(server, traitorCount);
|
|
}
|
|
|
|
private void Start(GameServer server, int traitorCount)
|
|
{
|
|
if (server == null) return;
|
|
|
|
List<Character> characters = new List<Character>(); //ANYONE can be a target.
|
|
List<Character> traitorCandidates = new List<Character>(); //Keep this to not re-pick traitors twice
|
|
foreach (Client client in server.ConnectedClients)
|
|
{
|
|
if (client.Character != null)
|
|
{
|
|
characters.Add(client.Character);
|
|
traitorCandidates.Add(client.Character);
|
|
}
|
|
}
|
|
|
|
if (server.Character != null)
|
|
{
|
|
characters.Add(server.Character); //Add host character
|
|
traitorCandidates.Add(server.Character);
|
|
}
|
|
|
|
if (characters.Count < 2)
|
|
{
|
|
return;
|
|
}
|
|
|
|
codeWords = ToolBox.GetRandomLine(wordsTxt) + ", " + ToolBox.GetRandomLine(wordsTxt);
|
|
codeResponse = ToolBox.GetRandomLine(wordsTxt) + ", " + ToolBox.GetRandomLine(wordsTxt);
|
|
|
|
while (traitorCount-- > 0)
|
|
{
|
|
if (traitorCandidates.Count <= 0) break;
|
|
|
|
int traitorIndex = Rand.Int(traitorCandidates.Count);
|
|
Character traitorCharacter = traitorCandidates[traitorIndex];
|
|
traitorCandidates.Remove(traitorCharacter);
|
|
|
|
//Add them to the list
|
|
traitorList.Add(new Traitor(traitorCharacter));
|
|
}
|
|
|
|
//Now that traitors have been decided, let's do objectives in post for deciding things like Document Exchange.
|
|
foreach (Traitor traitor in traitorList)
|
|
{
|
|
Character traitorCharacter = traitor.Character;
|
|
int targetIndex = Rand.Int(characters.Count);
|
|
while (characters[targetIndex] == traitorCharacter) //Cannot target self
|
|
{
|
|
targetIndex = Rand.Int(characters.Count);
|
|
}
|
|
|
|
Character targetCharacter = characters[targetIndex];
|
|
traitor.TargetCharacter = targetCharacter;
|
|
traitor.Greet(server, codeWords, codeResponse);
|
|
}
|
|
}
|
|
|
|
public string GetEndMessage()
|
|
{
|
|
if (GameMain.Server == null || traitorList.Count <= 0) return "";
|
|
|
|
string endMessage = "";
|
|
|
|
foreach (Traitor traitor in traitorList)
|
|
{
|
|
Character traitorCharacter = traitor.Character;
|
|
Character targetCharacter = traitor.TargetCharacter;
|
|
string messageTag;
|
|
|
|
if (targetCharacter.IsDead) //Partial or complete mission success
|
|
{
|
|
if (traitorCharacter.IsDead)
|
|
{
|
|
messageTag = "TraitorEndMessageSuccessTraitorDead";
|
|
}
|
|
else if (traitorCharacter.LockHands)
|
|
{
|
|
messageTag = "TraitorEndMessageSuccessTraitorDetained";
|
|
}
|
|
else
|
|
messageTag = "TraitorEndMessageSuccess";
|
|
}
|
|
else //Partial or complete failure
|
|
{
|
|
if (traitorCharacter.IsDead)
|
|
{
|
|
messageTag = "TraitorEndMessageFailureTraitorDead";
|
|
}
|
|
else if (traitorCharacter.LockHands)
|
|
{
|
|
messageTag = "TraitorEndMessageFailureTraitorDetained";
|
|
}
|
|
else
|
|
{
|
|
messageTag = "TraitorEndMessageFailure";
|
|
}
|
|
}
|
|
|
|
endMessage += (TextManager.ReplaceGenderPronouns(TextManager.Get(messageTag), traitorCharacter.Info.Gender) + "\n")
|
|
.Replace("[traitorname]", traitorCharacter.Name)
|
|
.Replace("[targetname]", targetCharacter.Name);
|
|
}
|
|
|
|
return endMessage;
|
|
}
|
|
}
|
|
}
|