Beispiel #1
0
        public void Finish()
        {
            if (GameLogger != null)
            {
                foreach (Agent agent in gameData.AgentList.OrderBy(x => x.AgentIdx))
                {
                    GameLogger.Log(string.Format("{0},status,{1},{2},{3},{4}", gameData.Day, agent.AgentIdx, gameData.GetRole(agent), gameData.GetStatus(agent), agentNameMap[agent]));
                }
                GameLogger.Log(string.Format("{0},result,{1},{2},{3}", gameData.Day, AliveHumanList.Count, AliveWolfList.Count, GetWinner()));
                GameLogger.Close();
            }

            foreach (Agent agent in gameData.AgentList)
            {
                gameServer.Finish(agent);
            }
        }
Beispiel #2
0
        public GameInfoToSend GetGameInfoToSend(Agent agent)
        {
            GameData       today = this;
            GameInfoToSend gi    = new GameInfoToSend();

            int day = today.Day;

            if (agent != null)
            {
                gi.Agent = agent.AgentIdx;
            }

            GameData yesterday = today.DayBefore;

            if (yesterday != null)
            {
                Agent executed = yesterday.Executed;
                if (executed != null)
                {
                    gi.ExecutedAgent = executed.AgentIdx;
                }

                Agent attacked = yesterday.Attacked;
                if (attacked != null)
                {
                    gi.AttackedAgent = attacked.AgentIdx;
                }

                if (gameSetting.VoteVisible)
                {
                    List <VoteToSend> voteList = new List <VoteToSend>();
                    foreach (Vote vote in yesterday.VoteList)
                    {
                        voteList.Add(new VoteToSend(vote));
                    }
                    gi.VoteList = voteList;
                }

                if (agent != null && (today.GetRole(agent) == Role.MEDIUM && executed != null))
                {
                    Species result = ((Role)yesterday.GetRole(executed)).GetSpecies();
                    gi.MediumResult = new JudgeToSend(new Judge(day, agent, executed, result));
                }

                if (agent == null || today.GetRole(agent) == Role.SEER)
                {
                    Judge divine = yesterday.Divine;
                    if (divine != null && divine.Target != null)
                    {
                        Species result = ((Role)yesterday.GetRole(divine.Target)).GetSpecies();
                        gi.DivineResult = new JudgeToSend(new Judge(day, divine.Agent, divine.Target, result));
                    }
                }

                if (agent == null || today.GetRole(agent) == Role.WEREWOLF)
                {
                    List <VoteToSend> attackVoteList = new List <VoteToSend>();
                    foreach (Vote vote in yesterday.AttackVoteList)
                    {
                        attackVoteList.Add(new VoteToSend(vote));
                    }
                    gi.AttackVoteList = attackVoteList;
                }
                if (agent == null || today.GetRole(agent) == Role.BODYGUARD)
                {
                    Guard guard = yesterday.Guard;
                    if (guard != null)
                    {
                        gi.GuardedAgent = guard.Target.AgentIdx;
                    }
                }
            }
            List <TalkToSend> talkList = new List <TalkToSend>();

            foreach (Talk talk in today.TalkList)
            {
                talkList.Add(new TalkToSend(talk));
            }
            gi.TalkList = talkList;

            Dictionary <int, string> statusMap = new Dictionary <int, string>();

            foreach (Agent a in agentStatusMap.Keys)
            {
                statusMap[a.AgentIdx] = agentStatusMap[a].ToString();
            }
            gi.StatusMap = statusMap;

            Dictionary <int, string> roleMap = new Dictionary <int, string>();
            Role?role = (Role?)agentRoleMap[agent];

            if (Role.WEREWOLF == role || agent == null)
            {
                List <TalkToSend> whisperList = new List <TalkToSend>();
                foreach (Talk talk in today.WhisperList)
                {
                    whisperList.Add(new TalkToSend(talk));
                }
                gi.WhisperList = whisperList;
            }

            if (role != null)
            {
                roleMap[agent.AgentIdx] = role.ToString();
                if (today.GetRole(agent) == Role.WEREWOLF)
                {
                    foreach (Agent target in today.AgentList)
                    {
                        if (today.GetRole(target) == Role.WEREWOLF)
                        {
                            roleMap[target.AgentIdx] = Role.WEREWOLF.ToString();
                        }
                    }
                }
                if (today.GetRole(agent) == Role.FREEMASON)
                {
                    foreach (Agent target in today.AgentList)
                    {
                        if (today.GetRole(target) == Role.FREEMASON)
                        {
                            roleMap[target.AgentIdx] = Role.FREEMASON.ToString();
                        }
                    }
                }
            }
            gi.RoleMap = roleMap;
            gi.Day     = day;

            return(gi);
        }