예제 #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);
            }
        }
예제 #2
0
        private void compileChoices()
        {
            Log.info("Creating list of custom farm types...");
            var farmTypeDirs = Directory.GetDirectories(Path.Combine(Helper.DirectoryPath, "assets", "FarmTypes"));

            foreach (var folderPath in farmTypeDirs)
            {
                IContentPack contentPack = this.Helper.ContentPacks.CreateFake(folderPath);
                if (!File.Exists(Path.Combine(folderPath, "type.json")) || !File.Exists(Path.Combine(folderPath, "map.xnb")) || !File.Exists(Path.Combine(folderPath, "icon.png")))
                {
                    Log.error($"A required file is missing for custom farm type \"{folderPath}\".");
                    continue;
                }

                FarmType type = contentPack.ReadJsonFile <FarmType>("type.json");
                if (type == null)
                {
                    Log.error($"Problem reading type.json for custom farm type \"{folderPath}\".");
                    continue;
                }

                type.Folder = Path.Combine("assets", "FarmTypes", Path.GetFileName(folderPath));
                FarmType.register(type);
                Log.info($"\tFarm type: {type.Name} ({type.ID})");
            }
        }
예제 #3
0
        private void compileChoices()
        {
            Log.info("Creating list of custom farm types...");
            var choices = Directory.GetDirectories(Path.Combine(Helper.DirectoryPath, "FarmTypes"));

            foreach (var choice in choices)
            {
                if (!File.Exists(Path.Combine(choice, "type.json")) || !File.Exists(Path.Combine(choice, "map.xnb")) || !File.Exists(Path.Combine(choice, "icon.png")))
                {
                    Log.error("A required file is missing for custom farm type \"" + choice + "\".");
                    continue;
                }

                FarmType type = Helper.ReadJsonFile <FarmType>(Path.Combine(choice, "type.json"));
                if (type == null)
                {
                    Log.error("Problem reading type.json for custom farm type \"" + choice + "\".");
                    continue;
                }

                type.Folder = Path.Combine("FarmTypes", Path.GetFileName(choice));
                FarmType.register(type);
                Log.info("\tFarm type: " + type.Name + " (" + type.ID + ")");
            }
        }
예제 #4
0
 public static void register(FarmType type)
 {
     if (types.ContainsKey(type.ID))
     {
         Log.error("Type \"" + type.ID + "\" already registered.");
         return;
     }
     types.Add(type.ID, type);
 }
예제 #5
0
        public static FarmType getFarmTypeFromPreset(int vanillaId)
        {
            FarmType f = new FarmType();

            f.Name            = Farm.getMapNameFromTypeInt(vanillaId);
            f.ID              = "StardewValley." + f.Name;
            f.BehaviorPreset  = vanillaId;
            f.FarmhousePreset = vanillaId;

            return(f);
        }
예제 #6
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);
            }
        }
예제 #7
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();
            }
        }
예제 #8
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();
            }
        }
예제 #9
0
 public CustomFarm(FarmType theType, string locationName)
     : base(theType.loadMap(), locationName)
 {
     type = theType;
 }