Exemple #1
0
        private string RandomName(LocationType type)
        {
            string randomName      = ToolBox.GetRandomLine("Content/Map/locationNames.txt");
            int    nameFormatIndex = Rand.Int(type.NameFormats.Count, false);

            return(type.NameFormats[nameFormatIndex].Replace("[name]", randomName));
        }
Exemple #2
0
            public bool Start(GameServer server, TraitorManager traitorManager, Character.TeamType team)
            {
                var assignedCandidates = AssignTraitors(server, traitorManager, team, true);

                if (assignedCandidates == null)
                {
                    return(false);
                }

                foreach (Client client in server.ConnectedClients)
                {
                    client.RoundsSincePlayedAsTraitor++;
                }

                Traitors.Clear();
                foreach (var candidate in assignedCandidates)
                {
                    var traitor = new Traitor(this, candidate.Item1, candidate.Item2.Item1.Character);
                    Traitors.Add(candidate.Item1, traitor);
                    candidate.Item2.Item1.RoundsSincePlayedAsTraitor = 0;
                }
                CodeWords    = ToolBox.GetRandomLine(wordsTxt) + ", " + ToolBox.GetRandomLine(wordsTxt);
                CodeResponse = ToolBox.GetRandomLine(wordsTxt) + ", " + ToolBox.GetRandomLine(wordsTxt);

                /**if (pendingObjectives.Count <= 0 || !pendingObjectives[0].CanBeStarted(Traitors.Values))
                 * {
                 *  Traitors.Clear();
                 *  return false;
                 * }**/

                var pendingMessages = new Dictionary <Traitor, List <string> >();

                pendingMessages.Clear();
                foreach (var traitor in Traitors.Values)
                {
                    pendingMessages.Add(traitor, new List <string>());
                }
                foreach (var traitor in Traitors.Values)
                {
                    traitor.Greet(server, CodeWords, CodeResponse, message => pendingMessages[traitor].Add(message));
                }
                pendingMessages.ForEach(traitor => traitor.Value.ForEach(message => traitor.Key.SendChatMessage(message, Identifier)));
                pendingMessages.ForEach(traitor => traitor.Value.ForEach(message => traitor.Key.SendChatMessageBox(message, Identifier)));

                Update(0.0f, () => { GameMain.Server.TraitorManager.ShouldEndRound = true; });
#if SERVER
                foreach (var traitor in Traitors.Values)
                {
                    GameServer.Log($"{GameServer.CharacterLogName(traitor.Character)} is a traitor and the current goals are:\n{(traitor.CurrentObjective?.GoalInfos != null ? TextManager.GetServerMessage(traitor.CurrentObjective?.GoalInfos) : "(empty)")}", ServerLog.MessageType.ServerMessage);
                }
#endif
                return(true);
            }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        public CharacterInfo(string file, string name = "", Gender gender = Gender.None, JobPrefab jobPrefab = null)
        {
            this.File = file;

            headSpriteRange = new Vector2[2];

            pickedItems = new List <ushort>();

            SpriteTags = new List <string>();

            //ID = -1;

            XDocument doc = ToolBox.TryLoadXml(file);

            if (doc == null)
            {
                return;
            }

            if (ToolBox.GetAttributeBool(doc.Root, "genders", false))
            {
                if (gender == Gender.None)
                {
                    float femaleRatio = ToolBox.GetAttributeFloat(doc.Root, "femaleratio", 0.5f);
                    this.gender = (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < femaleRatio) ? Gender.Female : Gender.Male;
                }
                else
                {
                    this.gender = gender;
                }
            }

            headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero);
            headSpriteRange[1] = headSpriteRange[0];
            if (headSpriteRange[0] == Vector2.Zero)
            {
                headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "maleheadid", Vector2.Zero);
                headSpriteRange[1] = ToolBox.GetAttributeVector2(doc.Root, "femaleheadid", Vector2.Zero);
            }

            int genderIndex = (this.gender == Gender.Female) ? 1 : 0;

            if (headSpriteRange[genderIndex] != Vector2.Zero)
            {
                HeadSpriteId = Rand.Range((int)headSpriteRange[genderIndex].X, (int)headSpriteRange[genderIndex].Y + 1);
            }

            this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab);

            if (!string.IsNullOrEmpty(name))
            {
                this.Name = name;
                return;
            }

            name = "";

            if (doc.Root.Element("name") != null)
            {
                string firstNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "firstname", "");
                if (firstNamePath != "")
                {
                    firstNamePath = firstNamePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : "");
                    this.Name     = ToolBox.GetRandomLine(firstNamePath);
                }

                string lastNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "lastname", "");
                if (lastNamePath != "")
                {
                    lastNamePath = lastNamePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : "");
                    if (this.Name != "")
                    {
                        this.Name += " ";
                    }
                    this.Name += ToolBox.GetRandomLine(lastNamePath);
                }
            }

            Salary = CalculateSalary();
        }