示例#1
0
        private void RenameFolderClick(object sender, RoutedEventArgs e)
        {
            if (SelectedList == null)
            {
                return;
            }
            var id   = new InputDlg("Rename Folder", "Please enter a new folder name", "");
            var name = id.GetString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }
            try
            {
                var di      = new DirectoryInfo(SelectedList.Path);
                var newPath = Path.Combine(di.Parent.FullName, name);
                Directory.Move(SelectedList.Path, newPath);
                var parent = SelectedList.Parent;
                parent.DeckLists.Remove(SelectedList);
                parent.DeckLists.Add(new DeckList(newPath, this.Dispatcher, parent));
            }
            catch (Exception ex)
            {
                Log.Warn("RenameFolderClick", ex);
                TopMostMessageBox.Show(
                    "This folder name is invalid.",
                    "Invalid",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
        }
示例#2
0
        private void NewFolderClick(object sender, RoutedEventArgs e)
        {
            if (SelectedList == null)
            {
                return;
            }
            var id   = new InputDlg("Create a New Folder", "Please enter a folder name", "");
            var name = id.GetString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }
            try
            {
                var path = Path.Combine(SelectedList.Path, name);
                Directory.CreateDirectory(path);
                SelectedList.DeckLists.Add(new DeckList(path, this.Dispatcher, SelectedList, false));
            }
            catch (Exception ex)
            {
                Log.Warn("NewFolderClick", ex);
                TopMostMessageBox.Show(
                    "This folder name is invalid.",
                    "Invalid",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
        }
示例#3
0
        public GameEngine(Game def, string nickname, bool isLocal = false)
        {
            IsLocal     = isLocal;
            _definition = def;
            _table      = new Table(def.Table);
            Variables   = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            nick = nickname;
            while (String.IsNullOrWhiteSpace(nick))
            {
                nick = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(nick))
                {
                    nick = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = nick;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", nick);
                    retNick = i.GetString();
                }));
                nick = retNick;
            }
        }
示例#4
0
        public GameEngine(Game def, string nickname, string password = "", bool isLocal = false)
        {
            IsLocal       = isLocal;
            this.Password = password;
            _definition   = def;
            _table        = new Table(def.Table);
            Variables     = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", this.Nickname);
                    retNick = i.GetString();
                }));
                this.Nickname = retNick;
            }
            // Load all game markers
            foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers())
            {
                if (!_markersById.ContainsKey(m.Id))
                {
                    _markersById.Add(m.Id, m);
                }
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            TurnPlayer      = null;

            CardFrontBitmap = ImageUtils.CreateFrozenBitmap(Definition.GetCardFrontUri());
            CardBackBitmap  = ImageUtils.CreateFrozenBitmap(Definition.GetCardBackUri());
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Play.Player(Definition, this.Nickname, 255, Crypto.ModExp(Program.PrivateKey));
            }));
        }
示例#5
0
 public string AskString(string question, string defaultValue)
 {
     return(QueueAction <string>(() =>
     {
         var dlg = new InputDlg("Question", question, defaultValue);
         var result = dlg.GetString();
         return dlg.DialogResult.GetValueOrDefault() ? result : null;
     }));
 }
