예제 #1
0
        public static Save_Info get_save_info(int file_id, Save_File file, bool suspend)
        {
            Save_Info result = new Save_Info();

            result.File_Id = file_id;

            result.Time = new DateTime(); //@Yeti
            var mostRecent = file.most_recent_save;

            if (mostRecent != null)
            {
                result.Time = mostRecent.time;
            }

            result.Style           = file.Style;
            result.Map_Save_Exists = false;
            result.Suspend_Exists  = suspend;

            if (file.NoData)
            {
                result.Chapter_Id = "";
                result.Difficulty = file.Difficulty;
            }
            else
            {
                Save_Data data = file.most_recent_save;
                result.Chapter_Id = data.chapter_id;
                result.Difficulty = data.difficulty;
                //result.Chapter_Id = file.data[chapter_id][indices[index]].chapter_id; //Debug
                //result.Difficulty = file.data[chapter_id][indices[index]].difficulty;
            }

            result.get_save_info(file);
            return(result);
        }
예제 #2
0
        public static Save_Data read(BinaryReader reader)
        {
            Save_Data result = new Save_Data();

            if (!Global.LOADED_VERSION.older_than(0, 4, 3, 0))
            {
                result.Time = DateTime.FromBinary(reader.ReadInt64());
            }
            result.Chapter_Id     = reader.ReadString();
            result.Progression_Id = reader.ReadString();
            result.System         = new Game_System();
            result.System.read(reader);
            if (Global.LOADED_VERSION.older_than(0, 4, 0, 4))
            {
                List <string> previous_chapters = Global.data_chapters[result.Chapter_Id].Prior_Chapters;
                result.System.previous_chapters.AddRange(previous_chapters);
            }
            result.Battalions = new Game_Battalions();
            result.Battalions.read(reader);
            if (Global.LOADED_VERSION.older_than(0, 5, 3, 1))
            {
                if (Global.data_chapters.ContainsKey(result.Chapter_Id))
                {
                    // Correct battalion id
                    result.Battalions.correct_battalion_id(
                        Global.data_chapters[result.Chapter_Id]);
                }
            }


            result.Actors = new Game_Actors();
            result.Actors.read(reader);
            result.Switches = Event_Variable_Data <bool> .read(reader);

            //result.Switches = new bool[Config.EVENT_DATA_LENGTH]; //Debug
            //result.Switches = result.Switches.read(reader);
            result.Variables = Event_Variable_Data <int> .read(reader);

            //result.Variables = new int[Config.EVENT_DATA_LENGTH];
            //result.Variables = result.Variables.read(reader);
            result.Ranking = Game_Ranking.read(reader);
            if (!Global.LOADED_VERSION.older_than(0, 4, 4, 0))
            {
                result.Past_Rankings = PastRankings.read(reader, result.System.Difficulty_Mode);
            }
            else
            {
                result.Past_Rankings = new PastRankings();
            }
            // If this save predates storing difficulty in the ranking object
            if (Global.LOADED_VERSION.older_than(0, 6, 1, 1))
            {
                Difficulty_Modes difficulty = result.System.Difficulty_Mode;
                result.Ranking = new Game_Ranking(result.Ranking, difficulty);
            }

            return(result);
        }
예제 #3
0
        internal void save_data(string chapter_id, string progression_id, PastRankings rankings)
        {
            if (!Data.ContainsKey(chapter_id))
            {
                Data[chapter_id] = new Dictionary <string, Save_Data>();
            }

            Data[chapter_id][progression_id] = new Save_Data();
            Data[chapter_id][progression_id].save_data(chapter_id, progression_id, rankings);
        }
예제 #4
0
        private static Dictionary <string, Save_Data> read_chapter(BinaryReader reader)
        {
            Dictionary <string, Save_Data> result = new Dictionary <string, Save_Data>();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string    key   = reader.ReadString();
                Save_Data value = Save_Data.read(reader);
                result.Add(key, value);
            }
            return(result);
        }
예제 #5
0
        internal PastRankings past_rankings(
            string chapter_id, Dictionary <string, string> previousChapterIds)
        {
            List <Save_Data> previous_chapters = new List <Save_Data>();
            List <string>    previous_ranking_progression_ids = new List <string>(
                Global.data_chapters[chapter_id].Prior_Chapters);

            // If using a subset of prior chapters for rankings
            if (Global.data_chapters[chapter_id].Prior_Ranking_Chapters.Count != 0)
            {
                previous_ranking_progression_ids = new List <string>(
                    previous_ranking_progression_ids.Intersect(
                        Global.data_chapters[chapter_id].Prior_Ranking_Chapters));
            }

            if (previous_ranking_progression_ids.Count > 0)
            {
                for (int i = 0; i < previous_ranking_progression_ids.Count; i++)
                {
                    string progression_id = previous_ranking_progression_ids[i];
                    if (previousChapterIds.ContainsKey(progression_id))
                    {
                        string previous_chapter_id = previousChapterIds[progression_id];
                        if (Data.ContainsKey(previous_chapter_id) &&
                            Data[previous_chapter_id].ContainsKey(progression_id))
                        {
                            previous_chapters.Add(Data[previous_chapter_id][progression_id]);
                        }
#if DEBUG
                        else
                        {
                            Debug.Assert(string.IsNullOrEmpty(previous_chapter_id));
                        }
#endif
                    }
                    else
                    {
                        Save_Data previous_data = recent_save(progression_id);
#if DEBUG
                        Debug.Assert(previous_data != null);
#endif
                        previous_chapters.Add(previous_data);
                    }
                }
            }

            return(Save_Data.process_past_ranking(previous_chapters));
        }
