예제 #1
0
        public static async Task EndGame(GameOverReason gameOverReason)
        {
            if (!_instance.isServerActive)
            {
                return;
            }
            LogInfo("EndGame");
            // Dayを終了
            await EndDay();

            // ゲーム終了理由を更新
            using (var client = new HttpClient())
            {
                string url      = _instance.url + _instance.gameId.ToString() + "/";
                var    response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    ResGame retGame = JsonConvert.DeserializeObject <ResGame>(data);
                    retGame.gameOverReason = (int)gameOverReason;
                    string json    = JsonConvert.SerializeObject(retGame);
                    var    content = new StringContent(json, Encoding.UTF8);
                    response = await client.PutAsync(url, content);
                }
                else
                {
                    _instance.isServerActive = false;
                }
            }
        }
예제 #2
0
        public static async Task NewGame(string map)
        {
            if (!_instance.isServerActive)
            {
                return;
            }
            LogInfo("NewGame");
            _instance.isGameEnd     = false;
            _instance.deadPlayers   = new List <int>();
            _instance.exiledPlayers = new List <int>();
            Game game = new Game();

            game.mapName = map;
            // プレイヤー一覧取得
            List <Player> players = new List <Player>();

            foreach (PlayerControl player in PlayerControl.AllPlayerControls)
            {
                Player p = new Player();
                p.x        = player.transform.position.x;
                p.y        = player.transform.position.y;
                p.z        = player.transform.position.z;
                p.isDead   = player.Data.IsDead;
                p.colorId  = player.Data.ColorId;
                p.playerId = player.Data.PlayerId;
                p.name     = player.name;
                List <RoleInfo> roles = RoleInfo.getRoleInfoForPlayer(player);
                foreach (RoleInfo rol in roles)
                {
                    if (p.role.Length != 0)
                    {
                        p.role += ", ";
                    }
                    p.role += rol.name;
                }
                players.Add(p);
            }
            game.players = JsonConvert.SerializeObject(players);
            string json = JsonConvert.SerializeObject(game);

            using (var client = new HttpClient())
            {
                var content  = new StringContent(json, Encoding.UTF8);
                var response = await client.PostAsync(_instance.url, content);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    ResGame retGame = JsonConvert.DeserializeObject <ResGame>(data);
                    _instance.gameId = retGame.id;
                }
                else
                {
                    _instance.isServerActive = false;
                }
            }
            await NewDay();

            return;
        }