Пример #1
0
        /// <summary>
        /// Save the current empire object.
        /// </summary>
        /// <param name="characterSave">Flag to allow character saving when it is not a new player.</param>
        /// <param name="isNew">Flag to allow the creation of a new empire object.</param>
        /// <returns>True when empire object is saved.</returns>
        public bool Save(bool characterSave = false, bool isNew = false)
        {
            Logger.Info($"Empire::Save - Saving empire with Id {Id}");

            lock (_EmpireLock)
            {
                try
                {
                    if (isNew)
                    {
                        Database.Empires.Add(this);
                    }
                    else if ((characterSave) && (CurrentCharacterid > 0))
                    {
                        CurrentCharacter.Save();
                    }

                    XMLHelper.SerializeObjectToFile(this, $"{PathingHelper.playerDir}empires{Path.DirectorySeparatorChar}{Id}.xml");
                }

                catch (Exception Ex)
                {
                    Logger.Error($"Empire::Save - Error saving empire with Id {Id}. Error: {Ex}");
                }
            }

            return(File.Exists($"{PathingHelper.playerDir}empires{Path.DirectorySeparatorChar}{Id}.xml"));
        }