示例#6
0
        private void StartJoinGame(HostedGameViewModel hostedGame, DataNew.Entities.Game game, bool spectate)
        {
            if (hostedGame.GameSource == "Online")
            {
                var client = new Octgn.Site.Api.ApiClient();
                if (!client.IsGameServerRunning(Program.LobbyClient.Username, Program.LobbyClient.Password))
                {
                    throw new UserMessageException("The game server is currently down. Please try again later.");
                }
            }
            Log.InfoFormat("Starting to join a game {0} {1}", hostedGame.GameId, hostedGame.Name);
            Program.IsHost        = false;
            Program.IsMatchmaking = false;
            var password = "";

            if (hostedGame.HasPassword)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    var dlg  = new InputDlg("Password", "Please enter this games password", "");
                    password = dlg.GetString();
                }));
            }
            var username = (Program.LobbyClient.IsConnected == false ||
                            Program.LobbyClient.Me == null ||
                            Program.LobbyClient.Me.UserName == null) ? Prefs.Nickname : Program.LobbyClient.Me.UserName;

            Program.GameEngine            = new GameEngine(game, username, spectate, password);
            Program.CurrentOnlineGameName = hostedGame.Name;
            IPAddress hostAddress = hostedGame.IPAddress;

            if (hostAddress == null)
            {
                Log.WarnFormat("Dns Error, couldn't resolve {0}", AppConfig.GameServerPath);
                throw new UserMessageException("There was a problem with your DNS. Please try again.");
            }

            try
            {
                Log.InfoFormat("Creating client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client = new ClientSocket(hostAddress, hostedGame.Port);
                Log.InfoFormat("Connecting client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client.Connect();
            }
            catch (Exception e)
            {
                Log.Warn("Start join game error ", e);
                throw new UserMessageException("Could not connect. Please try again.");
            }
        }
示例#7
0
        public Game(GameDef def, bool isLocal = false)
        {
            IsLocal     = isLocal;
            _definition = def;
            _table      = new Table(def.TableDefinition);
            Variables   = new Dictionary <string, int>();
            foreach (VariableDef varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.DefaultValue);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (GlobalVariableDef varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            if (IsLocal)
            {
                var i = new InputDlg("Choose a nickname", "Choose a nickname",
                                     "User" + new Random().Next().ToString(CultureInfo.InvariantCulture));
                var ret = i.GetString();
                if (ret == "")
                {
                    ret = "User" + new Random().Next().ToString(CultureInfo.InvariantCulture);
                }
                nick = ret;
            }
            else
            {
                if (Program.LobbyClient == null || Program.LobbyClient.Me == null)
                {
                    nick = "User" + new Random().Next().ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    nick = Program.LobbyClient.Me.User.User;
                }
            }
        }
示例#8
0
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            var hostedGame = _game;

            try {
                Program.CurrentHostedGame = hostedGame;
                var password = string.Empty;
                if (Program.IsHost = _isHost)
                {
                    password = hostedGame.Password;
                }
                else
                {
                    if (hostedGame.HasPassword)
                    {
                        var dlg = new InputDlg("Password", "Please enter this games password", "");

                        password = dlg.GetString();
                    }
                }

                if (hostedGame.Source == HostedGameSource.Online)
                {
                    Program.CurrentOnlineGameName = hostedGame.Name;
                }

                loadingView.UpdateStatus("Loading game");
                var gm = GameManager.Get();

                var game = GameManager.Get().GetById(hostedGame.GameId);

                if (game == null)
                {
                    var msg = $"Game {hostedGame.GameName}({hostedGame.Id}) could not be found.";
                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                loadingView.UpdateStatus("Building engine");
                Program.GameEngine = new GameEngine(game, _username, _spectate, password);

                loadingView.UpdateStatus($"Connecting to {hostedGame.HostAddress}");
                await Task.Delay(100);

                Program.Client = await Connect(hostedGame.Host, hostedGame.Port);

                if (Program.Client == null)
                {
                    var msg = $"Unable to connect to {hostedGame.Name} at {hostedGame.HostAddress}";

                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                Window window = null;
                await Dispatcher.CurrentDispatcher.InvokeAsync(() => {
                    window = WindowManager.PlayWindow = new PlayWindow();

                    window.Closed += PlayWindow_Closed;

                    window.Show();
                }, DispatcherPriority.Background);

                return(window);
            } catch (Exception e) {
                var msg = $"Error joining game {hostedGame.Name}: {e.Message}";

                Log.Warn(msg, e);

                throw new UserMessageException(UserMessageExceptionMode.Blocking, msg, e);
            }
        }
示例#9
0
        public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false)
        {
            History = new JodsEngineHistory(def.Id);
            if (Program.IsHost)
            {
                History.Name = Program.CurrentOnlineGameName;
            }

            ReplayWriter = new ReplayWriter();

            LoadedCards          = new ObservableDeck();
            LoadedCards.Sections = new ObservableCollection <ObservableSection>();

            DeckStats = new DeckStatsViewModel();

            Spectator = specator;
            Program.GameMess.Clear();
            if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0)))
            {
                Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl);
                def.ScriptVersion = new Version(3, 1, 0, 0);
            }
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LowestVersion;
            }
            else
            {
                var vmeta = Versioned.GetVersion(def.ScriptVersion);
                if (vmeta.DeleteDate <= DateTime.Now)
                {
                    Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}."
                                             , def.ScriptVersion, def.GameUrl);
                }
            }
            //Program.ChatLog.ClearEvents();
            IsLocal       = isLocal;
            this.Password = password;
            Definition    = def;
            _table        = new Table(def.Table);
            if (def.Phases != null)
            {
                byte PhaseId = 1;
                _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList();
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Key, varDef.Value.Value);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", Nickname);
                    retNick = i.GetString();
                });
                this.Nickname = retNick;
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            if (Definition.GameBoards.ContainsKey(""))
            {
                GameBoard = Definition.GameBoards[""];
            }
            ActivePlayer = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Value.Name, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true, IsReplay);
            }));
        }
示例#10
0
        public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false)
        {
            Spectator = specator;
            Program.GameMess.Clear();
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LatestVersion;
            }
            //Program.ChatLog.ClearEvents();
            IsLocal       = isLocal;
            this.Password = password;
            _definition   = def;
            _table        = new Table(def.Table);
            Variables     = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", this.Nickname);
                    retNick = i.GetString();
                }));
                this.Nickname = retNick;
            }
            // Load all game markers
            foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers())
            {
                if (!_markersById.ContainsKey(m.Id))
                {
                    _markersById.Add(m.Id, m);
                }
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            TurnPlayer      = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Key, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Play.Player(Definition, this.Nickname, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true);
            }));
        }