Example #1
0
        private void afterLoad(object sender, EventArgs args)
        {
            try
            {
                if (!Game1.IsMultiplayer || Game1.IsMasterGame)
                {
                    Log.info("Loading save data (\"" + SaveData.FilePath + "\")...");
                    var oldData = Helper.ReadJsonFile <SaveData>(SaveData.FilePath);

                    Data = Helper.ReadJsonFile <MultiplayerSaveData>(MultiplayerSaveData.FilePath) ?? new MultiplayerSaveData();
                    if (oldData != null && !Data.players.ContainsKey(Game1.MasterPlayer.UniqueMultiplayerID))
                    {
                        var player = new MultiplayerSaveData.PlayerData();
                        player.mana       = oldData.mana;
                        player.manaCap    = oldData.manaCap;
                        player.magicLevel = oldData.magicLevel;
                        player.magicExp   = oldData.magicExp;
                        player.freePoints = oldData.freePoints;
                        player.spellBook  = oldData.spellBook;

                        Data.players[Game1.MasterPlayer.UniqueMultiplayerID] = player;
                    }

                    if (!Data.players.ContainsKey(Game1.player.UniqueMultiplayerID))
                    {
                        Data.players[Game1.player.UniqueMultiplayerID] = new MultiplayerSaveData.PlayerData();
                    }
                }
            }
            catch (Exception e)
            {
                Log.warn("Exception loading save data: " + e);
            }
        }
Example #2
0
        /// <summary>Raised after the player loads a save slot.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void onSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            try
            {
                if (!Game1.IsMultiplayer || Game1.IsMasterGame)
                {
                    Log.info($"Loading save data (\"{SaveData.FilePath}\")...");
                    var oldData = File.Exists(SaveData.FilePath)
                        ? JsonConvert.DeserializeObject <SaveData>(File.ReadAllText(SaveData.FilePath))
                        : null;
                    Data = File.Exists(MultiplayerSaveData.FilePath)
                        ? JsonConvert.DeserializeObject <MultiplayerSaveData>(File.ReadAllText(MultiplayerSaveData.FilePath))
                        : new MultiplayerSaveData();

                    if (oldData != null && !Data.players.ContainsKey(Game1.MasterPlayer.UniqueMultiplayerID))
                    {
                        var player = new MultiplayerSaveData.PlayerData
                        {
                            mana       = oldData.mana,
                            manaCap    = oldData.manaCap,
                            magicLevel = oldData.magicLevel,
                            magicExp   = oldData.magicExp,
                            freePoints = oldData.freePoints,
                            spellBook  = oldData.spellBook
                        };

                        Data.players[Game1.MasterPlayer.UniqueMultiplayerID] = player;
                    }

                    if (!Data.players.ContainsKey(Game1.player.UniqueMultiplayerID))
                    {
                        Data.players[Game1.player.UniqueMultiplayerID] = new MultiplayerSaveData.PlayerData();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.warn($"Exception loading save data: {ex}");
            }
        }