예제 #6
0
        public Dictionary <string, Game_Ranking> all_rankings(
            string chapterId)
        {
            if (!ContainsKey(chapterId))
            {
                return(null);
            }

            var save = recent_save(chapterId, "");

            if (save == null)
            {
                return(null);
            }

            var rankings = Save_Data.process_past_ranking(
                new List <Save_Data> {
                save
            });

            return(rankings.GetData());
        }
예제 #7
0
        public static Save_File read(BinaryReader reader)
        {
            Save_File result = new Save_File();

            result.Style = (Mode_Styles)reader.ReadInt32();
            if (!Global.LOADED_VERSION.older_than(0, 4, 3, 4))
            {
                result.Difficulty = (Difficulty_Modes)reader.ReadInt32();
            }
            if (!Global.LOADED_VERSION.older_than(0, 5, 7, 0))
            {
                result.Description = reader.ReadString();
            }

            int chapter_count = reader.ReadInt32();

            if (Global.LOADED_VERSION.older_than(0, 6, 1, 0))
            {
                var old_data = new Dictionary <string, Dictionary <Difficulty_Modes, Dictionary <string, Save_Data> > >();
                if (Global.LOADED_VERSION.older_than(0, 4, 4, 0))
                {
                    for (int i = 0; i < chapter_count; i++)
                    {
                        string    key   = reader.ReadString();
                        Save_Data value = Save_Data.read(reader);
                        old_data.Add(key, new Dictionary <Difficulty_Modes, Dictionary <string, Save_Data> > {
                            { value.difficulty, new Dictionary <string, Save_Data> {
                                  { value.progression_id, value }
                              } }
                        });
                    }
                }
                else
                {
                    for (int i = 0; i < chapter_count; i++)
                    {
                        string chapter_key = reader.ReadString();
                        Dictionary <Difficulty_Modes, Dictionary <string, Save_Data> > chapter =
                            new Dictionary <Difficulty_Modes, Dictionary <string, Save_Data> >();

                        int count = reader.ReadInt32();
                        for (int j = 0; j < count; j++)
                        {
                            Difficulty_Modes key = (Difficulty_Modes)reader.ReadInt32();
                            Dictionary <string, Save_Data> value = read_chapter(reader);
                            chapter.Add(key, value);
                        }
                        old_data.Add(chapter_key, chapter);
                    }
                }
                // Select the newer save data for each chapter?
                result.Data = new Dictionary <string, Dictionary <string, Save_Data> >();
                foreach (var pair in old_data)
                {
                    result.Data.Add(pair.Key, new Dictionary <string, Save_Data>());
                    // Get all progression ids
                    var progression_ids = pair.Value.SelectMany(y => y.Value.Select(x => x.Key))
                                          .Distinct()
                                          .ToList();
                    foreach (string progression in progression_ids)
                    {
                        var chapter_dataset = pair.Value
                                              .Where(x => x.Value.ContainsKey(progression))
                                              .Select(x => x.Value[progression])
                                              // Find the newest
                                              .OrderByDescending(x =>
                        {
                            if (x.difficulty != Difficulty_Modes.Normal)
                            {
                            }
                            // Add 5 minutes if the save is a on hard mode,
                            //     to account for hard saving before normal
                            int extra_minutes =
                                x.difficulty == Difficulty_Modes.Normal ? 0 : 5;
                            return(x.time + new TimeSpan(0, extra_minutes, 0));
                        })
                                              .ToList();
                        if (chapter_dataset.Count > 1 && !(
                                chapter_dataset[0].time.Date == chapter_dataset[1].time.Date &&
                                chapter_dataset[0].time.Hour == chapter_dataset[1].time.Hour &&
                                chapter_dataset[0].time.Minute == chapter_dataset[1].time.Minute))
                        {
                        }
                        result.Data[pair.Key].Add(progression, chapter_dataset.First());
                    }
                }
            }
            else
            {
                for (int i = 0; i < chapter_count; i++)
                {
                    string chapter_key = reader.ReadString();
                    Dictionary <string, Save_Data> value = read_chapter(reader);
                    result.Data.Add(chapter_key, value);
                }
            }
            return(result);
        }
