/// <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); } }
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); } }
/// <summary>Raised after the game state is updated (≈60 times per second).</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnUpdateTicked(object sender, EventArgs e) { if (Game1.activeClickableMenu is TitleMenu && TitleMenu.subMenu is CharacterCustomization) { Log.debug("Found vanilla new game window, replacing with our own."); var oldMenu = (CharacterCustomization)TitleMenu.subMenu; var shirts = Helper.Reflection.GetField <List <int> >(oldMenu, "shirtOptions").GetValue(); var hairs = Helper.Reflection.GetField <List <int> >(oldMenu, "hairStyleOptions").GetValue(); var accessories = Helper.Reflection.GetField <List <int> >(oldMenu, "accessoryOptions").GetValue(); var wizard = Helper.Reflection.GetField <bool>(oldMenu, "wizardSource").GetValue(); var newMenu = new NewCharacterCustomizeMenu(shirts, hairs, accessories, wizard); TitleMenu.subMenu = newMenu; } }
/// <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(); } }
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(); } }
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); } } }
/// <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); }
public override void DayUpdate(int dayOfMonth) { Log.debug("Custom farm " + type.ID + " DayUpdate"); base.DayUpdate(dayOfMonth); if (type.Behavior.RepopulateStumps) { for (int x = 0; x < this.map.Layers[0].LayerWidth; ++x) { for (int y = 0; y < this.map.Layers[0].LayerHeight; ++y) { if (this.map.GetLayer("Paths").Tiles[x, y] != null && this.map.GetLayer("Paths").Tiles[x, y].TileIndex == 21 && (this.isTileLocationTotallyClearAndPlaceable(x, y) && this.isTileLocationTotallyClearAndPlaceable(x + 1, y)) && (this.isTileLocationTotallyClearAndPlaceable(x + 1, y + 1) && this.isTileLocationTotallyClearAndPlaceable(x, y + 1))) { this.resourceClumps.Add(new ResourceClump(600, 2, 2, new Vector2((float)x, (float)y))); } } } } if (type.Behavior.ForageableSpawnBehavior != null && type.Behavior.ForageableSpawnBehavior.ContainsKey(Game1.currentSeason)) { double d = type.Behavior.ForageableSpawnChanceBase; while (Game1.random.NextDouble() < d) { var area = FarmType.FarmBehavior.chooseSpawnArea(type.Behavior.ForageableSpawnBehavior[Game1.currentSeason]); if (area != null) { var entry = FarmType.FarmBehavior.SpawnBehaviorEntry.chooseEntry(area.Entries); if (entry != null) { var obj = entry.getObject(); obj.CanBeSetDown = false; if (obj.ParentSheetIndex < 75 || obj.ParentSheetIndex > 77) { obj.IsSpawnedObject = true; } obj.TileLocation = new Vector2(area.Area.x + Game1.random.Next(area.Area.w), area.Area.y + Game1.random.Next(area.Area.h)); obj.getBoundingBox(obj.TileLocation); dropObject(obj, new Vector2(obj.TileLocation.X * Game1.tileSize, obj.TileLocation.Y * Game1.tileSize), Game1.viewport, true, null); if (!entry.SkipChanceDecrease) { d *= type.Behavior.ForageableSpawnChanceMultiplier; } continue; } } d *= type.Behavior.ForageableSpawnChanceMultiplier; } } if (type.Behavior.SpecialWeedCount > 0 && !Game1.IsWinter) { if (this.Objects.Any()) { for (int index = 0; index < type.Behavior.SpecialWeedCount; ++index) { SObject @object = this.objects.ElementAt(Game1.random.Next(this.objects.Count)).Value; if (@object.name.Equals("Weeds")) { @object.ParentSheetIndex = 792 + Utility.getSeasonNumber(Game1.currentSeason); } } } } doOreSpawns(); if (type.Behavior.SpawnMonsters && !Game1.player.mailReceived.Contains("henchmanGone")) { Game1.spawnMonstersAtNight = true; } }