async public Task <bool> LeaveGame()
        {
            using (var busy = new Busy(this, "Leaving game"))
            {
                var  isCoordinator = Game.IsCoordinator();
                var  teamId        = Game.GetTeam()?.Id;
                Game saved         = Game;

                Game gameWithoutMe       = null;
                Func <Game, Game> action = (refreshedGame) =>
                {
                    refreshedGame = refreshedGame ?? Game;
                    gameWithoutMe = refreshedGame.Clone();
                    gameWithoutMe.AbandonGame();
                    return(gameWithoutMe);
                };

                Game savedGame = null;
                if (isCoordinator)
                {
                    savedGame = await SaveGameSafe(action, GameUpdateAction.EndGame);
                }
                else
                {
                    savedGame = await SaveGameSafe(action, GameUpdateAction.LeaveTeam,
                                                   new Dictionary <string, string> {
                        { "playerAlias", App.Instance.Player.Alias }, { "teamId", teamId }
                    });
                }

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

                //Verify player has been removed
                var success = savedGame.GetTeam(App.Instance.Player) == null;
                App.Instance.CurrentGame = null;

                return(success);
            }
        }
Exemple #2
0
 public static bool AbandonGame(this Game game)
 {
     return(game.AbandonGame(App.Instance.Player));
 }