예제 #8
0
        public void load_data(string chapter_id,
                              Dictionary <string, string> previous_chapters, string progression_id)
        {
            TactileLibrary.Data_Chapter chapter = Global.data_chapters[chapter_id];
            if (chapter.Prior_Chapters.Count > 0)
            {
#if DEBUG
                foreach (var previous_chapter in previous_chapters)
                {
                    // Keys for Data are progression ids
                    Debug.Assert(Data.ContainsKey(previous_chapter.Value),
                                 string.Format(
                                     "No save data for \"{0}\", the previous chapter of {1}",
                                     previous_chapter.Value, chapter_id));

                    if (chapter.Prior_Chapters.Contains(previous_chapter.Key))
                    {
                        // This doesn't seem formed correctly, why is Prior_Chapters[0] required? //Yeti
                        Debug.Assert(Data[previous_chapter.Value].ContainsKey(
                                         previous_chapter.Key),
                                     string.Format(
                                         "Chapter \"{0}\" doesn't have save data for progression id {1}",
                                         previous_chapter.Value,
                                         previous_chapter.Key));
                    }
                }
#endif
            }
            // An list of the battalions of the chapters being loaded from, in order with the last being the most important
            List <int> previous_chapter_battalions = new List <int>(), completed_chapter_battalions = new List <int>();
            Dictionary <int, Save_Data> battalion_chapters = new Dictionary <int, Save_Data>();

            for (int i = 0; i < chapter.Prior_Chapters.Count; i++)
            {
                string    prior_id = chapter.Prior_Chapters[i];
                Save_Data data;
                if (previous_chapters.ContainsKey(prior_id))
                {
                    data = Data[previous_chapters[prior_id]][prior_id];
                }
                else
                {
                    data = recent_save(prior_id);
                }
                //int battalion = Global.data_chapters.Values.Single(x => x.Id == data.chapter_id).Battalion; //Debug
                int battalion = Global.data_chapters[data.chapter_id].Battalion;

                // If no data for this chapter's battalion yet
                if (!battalion_chapters.ContainsKey(battalion))
                {
                    battalion_chapters[battalion] = data;
                    // Insert instead of add so the first added data will be at the end of the list, and iterated last below
                    previous_chapter_battalions.Insert(0, battalion);
                }
            }
            for (int i = 0; i < chapter.Completed_Chapters.Count; i++)
            {
                string    prior_id = chapter.Completed_Chapters[i];
                Save_Data data;
                // If there's specific previous chapter data, load that
                if (previous_chapters.ContainsKey(prior_id))
                {
                    data = Data[previous_chapters[prior_id]][prior_id];
                }
                // Otherwise default to the most recent valid save
                else
                {
                    data = recent_save(prior_id);
                }

                //int battalion = Global.data_chapters.Values.Single(x => x.Id == data.chapter_id).Battalion; //Debug
                int battalion = Global.data_chapters[data.chapter_id].Battalion;

                // If no data for this chapter's battalion yet
                if (!battalion_chapters.ContainsKey(battalion))
                {
                    battalion_chapters[battalion] = data;
                    completed_chapter_battalions.Insert(0, battalion);
                }
            }

            int chapter_battalion = chapter.Battalion;
            Save_Data.reset_old_data();
            // Load system and event data from each previous file
            foreach (int battalion in previous_chapter_battalions)
            {
                battalion_chapters[battalion].load_data();
            }
            foreach (int battalion in previous_chapter_battalions.Take(previous_chapter_battalions.Count - 1))
            {
                battalion_chapters[battalion].load_event_data(false);
            }
            // I need to load event data from completed chapters, to check what gaidens other lords took and such //Debug
            // Actually no if you want event data from a previous chapter you need to use Prior Chapters
            //foreach (int battalion in completed_chapter_battalions) //Debug
            //    battalion_chapters[battalion].load_event_data(false);
            // Load all actors from each save
            foreach (int battalion in completed_chapter_battalions)
            {
                battalion_chapters[battalion].load_actors();
            }
            foreach (int battalion in previous_chapter_battalions)
            {
                battalion_chapters[battalion].load_actors();
            }
            // Then load only battalion actors from every save, overwriting data actors might have on routes where they aren't PCs
            foreach (int battalion in completed_chapter_battalions)
            {
                battalion_chapters[battalion].load_battalion(battalion);
            }
            foreach (int battalion in previous_chapter_battalions)
            {
                battalion_chapters[battalion].load_battalion(battalion);
            }


            if (!Global.game_battalions.ContainsKey(chapter_battalion))
            {
                Global.game_battalions.add_battalion(chapter_battalion);
            }
            Global.game_battalions.current_battalion = chapter_battalion;
        }