Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to save all modified player files
        /// </summary>
        /// <param name="playerOnError"></param>
        /// <returns>True if there were any modified player files.</returns>
        /// <exception cref="IOException">can happen during file save</exception>
        public bool SaveAllModifiedPlayers(ref PlayerCollection playerOnError)
        {
            int numModified = 0;

            // Save each player as necessary
            foreach (KeyValuePair <string, PlayerCollection> kvp in this.userContext.Players)
            {
                string           playerFile = kvp.Key;
                PlayerCollection player     = kvp.Value;

                if (player == null)
                {
                    continue;
                }

                if (player.IsModified)
                {
                    ++numModified;
                    playerOnError = player;                    // if needed by caller
                    TQData.BackupFile(player.PlayerName, playerFile);
                    TQData.BackupStupidPlayerBackupFolder(playerFile);
                    PlayerCollectionProvider.Save(player, playerFile);
                }
            }

            return(numModified > 0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// OK button handler
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">EventArgs data</param>
        private void OKButton_Click(object sender, EventArgs e)
        {
            if (!Config.Settings.Default.AllowCharacterEdit)
            {
                return;
            }
            if (_playerCollection.PlayerInfo == null)
            {
                return;
            }
            try
            {
                var playerInfo = new PlayerInfo();
                playerInfo.CurrentLevel       = Convert.ToInt32(levelNumericUpDown.Value);
                playerInfo.CurrentXP          = int.Parse(xpTextBox.Text);
                playerInfo.Money              = _playerCollection.PlayerInfo.Money > 0 ? _playerCollection.PlayerInfo.Money : 0;
                playerInfo.DifficultyUnlocked = difficultlyComboBox.SelectedIndex;
                playerInfo.AttributesPoints   = Convert.ToInt32(attributeNumericUpDown.Value);
                playerInfo.SkillPoints        = Convert.ToInt32(skillPointsNumericUpDown.Value);
                playerInfo.BaseStrength       = Convert.ToInt32(strengthUpDown.Value);
                playerInfo.BaseDexterity      = Convert.ToInt32(dexterityUpDown.Value);
                playerInfo.BaseIntelligence   = Convert.ToInt32(intelligenceUpDown.Value);
                playerInfo.BaseHealth         = Convert.ToInt32(healthUpDown.Value);
                playerInfo.BaseMana           = Convert.ToInt32(manacUpDown.Value);
                UpdateMoneySituation(_playerCollection.PlayerInfo, playerInfo);
                PlayerCollectionProvider.CommitPlayerInfo(_playerCollection, playerInfo);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("{0}", ex.Message));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to save all modified vault files
        /// </summary>
        private void SaveAllModifiedVaults()
        {
            foreach (KeyValuePair <string, PlayerCollection> kvp in this.vaults)
            {
                string           vaultFile = kvp.Key;
                PlayerCollection vault     = kvp.Value;

                if (vault == null)
                {
                    continue;
                }

                if (vault.IsModified)
                {
                    bool done = false;

                    // backup the file
                    while (!done)
                    {
                        try
                        {
                            TQData.BackupFile(vault.PlayerName, vaultFile);
                            PlayerCollectionProvider.Save(vault, vaultFile);
                            done = true;
                        }
                        catch (IOException exception)
                        {
                            string title = string.Format(CultureInfo.InvariantCulture, Resources.MainFormSaveError, vault.PlayerName);
                            Log.Error(title, exception);
                            switch (MessageBox.Show(Log.FormatException(exception), title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, RightToLeftOptions))
                            {
                            case DialogResult.Abort:
                            {
                                // rethrow the exception
                                throw;
                            }

                            case DialogResult.Retry:
                            {
                                // retry
                                break;
                            }

                            case DialogResult.Ignore:
                            {
                                done = true;
                                break;
                            }
                            }
                        }
                    }
                }
            }

            return;
        }
Ejemplo n.º 4
0
        private void UpdatePlayerInfo()
        {
            if (!Config.Settings.Default.AllowCharacterEdit)
            {
                return;
            }
            if (PlayerCollection.PlayerInfo == null)
            {
                return;
            }
            try
            {
                var playerInfo = new PlayerInfo();
                playerInfo.CurrentLevel = Convert.ToInt32(levelNumericUpDown.Value);

                if (playerInfo.CurrentLevel < 2)
                {
                    playerInfo.MasteriesAllowed = 0;
                }
                else if (playerInfo.CurrentLevel < 8)
                {
                    playerInfo.MasteriesAllowed = 1;
                }
                else
                {
                    playerInfo.MasteriesAllowed = 2;
                }

                playerInfo.CurrentXP               = int.Parse(xpTextBox.Text);
                playerInfo.Money                   = PlayerCollection.PlayerInfo.Money > 0 ? PlayerCollection.PlayerInfo.Money : 0;
                playerInfo.DifficultyUnlocked      = difficultlyComboBox.SelectedIndex;
                playerInfo.AttributesPoints        = Convert.ToInt32(attributeNumericUpDown.Value);
                playerInfo.SkillPoints             = Convert.ToInt32(skillPointsNumericUpDown.Value);
                playerInfo.BaseStrength            = Convert.ToInt32(strengthUpDown.Value);
                playerInfo.BaseDexterity           = Convert.ToInt32(dexterityUpDown.Value);
                playerInfo.BaseIntelligence        = Convert.ToInt32(intelligenceUpDown.Value);
                playerInfo.BaseHealth              = Convert.ToInt32(healthUpDown.Value);
                playerInfo.BaseMana                = Convert.ToInt32(manacUpDown.Value);
                playerInfo.MasteriesResetRequiered = this._MasteriesResetRequiered;
                UpdateMoneySituation(PlayerCollection.PlayerInfo, playerInfo);
                PlayerCollectionProvider.CommitPlayerInfo(PlayerCollection, playerInfo);

                this.Close();
            }
            catch (Exception ex)
            {
                this.Log.ErrorException(ex);
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads a vault file
        /// </summary>
        /// <param name="vaultName">Name of the vault</param>
        public LoadVaultResult LoadVault(string vaultName)
        {
            var result = new LoadVaultResult();

            // Get the filename
            result.Filename = TQData.GetVaultFile(vaultName);

            // Check the cache
            try
            {
                result.Vault = this.userContext.Vaults[result.Filename];
            }
            catch (KeyNotFoundException)
            {
                // We need to load the vault.
                if (!File.Exists(result.Filename))
                {
                    // the file does not exist so create a new vault.
                    result.Vault       = this.CreateVault(vaultName, result.Filename);
                    result.VaultLoaded = true;
                }
                else
                {
                    result.Vault         = new PlayerCollection(vaultName, result.Filename);
                    result.Vault.IsVault = true;
                    try
                    {
                        PlayerCollectionProvider.LoadFile(result.Vault);
                        result.VaultLoaded = true;
                    }
                    catch (ArgumentException argumentException)
                    {
                        result.ArgumentException = argumentException;
                    }
                }

                // Add the vault to the cache, but only if we create it or it successfully loads.
                if (result.VaultLoaded)
                {
                    this.userContext.Vaults.Add(result.Filename, result.Vault);
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to save all modified vault files
        /// </summary>
        /// <param name="vaultOnError"></param>
        /// <exception cref="IOException">can happen during file save</exception>
        public void SaveAllModifiedVaults(ref PlayerCollection vaultOnError)
        {
            foreach (KeyValuePair <string, PlayerCollection> kvp in this.userContext.Vaults)
            {
                string           vaultFile = kvp.Key;
                PlayerCollection vault     = kvp.Value;

                if (vault == null)
                {
                    continue;
                }

                if (vault.IsModified)
                {
                    // backup the file
                    vaultOnError = vault;
                    TQData.BackupFile(vault.PlayerName, vaultFile);
                    PlayerCollectionProvider.Save(vault, vaultFile);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads a player using the drop down list.
        /// Assumes designators are appended to character name.
        /// </summary>
        /// <param name="selectedText">Player string from the drop down list.</param>
        /// <param name="isIT"></param>
        /// <returns></returns>
        public LoadPlayerResult LoadPlayer(string selectedText, bool isIT = false)
        {
            var result = new LoadPlayerResult();

            if (string.IsNullOrWhiteSpace(selectedText))
            {
                return(result);
            }

            result.IsCustom = selectedText.EndsWith(PlayerService.CustomDesignator, StringComparison.Ordinal);
            if (result.IsCustom)
            {
                // strip off the end from the player name.
                selectedText = selectedText.Remove(selectedText.IndexOf(PlayerService.CustomDesignator, StringComparison.Ordinal), PlayerService.CustomDesignator.Length);
            }

            #region Get the player

            result.PlayerFile = TQData.GetPlayerFile(selectedText);

            try
            {
                result.Player = this.userContext.Players[result.PlayerFile];
            }
            catch (KeyNotFoundException)
            {
                result.Player = new PlayerCollection(selectedText, result.PlayerFile);
                result.Player.IsImmortalThrone = isIT;
                try
                {
                    PlayerCollectionProvider.LoadFile(result.Player);
                    this.userContext.Players.Add(result.PlayerFile, result.Player);
                }
                catch (ArgumentException argumentException)
                {
                    result.PlayerArgumentException = argumentException;
                }
            }

            #endregion

            #region Get the player's stash

            result.StashFile = TQData.GetPlayerStashFile(selectedText);

            try
            {
                result.Stash = this.userContext.Stashes[result.StashFile];
            }
            catch (KeyNotFoundException)
            {
                result.Stash = new Stash(selectedText, result.StashFile);
                try
                {
                    result.StashFound = StashProvider.LoadFile(result.Stash);
                    if (result.StashFound.Value)
                    {
                        this.userContext.Stashes.Add(result.StashFile, result.Stash);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.StashArgumentException = argumentException;
                }
            }

            #endregion

            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Attempts to save all modified player files
        /// </summary>
        /// <returns>True if there were any modified player files.</returns>
        private bool SaveAllModifiedPlayers()
        {
            int numModified = 0;

            // Save each player as necessary
            foreach (KeyValuePair <string, PlayerCollection> kvp in this.players)
            {
                string           playerFile = kvp.Key;
                PlayerCollection player     = kvp.Value;

                if (player == null)
                {
                    continue;
                }

                if (player.IsModified)
                {
                    ++numModified;
                    bool done = false;

                    // backup the file
                    while (!done)
                    {
                        try
                        {
                            TQData.BackupFile(player.PlayerName, playerFile);
                            TQData.BackupStupidPlayerBackupFolder(playerFile);
                            PlayerCollectionProvider.Save(player, playerFile);
                            done = true;
                        }
                        catch (IOException exception)
                        {
                            string title = string.Format(CultureInfo.InvariantCulture, Resources.MainFormSaveError, player.PlayerName);
                            Log.Error(title, exception);
                            switch (MessageBox.Show(Log.FormatException(exception), title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, RightToLeftOptions))
                            {
                            case DialogResult.Abort:
                            {
                                // rethrow the exception
                                throw;
                            }

                            case DialogResult.Retry:
                            {
                                // retry
                                break;
                            }

                            case DialogResult.Ignore:
                            {
                                done = true;
                                break;
                            }
                            }
                        }
                    }
                }
            }

            return(numModified > 0);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads a player using the drop down list.
        /// Assumes designators are appended to character name.
        /// Changed by VillageIdiot to a separate function.
        /// </summary>
        /// <param name="selectedText">Player string from the drop down list.</param>
        private void LoadPlayer(string selectedText)
        {
            string customDesignator = "<Custom Map>";

            bool isCustom = selectedText.EndsWith(customDesignator, StringComparison.Ordinal);

            if (isCustom)
            {
                // strip off the end from the player name.
                selectedText = selectedText.Remove(selectedText.IndexOf(customDesignator, StringComparison.Ordinal), customDesignator.Length);
            }

            string playerFile = TQData.GetPlayerFile(selectedText);

            // Get the player
            try
            {
                PlayerCollection player;
                try
                {
                    player = this.players[playerFile];
                }
                catch (KeyNotFoundException)
                {
                    bool playerLoaded = false;
                    player = new PlayerCollection(selectedText, playerFile);
                    try
                    {
                        PlayerCollectionProvider.LoadFile(player);
                        playerLoaded = true;
                    }
                    catch (ArgumentException argumentException)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, playerFile, argumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        playerLoaded = false;
                    }

                    // Only add the player to the list if it loaded successfully.
                    if (playerLoaded)
                    {
                        this.players.Add(playerFile, player);
                    }
                }

                this.playerPanel.Player    = player;
                this.stashPanel.Player     = player;
                this.stashPanel.CurrentBag = 0;
            }
            catch (IOException exception)
            {
                string msg = string.Format(CultureInfo.InvariantCulture, Resources.MainFormReadError, playerFile, exception.ToString());
                MessageBox.Show(msg, Resources.MainFormPlayerReadError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                Log.Error(msg, exception);
                this.playerPanel.Player = null;
                this.characterComboBox.SelectedIndex = 0;
            }

            string stashFile = TQData.GetPlayerStashFile(selectedText);

            // Get the player's stash
            try
            {
                Stash stash;
                try
                {
                    stash = this.stashes[stashFile];
                }
                catch (KeyNotFoundException)
                {
                    bool stashLoaded = false;
                    stash = new Stash(selectedText, stashFile);
                    try
                    {
                        bool stashPresent = StashProvider.LoadFile(stash);

                        // Throw a message if the stash is not present.
                        if (!stashPresent)
                        {
                            MessageBox.Show(Resources.StashNotFoundMsg, Resources.StashNotFound, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        }

                        stashLoaded = stashPresent;
                    }
                    catch (ArgumentException argumentException)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, stashFile, argumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        stashLoaded = false;
                    }

                    if (stashLoaded)
                    {
                        this.stashes.Add(stashFile, stash);
                    }
                }

                this.stashPanel.Stash = stash;
            }
            catch (IOException exception)
            {
                string msg = string.Concat(Resources.MainFormReadError, stashFile, exception.ToString());
                MessageBox.Show(msg, Resources.MainFormStashReadError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                Log.Error(msg, exception);
                this.stashPanel.Stash = null;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads a vault file
        /// </summary>
        /// <param name="vaultName">Name of the vault</param>
        /// <param name="secondaryVault">flag indicating whether this selection is for the secondary panel</param>
        private void LoadVault(string vaultName, bool secondaryVault)
        {
            PlayerCollection vault = null;

            if (secondaryVault && vaultName == Resources.MainFormSelectVault)
            {
                if (this.secondaryVaultPanel.Player != null)
                {
                    this.secondaryVaultPanel.Player = null;
                }
            }
            else
            {
                // Get the filename
                string filename = TQData.GetVaultFile(vaultName);

                // Check the cache
                try
                {
                    vault = this.vaults[filename];
                }
                catch (KeyNotFoundException)
                {
                    // We need to load the vault.
                    bool vaultLoaded = false;
                    if (!File.Exists(filename))
                    {
                        // the file does not exist so create a new vault.
                        vault       = CreateVault(vaultName, filename);
                        vaultLoaded = true;
                    }
                    else
                    {
                        vault         = new PlayerCollection(vaultName, filename);
                        vault.IsVault = true;
                        try
                        {
                            PlayerCollectionProvider.LoadFile(vault);
                            vaultLoaded = true;
                        }
                        catch (ArgumentException argumentException)
                        {
                            string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, filename, argumentException.Message);
                            MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                            vaultLoaded = false;
                        }
                    }

                    // Add the vault to the cache, but only if we create it or it successfully loads.
                    if (vaultLoaded)
                    {
                        this.vaults.Add(filename, vault);
                    }
                }
            }

            // Now assign the vault to the vaultpanel
            if (secondaryVault)
            {
                this.secondaryVaultPanel.Player = vault;
            }
            else
            {
                this.vaultPanel.Player = vault;
            }
        }