Beispiel #1
0
        /// <summary>Raised after the game finishes creating the save file or saving.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, EventArgs e)
        {
            Log.info("Saved, putting custom farms back...");
            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.debug("Putting custom farm back for " + entry.Key + "=" + entry.Value);
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from save");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);
            }
        }
Beispiel #2
0
        private void doFirstDayStuff(CustomFarm newFarm, FarmType type)
        {
            for (int index = 0; index < type.Behavior.NewSaveOreGenRuns; ++index)
            {
                newFarm.doOreSpawns();
            }

            var house = (FarmHouse)Game1.getLocationFromName("FarmHouse");

            house.furniture.Clear();
            house.objects.Clear();
            if (type.Farmhouse.WallpaperID != -1)
            {
                Log.debug("Wallpaper: " + type.Farmhouse.WallpaperID);
                house.setWallpaper(type.Farmhouse.WallpaperID, -1, true);
            }
            if (type.Farmhouse.FlooringID != -1)
            {
                Log.debug("Flooring: " + type.Farmhouse.FlooringID);
                house.setFloor(type.Farmhouse.FlooringID, -1, true);
            }
            foreach (var fp in type.Farmhouse.Furniture)
            {
                var furn = new Furniture(fp.FurnitureID, fp.Position, fp.Rotations);
                if (fp.HeldFurnitureID != -1)
                {
                    furn.heldObject.Value = new Furniture(fp.HeldFurnitureID, fp.Position);
                }
                Log.debug("Furniture: " + fp.FurnitureID + "(" + fp.HeldFurnitureID + ") @ " + fp.Position + " " + fp.Rotations);
                house.furniture.Add(furn);
            }
            if (type.Farmhouse.TV.FurnitureID != -1)
            {
                Log.debug("TV: " + type.Farmhouse.TV.FurnitureID + " " + type.Farmhouse.TV.Position);
                house.furniture.Add(new TV(type.Farmhouse.TV.FurnitureID, type.Farmhouse.TV.Position));
            }
            if (type.Farmhouse.Giftbox.Contents.Count > 0)
            {
                List <Item> items = new List <Item>();
                foreach (var e in type.Farmhouse.Giftbox.Contents)
                {
                    Log.debug("Giftbox item: " + e.ObjectID + " x " + e.Amount);
                    items.Add(new SObject(e.ObjectID, e.Amount));
                }
                Log.debug("Giftbox position: " + type.Farmhouse.Giftbox.Position);
                var giftbox = new Chest(0, items, type.Farmhouse.Giftbox.Position, items.Count == 1);
                house.objects.Add(type.Farmhouse.Giftbox.Position, giftbox);
            }
        }
Beispiel #3
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, EventArgs e)
        {
            if (!(Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 0))
            {
                Log.debug($"Loading save data... {Game1.year} {Game1.currentSeason} {Game1.dayOfMonth}");
                Data = Helper.Data.ReadSaveData <SaveData>("custom-farm-types");
                if (Data == null)
                {
                    Data = new SaveData();
                    return;
                }
            }

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.info($"Custom farm type {entry.Value} for {entry.Key}");
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.Name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from load");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);

                Game1.setGraphicsForSeason();
            }
        }
Beispiel #4
0
        private void afterLoad(object sender, EventArgs args)
        {
            if (!(Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 0))
            {
                Log.debug("Loading save data... " + Game1.year + " " + Game1.currentSeason + " " + Game1.dayOfMonth);
                Data = Helper.ReadJsonFile <SaveData>(Path.Combine(Constants.CurrentSavePath, "custom-farm-type.json"));
                if (Data == null)
                {
                    Data = new SaveData();
                    return;
                }
            }

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() != typeof(Farm))
                {
                    continue;
                }

                Log.info("Custom farm type " + entry.Value + " for " + entry.Key);
                FarmType type = FarmType.getType(entry.Value);
                if (type == null)
                {
                    Log.error("Custom farm type is missing!");
                    return;
                }

                var newFarm = new CustomFarm(type, loc.name);
                if (Game1.year == 1 && Game1.currentSeason == "spring" && Game1.dayOfMonth == 1)
                {
                    Log.debug("First day? from load");
                    doFirstDayStuff(newFarm, type);
                }
                else
                {
                    CustomFarm.swapFarms(loc as Farm, newFarm);
                }
                Game1.locations.Remove(loc);
                Game1.locations.Add(newFarm);

                Game1.setGraphicsForSeason();
            }
        }
Beispiel #5
0
        private void beforeSave(object sender, EventArgs args)
        {
            Log.info("Before save, use vanilla farms...");

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() == typeof(CustomFarm))
                {
                    Log.debug("Putting vanilla farm over " + entry.Key + "=" + entry.Value);
                    var  farm    = loc as CustomFarm;
                    Farm newFarm = new Farm(Helper.Content.Load <xTile.Map>("Maps\\Farm", ContentSource.GameContent), loc.name);
                    CustomFarm.swapFarms(farm, newFarm);
                    Game1.locations.Remove(farm);
                    Game1.locations.Add(newFarm);
                }
            }
        }
Beispiel #6
0
        /// <summary>Raised before the game creates a new save file or saves.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaving(object sender, EventArgs e)
        {
            Log.info("Before save, use vanilla farms...");

            foreach (var entry in Data.FarmTypes)
            {
                GameLocation loc = Game1.getLocationFromName(entry.Key);
                if (loc.GetType() == typeof(CustomFarm))
                {
                    Log.debug($"Putting vanilla farm over {entry.Key}={entry.Value}");
                    var  farm    = loc as CustomFarm;
                    Farm newFarm = new Farm("Maps\\Farm", loc.Name);
                    CustomFarm.swapFarms(farm, newFarm);
                    Game1.locations.Remove(farm);
                    Game1.locations.Add(newFarm);
                }
            }

            Helper.Data.WriteSaveData("custom-farm-types", Data);
        }