internal static bool Prefix(StardewValley.GameLocation __instance, ref bool __result, Response answer) { if (__instance.Name != "Greenhouse") { return(true); } switch (answer.responseKey) { case "Offering_Yes": int offeringsCount = 0; if (!int.TryParse(Game1.MasterPlayer.modData[ModEntry.offeringsStoredInWaterHutKey], out offeringsCount)) { monitor.Log($"Issue parsing ModData key [{ModEntry.offeringsStoredInWaterHutKey}]'s value to int", LogLevel.Trace); } Game1.MasterPlayer.modData[ModEntry.offeringsStoredInWaterHutKey] = (offeringsCount + Game1.player.ActiveObject.Stack).ToString(); ModEntry.AcceptOffering(Game1.player, "Yay, yay! Your offerings have pleased us!", Game1.player.ActiveObject.Stack); __result = true; return(false); case "Offering_No": __result = true; return(false); } return(true); }
public static void GoToNextEventCommandInLocation(SDV.GameLocation location) { if (!IsEventOccurringInLocation(location)) { return; } ++GetEventInLocation(location).CurrentCommand; }
internal static void SpawnFireflies(StardewValley.GameLocation location, Vector2 tile, int maxSpawnPerTile) { location.critters.Add(new Firefly(tile)); for (int x = 0; x < Game1.random.Next(1, maxSpawnPerTile); x++) { location.critters.Add(new Firefly(tile + new Vector2(Game1.random.Next(-2, 3), Game1.random.Next(-2, 3)))); } }
internal static void Postfix(StardewValley.GameLocation __instance) { if (__instance.Name != "Greenhouse") { return; } if (Game1.isRaining) { Game1.changeMusicTrack("rain"); butterflySpawnChance -= 50; fireflySpawnChance -= 25; maxButterflySpawnPerTile -= 3; maxFireflySpawnPerTile -= 1; } else if (Game1.timeOfDay < 1800) { Game1.changeMusicTrack("woodsTheme"); } // Spawn the critters __instance.critters = new List <Critter>(); if (Game1.isDarkOut()) { foreach (Vector2 tile in fireflySpawnLocations) { if (Game1.random.Next(100) < fireflySpawnChance) { SpawnFireflies(__instance, tile, maxFireflySpawnPerTile); } } } else { foreach (Vector2 tile in butterflySpawnLocations) { if (Game1.random.Next(100) < butterflySpawnChance) { SpawnButterflies(__instance, tile, maxButterflySpawnPerTile); } } if (!Game1.isRaining) { // Spawn the Junimos foreach (Vector2 tile in junimoSpawnLocations) { if (Game1.random.Next(100) < junimoSpawnChance) { SpawnJunimo(__instance, tile); } } } } }
public static void SetFindHomeDoorPathController(SDV.FarmAnimal animal, SDV.GameLocation location) { if (HasHome(animal)) { return; } animal.controller = new SDV.PathFindController(animal, location, SDV.PathFindController.isAtEndPoint, 0, false, null, 200, new Point(animal.home.tileX.Value + animal.home.animalDoor.X, animal.home.tileY.Value + animal.home.animalDoor.Y)); }
internal static void SpawnJunimo(StardewValley.GameLocation location, Vector2 tile) { if (!location.isTileLocationTotallyClearAndPlaceable(tile)) { return; } Junimo j = new Junimo(tile * 64f, 6, false); if (!location.isCollidingPosition(j.GetBoundingBox(), Game1.viewport, j)) { location.characters.Add(j); } Game1.playSound("junimoMeep1"); }
/// <summary> /// Finds the user's current location /// </summary> /// <returns>LocationFlags enum of the location</returns> public LocationFlags GetLocation() { StardewValley.GameLocation location = Game1.currentLocation; if (location is Farm) { return(LocationFlags.Farm); } if (location is StardewValley.Locations.Beach) { return(LocationFlags.Beach); } if (location is StardewValley.Locations.FarmHouse) { return(LocationFlags.Farmhouse); } if (location is StardewValley.Locations.FarmCave) { return(LocationFlags.FarmCave); } if (location is StardewValley.Locations.Cellar) { return(LocationFlags.Cellar); } if (location is StardewValley.Locations.Desert) { return(LocationFlags.Desert); } if (location is StardewValley.Locations.LibraryMuseum) { return(LocationFlags.Museum); } if (location is StardewValley.Locations.CommunityCenter) { return(LocationFlags.CommunityCenter); } if (location is StardewValley.Locations.Mountain) { return(LocationFlags.Mountain); } if (location.IsGreenhouse) { return(LocationFlags.GreenHouse); } return(LocationFlags.Unknown); }
public static void ProcessPlant1x1(StardewValley.GameLocation gameLocation, int x, int y, StardewValley.Farmer who) { xTile.Dimensions.Location tileLocation = new xTile.Dimensions.Location(x, y); Vector2 vector = new Vector2((float)tileLocation.X, (float)tileLocation.Y); if (gameLocation.terrainFeatures.ContainsKey(vector) && gameLocation.terrainFeatures[vector].GetType() == typeof(StardewValley.TerrainFeatures.HoeDirt) && who.ActiveObject != null && (who.ActiveObject.Category == -74 || who.ActiveObject.Category == -19) && ((StardewValley.TerrainFeatures.HoeDirt)gameLocation.terrainFeatures[vector]).canPlantThisSeedHere(who.ActiveObject.ParentSheetIndex, tileLocation.X, tileLocation.Y, who.ActiveObject.Category == -19)) { if (((StardewValley.TerrainFeatures.HoeDirt)gameLocation.terrainFeatures[vector]).plant( who.ActiveObject.ParentSheetIndex, tileLocation.X, tileLocation.Y, who, who.ActiveObject.Category == -19) && who.IsMainPlayer) { who.reduceActiveItemByOne(); } } }
public static void ProcessPlant(StardewValley.GameLocation gameLocation, xTile.Dimensions.Location tileLocation, StardewValley.Farmer who) { //for (int x = who.getTileX() - 1; x <= who.getTileX() + 1; x++) //{ // for (int y = who.getTileY() - 1; y <= who.getTileY() + 1; y++) // { // ProcessPlant1x1(gameLocation, x, y, who); // } //} for (int x = tileLocation.X - 1; x <= tileLocation.X + 1; x++) { for (int y = tileLocation.Y - 1; y <= tileLocation.Y + 1; y++) { if (tileLocation.X == x && tileLocation.Y == y) { continue; } ProcessPlant1x1(gameLocation, x, y, who); } } }
internal static bool Prefix(StardewValley.GameLocation __instance, GameTime time) { if (__instance.Name != "Greenhouse") { return(true); } if (Game1.isMusicContextActiveButNotPlaying()) { if (Game1.isRaining) { Game1.changeMusicTrack("rain"); } else if (!Game1.isDarkOut()) { Game1.changeMusicTrack("woodsTheme"); } } return(false); }
public static bool IsCurrentLocation(SDV.Farmer farmer, SDV.GameLocation location) { return(Location.IsLocation(GetCurrentLocation(farmer), location)); }
public static void SetFindGrassPathController(SDV.FarmAnimal animal, SDV.GameLocation location) => animal.controller = new SDV.PathFindController(animal, location, SDV.FarmAnimal.grassEndPointFunction, -1, false, SDV.FarmAnimal.behaviorAfterFindingGrassPatch, 200, Point.Zero);
internal static bool Prefix(StardewValley.GameLocation __instance, ref bool __result, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who) { if (__instance.Name != "Greenhouse") { return(true); } Tile tile = __instance.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size); if (tile != null && tile.Properties.ContainsKey("CustomAction")) { if (tile.Properties["CustomAction"] == "Treehouse") { if (bool.Parse(tile.Properties["HasReceivedOfferingToday"]) is true) { Game1.drawObjectDialogue("Fruits, fruits! Come back tomorrow, forest will change!"); } else if (who.ActiveObject is null) { if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_1")) { Game1.drawObjectDialogue("An odd tree that seems to have a door fused to it.#From behind the door you can hear a tiny voice...#Gibe 100 Starfruit, we shape forest for more plants!"); } else if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_2")) { Game1.drawObjectDialogue("An odd tree that seems to have a door fused to it.#From behind the door you can hear a tiny voice...#Gibe 100 Sweet Gem Berries, we shape forest for more plants!"); } else if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_3")) { Game1.drawObjectDialogue("An odd tree that seems to have a door fused to it.#From behind the door you can hear a tiny voice...#Gibe 100 Ancient Fruit, we shape forest for more plants!"); } else { Game1.drawObjectDialogue("An odd tree that seems to have a door fused to it.#From behind the door you hear only silence."); } } else { if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_1") && who.ActiveObject.ParentSheetIndex == 268 && who.ActiveObject.Stack >= 100) { ModEntry.AcceptOffering(who, acceptedOfferingMessage, 100, tile); Game1.MasterPlayer.mailReceived.Add("SG_Treehouse_Expansion_1"); } else if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_2") && who.ActiveObject.ParentSheetIndex == 417 && who.ActiveObject.Stack >= 100) { ModEntry.AcceptOffering(who, acceptedOfferingMessage, 100, tile); Game1.MasterPlayer.mailReceived.Add("SG_Treehouse_Expansion_2"); } else if (!Game1.MasterPlayer.mailReceived.Contains("SG_Treehouse_Expansion_3") && who.ActiveObject.ParentSheetIndex == 454 && who.ActiveObject.Stack >= 100) { ModEntry.AcceptOffering(who, acceptedOfferingMessage, 100, tile); Game1.MasterPlayer.mailReceived.Add("SG_Treehouse_Expansion_3"); } else { Game1.drawObjectDialogue("Nothing interesting happens."); } } __result = true; return(false); } else if (tile.Properties["CustomAction"] == "Waterhut") { if (!Game1.MasterPlayer.modData.ContainsKey(ModEntry.offeringsStoredInWaterHutKey)) { Game1.MasterPlayer.modData[ModEntry.offeringsStoredInWaterHutKey] = "0"; } if (who.ActiveObject is null) { int offeringsCount = 0; if (!int.TryParse(Game1.MasterPlayer.modData[ModEntry.offeringsStoredInWaterHutKey], out offeringsCount)) { monitor.Log($"Issue parsing ModData key [{ModEntry.offeringsStoredInWaterHutKey}]'s value to int", LogLevel.Trace); } if (offeringsCount == 0) { Game1.drawObjectDialogue($"A chorus of tiny voices echo from inside the hut...#Gibe us fruit! Gibe us vegetables! Feed the mighty Junimos!#If we have at least one offering in storage, we'll water the plants of this forest!"); } else { Game1.drawObjectDialogue($"There are {offeringsCount} offering(s) stored inside. The Junimos will water the plants each morning for {offeringsCount} day(s)."); } } else { // If it is a vegetable or fruit, prompt to accept the offering if (who.ActiveObject.Category == -75 || who.ActiveObject.Category == -79) { Game1.drawObjectQuestionDialogue($"Offer the {who.ActiveObject.Stack} {who.ActiveObject.DisplayName}?", offeringResponses); } else { Game1.drawObjectDialogue("The Junimos aren't interested in that offering."); } } __result = true; return(false); } } return(true); }
public AllChestsValueContainer(Item item, StardewValley.GameLocation whereat, bool isChecked) { previousItem = item; location = whereat; hasBeenChecked = isChecked; }
//public static void setMissingWallpaperToDefault(StardewValley.Locations.FarmHouse house) //{ // List<Rectangle> walls = house.getWalls(); // while(house.wallPaper.Count < walls.Count) // { // house.wallPaper[house.wallPaper.Count] = getWallpaperIndex(house.map, walls[house.wallPaper.Count].X, walls[house.wallPaper.Count].Y); // } //} //public static void setMissingFloorsToDefault(StardewValley.Locations.FarmHouse house) //{ // List<Rectangle> floors = house.getFloors(); // while (house.floor.Count < floors.Count) // { // house.floor[house.floor.Count] = getFloorIndex(house.map, floors[house.floor.Count].X, floors[house.floor.Count].Y); // } //} //public static void setWallpaperDefaults(StardewValley.Locations.FarmHouse house) //{ // List<Rectangle> walls = house.getWalls(); // List<Rectangle> floors = house.getFloors(); // for (int wallIndex = 0; wallIndex < walls.Count; wallIndex++) // { // Logger.Log("Setting default wall for the wall " + walls[wallIndex].ToString() + "..."); // int wallPaperIndex = getWallpaperIndex(house.map, walls[wallIndex].X, walls[wallIndex].Y); // house.wallPaper[wallIndex] = wallPaperIndex; // //house.setWallpaper(wallPaperIndex, wallIndex, true); // } //} //public static int getWallpaperIndex(Map map, int x, int y) //{ // int wallIndex = getWallSpriteIndex(map, x, y); // if (wallIndex == -1) // { // Logger.Log("Could not find any wall tile on any layer at (" + x + ", " + y + ")"); // return 0; // } // int wallPaperX = wallIndex % 16; // int wallPaperY = wallIndex / 48; // int wallPaperIndex = (wallPaperY * 16) + wallPaperX; // Logger.Log("Found wallpaper index of " + wallPaperIndex + " for tilesheet index " + wallIndex + "."); // return wallPaperIndex; //} //public static int getFloorIndex(Map map, int x, int y) //{ // int floorIndex = getFloorpriteIndex(map, x, y); // if (floorIndex == -1 || floorIndex < 336) // { // Logger.Log("Could not find any floor tile on any layer at (" + x + ", " + y + ")"); // return 0; // } // floorIndex -= 336; // int floorX = (floorIndex / 2) % 8; // int floorY = floorIndex / 32; // int flooringIndex = (floorY * 8) + floorX; // Logger.Log("Found floor index of " + flooringIndex + " for tilesheet index " + floorIndex + "."); // return flooringIndex; //} //public static int getWallSpriteIndex(Map map, int x, int y) //{ // int index = -1; // if (isTileAWall(map, x, y, "Back")) // { // index = map.GetLayer("Back").Tiles[x, y].TileIndex; // Logger.Log("Found a wall tile on Back layer of index " + index); // } // else if (isTileAWall(map, x, y, "Buildings")) // { // index = map.GetLayer("Buildings").Tiles[x, y].TileIndex; // Logger.Log("Found a wall tile on Buildings layer of index " + index); // } // else if (isTileAWall(map, x, y, "Front")) // { // index = map.GetLayer("Front").Tiles[x, y].TileIndex; // Logger.Log("Found a wall tile on Front layer of index " + index); // } // return index; //} //public static bool isTileAWall(Map map, int x, int y, string layer) //{ // bool result = map.GetLayer(layer).Tiles[x, y] != null && (map.GetLayer(layer).Tiles[x, y].TileSheet.ImageSource.Contains("walls_and_floors")) && map.GetLayer(layer).Tiles[x, y].TileIndex <= 335; // return result; //} //public static int getFloorpriteIndex(Map map, int x, int y) //{ // int index = -1; // if (map.GetLayer("Back").Tiles[x, y] != null) // { // if (map.GetLayer("Back").Tiles[x, y].TileSheet.ImageSource.Contains("walls_and_floors")) // { // index = map.GetLayer("Back").Tiles[x, y].TileIndex; // Logger.Log("Found a floor tile on Back layer of index " + index); // } // } // return index; //} //Stolen (with explicit permission) from original author Bwdy //https://github.com/bwdymods/SDV-bwdyworks/blob/master/ModUtil.cs public static HashSet <string> GetAllCharacterNames(bool onlyDateable = false, bool onlyVillager = false, StardewValley.GameLocation onlyThisLocation = null) { HashSet <string> characters = new HashSet <string>(); //hashset ensures only unique values exist if (onlyThisLocation != null) { foreach (var c in onlyThisLocation.characters) { if (!string.IsNullOrWhiteSpace(c.Name)) { if (!onlyVillager || c.isVillager()) { if (!onlyDateable || c.datable.Value) { characters.Add(c.Name); } } } } return(characters); //only checking the one location } //start with NPCDispositions Dictionary <string, string> dictionary = StardewValley.Game1.content.Load <Dictionary <string, string> >("Data\\NPCDispositions"); foreach (string s in dictionary.Keys) { var c = StardewValley.Game1.getCharacterFromName(s, onlyVillager); if (c != null) //simple nullcheck to ensure they weren't removed { if (!onlyDateable || c.datable.Value) { if (!string.IsNullOrWhiteSpace(c.Name)) { characters.Add(c.Name); } } } } //iterate locations for mod-added NPCs that aren't in the data foreach (var loc in StardewValley.Game1.locations) { foreach (var c in loc.characters) { if (!string.IsNullOrWhiteSpace(c.Name)) { if (!onlyVillager || c.isVillager()) { if (!onlyDateable || c.datable.Value) { characters.Add(c.Name); } } } } } //return the list return(characters); }
public static bool IsEventOccurringInLocation(SDV.GameLocation location) { return(GetEventInLocation(location) != null); }
public static SDV.Event GetEventInLocation(SDV.GameLocation location) { return(location.currentEvent); }