Пример #1
0
        /// <summary>
        /// Whisper by werewolf.
        /// </summary>
        public void Whisper()
        {
            List <Agent> overList = new List <Agent>();

            for (int j = 0; j < gameSetting.MaxTalk; j++)
            {
                bool         continueWhisper = false;
                List <Agent> aliveList       = AliveAgentList.Union(overList).Shuffle().ToList();
                foreach (Agent agent in aliveList)
                {
                    if (gameData.GetRole(agent) == Role.WEREWOLF)
                    {
                        if (overList.Contains(agent))
                        {
                            continue;
                        }
                        string whisperContent = gameServer.RequestWhisper(agent);
                        if (whisperContent != null && whisperContent.Length != 0)
                        {
                            Talk whisper = new Talk(gameData.NextWhisperIdx, gameData.Day, agent, whisperContent);
                            gameData.AddWhisper(agent, whisper);
                            if (!whisperContent.Equals(Common.Data.Talk.OVER))
                            {
                                continueWhisper = true;
                                overList.Clear();
                            }
                            else
                            {
                                overList.Add(agent);
                            }

                            if (GameLogger != null)
                            {
                                GameLogger.Log(string.Format("{0},whisper,{1},{2},{3}", gameData.Day, whisper.Idx, agent.AgentIdx, whisper.Content));
                            }
                        }
                    }
                }
                if (!continueWhisper)
                {
                    break;
                }
            }
        }
Пример #2
0
        void Whisper()
        {
            // No whisper in case of solo werewolf.
            if (AliveWolfList.Count == 1)
            {
                return;
            }
            foreach (var agent in AliveWolfList)
            {
                gameData.RemainWhisperMap[agent] = gameSetting.MaxWhisper;
            }

            var skipCounter = new Dictionary <Agent, int>();

            for (var turn = 0; turn < gameSetting.MaxWhisperTurn; turn++)
            {
                var continueWhisper = false;
                foreach (var agent in AliveWolfList.Shuffle())
                {
                    var text = Lib.Talk.OVER;
                    if (gameData.RemainWhisperMap[agent] > 0)
                    {
                        text = gameServer.RequestWhisper(agent);
                    }
                    if (text == null || text.Length == 0)
                    {
                        text = Lib.Talk.SKIP;
                    }
                    else
                    {
                        text = StripText(text);
                    }
                    if (text == Lib.Talk.SKIP)
                    {
                        if (skipCounter.ContainsKey(agent))
                        {
                            skipCounter[agent]++;
                        }
                        else
                        {
                            skipCounter[agent] = 1;
                        }
                        if (skipCounter[agent] > gameSetting.MaxSkip)
                        {
                            text = Lib.Talk.OVER;
                        }
                    }
                    var whisper = new Whisper(gameData.NextWhisperIdx, Day, turn, agent, text);
                    gameData.AddWhisper(whisper.Agent, whisper);
                    if (GameLogger != null)
                    {
                        GameLogger.Log($"{Day},whisper,{whisper.Idx},{whisper.Turn},{ whisper.Agent.AgentIdx},{whisper.Text}");
                    }
                    if (text != Lib.Talk.OVER && text != Lib.Talk.SKIP)
                    {
                        skipCounter[agent] = 0;
                    }
                    if (whisper.Text != Lib.Talk.OVER)
                    {
                        continueWhisper = true;
                    }
                }
                if (!continueWhisper)
                {
                    break;
                }
            }
        }