예제 #1
0
파일: DashBoard.cs 프로젝트: Dev01FC/CnC-SC
        private void JoinGame(GameCommand cmdReceived, Player player, PlayerGame playerGame, Game game)
        {
            if (playerGame != null)
            {
                new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "User already joined game").Save(this.FAppPrivate);
            }
            else
            {
                if (game == null)
                {
                    new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Game not found").Save(this.FAppPrivate);
                }
                else
                {
                    if (game.PlayersInGame.Count >= game.MaxNumberOfPlayers)
                    {
                        new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Already too many players in the game").Save(this.FAppPrivate);
                    }
                    else
                    {
                        PlayerGame newPlayerGame = new PlayerGame(game, cmdReceived.UserId, player.NickName);

                        foreach (MapTile tile in game.Map.MapTiles)
                        {

                            MapTile playerTile = new MapTile();
                            playerTile.TerrainType = -1;// tile.TerrainType;
                            playerTile.UserId = newPlayerGame.UserId;
                            playerTile.Xpos = tile.Xpos;
                            playerTile.Ypos = tile.Ypos;

                            newPlayerGame.Map.MapTiles.Add(playerTile);

                            //set spawn, check if not occupied first
                            if (newPlayerGame.Spawn == null && tile.IsSpawningPoint)
                            {
                                if (game.PlayersInGame.Where(c => c.Spawn.Xpos == tile.Xpos && c.Spawn.Ypos == tile.Ypos).Count() == 0)
                                {
                                    //not used yet
                                    newPlayerGame.Spawn = playerTile;
                                    PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, cmdReceived.UserId, playerTile);
                                    playerTile.TerrainType = 100;
                                    playerTile.IsSpawningPoint = true;
                                    playerTile.IsAccessible = true;
                                    playerMapTile.Save(this.FAppPrivate);
                                }
                            }
                        }


                        newPlayerGame.Save(this.FAppPrivate);
                        game.PlayersInGame.Add(newPlayerGame);
                        game.Save(this.FAppPublic);
                        new CommandFeedback(cmdReceived, enCommandStatus.Accepted, "Joined the game").Save(this.FAppPrivate);
                    }
                }
            }
        }