Ejemplo n.º 1
0
        /* SaveEvents_AfterCreate
         * Triggers after a save file is updated.
         * Used to retrieve data and seed the population of fish.
         */
        private void SaveEvents_AfterCreate(object sender, EventArgs e)
        {
            RealisticFishingData instance = this.Helper.ReadJsonFile <RealisticFishingData>($"data/{Constants.SaveFolderName}.json") ?? new RealisticFishingData();

            this.NumFishCaughtToday = instance.NumFishCaughtToday;
            this.AllFishCaughtToday = instance.AllFishCaughtToday;
            this.fp         = instance.fp;
            this.population = instance.fp.population;
            this.fp.CurrentFishIDCounter = instance.CurrentFishIDCounter;

            this.Helper.WriteJsonFile($"data/{Constants.SaveFolderName}.json", instance);
        }
Ejemplo n.º 2
0
        private void SaveEvents_AfterSave(object sender, EventArgs e)
        {
            RealisticFishingData instance = this.Helper.ReadJsonFile <RealisticFishingData>($"data/{Constants.SaveFolderName}.json") ?? new RealisticFishingData();

            if (!this.inventoryWasReconstructed)
            {
                this.RecoverItemsInInventory(instance);
            }

            // Recover items in chests
            if (!this.chestsWereReconstructed)
            {
                this.RecoverItemsInChests(instance);
            }
        }
Ejemplo n.º 3
0
        /* SaveEvents_BeforeSave
         * Triggers before a save file is saved.
         * Used to serialize the data into the save file.
         */
        private void SaveEvents_BeforeSave(object sender, EventArgs e)
        {
            RealisticFishingData instance = this.Helper.ReadJsonFile <RealisticFishingData>($"data/{Constants.SaveFolderName}.json");

            instance.NumFishCaughtToday = this.NumFishCaughtToday;
            instance.AllFishCaughtToday = this.AllFishCaughtToday;
            instance.fp                   = this.fp;
            instance.population           = this.fp.population;
            instance.CurrentFishIDCounter = this.fp.CurrentFishIDCounter;

            foreach (Tuple <int, string, int, int, int> fish in this.fp.AllFish)
            {
                if (this.fp.IsAverageFishBelowValue(fish.Item2))
                {
                    // Fish is endangered.  the value in the dictionary represents that the mail message from Demetrius has not yet been sent
                    if (!instance.endangeredFish.ContainsKey(fish.Item2))
                    {
                        instance.endangeredFish.Add(fish.Item2, false);
                        Game1.addMailForTomorrow("demetrius" + fish.Item2);
                        instance.endangeredFish[fish.Item2] = true;
                    }
                }
                else
                {
                    // Fish is no longer endangered
                    if (instance.endangeredFish.ContainsKey(fish.Item2))
                    {
                        if (instance.endangeredFish[fish.Item2] == true)
                        {
                            Game1.addMailForTomorrow("demetrius2" + fish.Item2);
                        }

                        instance.endangeredFish.Remove(fish.Item2);
                    }
                }
            }

            instance.inventory.Clear();

            // Save items in inventory
            for (int index = 0; index < Game1.player.maxItems; ++index)
            {
                if (index < Game1.player.items.Count && Game1.player.items[index] != null)
                {
                    Item item = Game1.player.items[index];
                    if (item is FishItem)
                    {
                        instance.inventory.Add(new Tuple <int, List <FishModel> >(item.ParentSheetIndex, (item as FishItem).FishStack));
                        Game1.player.removeItemFromInventory(item);
                    }
                }
            }

            instance.chests.Clear();

            // Save items in chests
            foreach (GameLocation location in Game1.locations)
            {
                var chestsInLocation = new Dictionary <Vector2, List <Tuple <int, List <FishModel> > > >();

                foreach (StardewValley.Object worldObject in location.objects.Values)
                {
                    var fishInChest = new List <Tuple <int, List <FishModel> > >();

                    if (worldObject is Chest)
                    {
                        foreach (Item item in (worldObject as Chest).items)
                        {
                            if (item is FishItem)
                            {
                                fishInChest.Add(new Tuple <int, List <FishModel> >(item.ParentSheetIndex, (item as FishItem).FishStack));
                                (worldObject as Chest).items.Remove(item);
                            }
                        }

                        chestsInLocation.Add(worldObject.TileLocation, fishInChest);
                    }
                }

                instance.chests.Add(location.Name, chestsInLocation);
            }

            this.Helper.WriteJsonFile($"data/{Constants.SaveFolderName}.json", instance);

            this.inventoryWasReconstructed = false;
            this.chestsWereReconstructed   = false;
            this.questsWereReconstructed   = false;
        }