/// <summary>
        /// Saves all pending changes to the database
        /// </summary>
        public void Save()
        {
            using (var db = GameDatabase.Open())
            {
                if (NeedsToSave)
                {
                    db.Update(new PlayerDto
                    {
                        Id                   = (int)Account.Id,
                        TutorialState        = TutorialState,
                        Level                = Level,
                        TotalExperience      = (int)TotalExperience,
                        PEN                  = (int)PEN,
                        AP                   = (int)AP,
                        Coins1               = (int)Coins1,
                        Coins2               = (int)Coins2,
                        CurrentCharacterSlot = CharacterManager.CurrentSlot
                    });
                    NeedsToSave = false;
                }

                Settings.Save(db);
                Inventory.Save(db);
                CharacterManager.Save(db);
                DenyManager.Save(db);
                Mailbox.Save(db);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves all pending changes to the database
        /// </summary>
        public void Save(bool createScope)
        {
            var scope = createScope ? new DataAccessScope() : null;

            try
            {
                if (NeedsToSave)
                {
                    var plrRef = GameDatabase.Instance.Players.GetReference((int)Account.Id);
                    plrRef.TutorialState   = TutorialState;
                    plrRef.Level           = Level;
                    plrRef.TotalExperience = (int)TotalExperience;
                    plrRef.PEN             = (int)PEN;
                    plrRef.AP     = (int)AP;
                    plrRef.Coins1 = (int)Coins1;
                    plrRef.Coins2 = (int)Coins2;
                    plrRef.CurrentCharacterSlot = CharacterManager.CurrentSlot;

                    NeedsToSave = false;
                }

                Inventory.Save();
                CharacterManager.Save();
                LicenseManager.Save();
                DenyManager.Save();
                Mailbox.Save();

                scope?.Complete();
            }
            finally
            {
                scope?.Dispose();
            }
        }