/// <summary> /// Part of the replaced code - taken from the original code called addStock in SeedShop.cs /// </summary> /// <param name="stock"></param> /// <param name="parentSheetIndex"></param> /// <param name="buyPrice"></param> private static void addStock(Dictionary <ISalable, int[]> stock, int parentSheetIndex, int buyPrice = -1, string item_season = null) { float num1 = 2f; int num2 = buyPrice; StardewValley.Object @object = new StardewValley.Object(Vector2.Zero, parentSheetIndex, 1); if (buyPrice == -1) { num2 = @object.salePrice(); num1 = 1f; } else if (@object.isSapling()) { num1 *= Game1.MasterPlayer.difficultyModifier; } if (item_season != null && item_season != Game1.currentSeason) { if (!Game1.MasterPlayer.hasOrWillReceiveMail("PierreStocklist")) { return; } num1 *= 1.5f; } int num3 = (int)((double)num2 * (double)num1); if (item_season != null) { foreach (KeyValuePair <ISalable, int[]> keyValuePair in stock) { if (keyValuePair.Key != null && keyValuePair.Key is StardewValley.Object) { StardewValley.Object key = keyValuePair.Key as StardewValley.Object; if (Utility.IsNormalObjectAtParentSheetIndex(key, parentSheetIndex)) { if (keyValuePair.Value.Length == 0 || num3 >= keyValuePair.Value[0]) { return; } keyValuePair.Value[0] = num3; stock[(ISalable)key] = keyValuePair.Value; return; } } } } stock.Add((ISalable)@object, new int[2] { num3, int.MaxValue }); }
public static bool Prefix(SObject __instance, ref bool __result, GameLocation location, int x, int y, Farmer who) { //Not a sapling if (!__instance.isSapling() || __instance.ParentSheetIndex == 251) // 251: tea sapling { return(true); } int tileX = x / 64; int tileY = y / 64; Vector2 index1 = new Vector2(tileX, tileY); //The original code has a check for this, but execution never actually reaches here because saplings aren't allowed to be placed on dirt //Terrain feature at the position if (location.terrainFeatures.TryGetValue(index1, out TerrainFeature feature)) { //Not dirt or the dirt has a crop if (!(feature is HoeDirt dirt) || dirt.crop != null) { return(true); } } bool nearbyTree = false; for (int index2 = tileX - 2; index2 <= tileX + 2; ++index2) { for (int index3 = tileY - 2; index3 <= tileY + 2; ++index3) { Vector2 key = new Vector2(index2, index3); if (location.terrainFeatures.ContainsKey(key) && (location.terrainFeatures[key] is Tree || location.terrainFeatures[key] is FruitTree)) { nearbyTree = true; break; } } if (nearbyTree) { break; } } bool correctTileProperties = IsFarm(location) ? ((location.doesTileHaveProperty((int)index1.X, (int)index1.Y, "Diggable", "Back") != null || location.doesTileHavePropertyNoNull((int)index1.X, (int)index1.Y, "Type", "Back").Equals("Grass")) && !location.doesTileHavePropertyNoNull((int)index1.X, (int)index1.Y, "NoSpawn", "Back").Equals("Tree")) : (location.IsGreenhouse && (location.doesTileHaveProperty((int)index1.X, (int)index1.Y, "Diggable", "Back") != null || location.doesTileHavePropertyNoNull((int)index1.X, (int)index1.Y, "Type", "Back").Equals("Stone"))); bool gameValidLocation = IsFarm(location) || location.IsGreenhouse; //If the game would return true, let it run if (gameValidLocation && correctTileProperties && !nearbyTree) { return(true); } //If not at farm or greenhouse and not allowed to plant outside farm, show an error bool failedBecauseOutsideFarm = !gameValidLocation && !BetterFruitTreesMod.Instance.Config.Allow_Placing_Fruit_Trees_Outside_Farm; //If at farm or greenhouse and tile properties are wrong and no dangerous planting allowed, show an error bool failedBecauseDangerousPlant = gameValidLocation && !correctTileProperties && !BetterFruitTreesMod.Instance.Config.Allow_Dangerous_Planting; if (failedBecauseOutsideFarm || failedBecauseDangerousPlant) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.13068")); __result = false; return(false); } //Place sapling location.playSound("dirtyHit"); DelayedAction.playSoundAfterDelay("coin", 100); //If the game was going to place a tree, it removed anything at the tree index, so we do the same bool actAsGreenhouse = location.IsGreenhouse || ((__instance.ParentSheetIndex == 69 || __instance.ParentSheetIndex == 835) && location is IslandWest); // 69: banana sapling, 835: mango sapling location.terrainFeatures.Remove(index1); location.terrainFeatures.Add(index1, new FruitTree(__instance.ParentSheetIndex) { GreenHouseTree = actAsGreenhouse, GreenHouseTileTree = location.doesTileHavePropertyNoNull((int)index1.X, (int)index1.Y, "Type", "Back") .Equals("Stone") }); __result = true; return(false); }
public static bool Prefix(Object __instance, GameLocation location, int x, int y, Farmer who, ref bool __result) { Vector2 placementTile = new Vector2((float)(x / 64), (float)(y / 64)); if (!Config.EnableMod || location.terrainFeatures.ContainsKey(placementTile)) { return(true); } if (!CanPlaceTreeHere(location, placementTile)) { return(true); } if (__instance.isSapling() && __instance.ParentSheetIndex != 251) { location.playSound("dirtyHit"); DelayedAction.playSoundAfterDelay("coin", 100, null, -1); bool actAsGreenhouse = location.IsGreenhouse || ((__instance.ParentSheetIndex == 69 || __instance.ParentSheetIndex == 835) && location is IslandWest); location.terrainFeatures.Add(placementTile, new FruitTree(__instance.ParentSheetIndex) { GreenHouseTree = actAsGreenhouse, GreenHouseTileTree = location.doesTileHavePropertyNoNull((int)placementTile.X, (int)placementTile.Y, "Type", "Back").Equals("Stone") }); return(false); for (int i = 0; i < 29; i++) { location.terrainFeatures[placementTile].dayUpdate(location, placementTile); } } int whichTree; switch (__instance.ParentSheetIndex) { case 309: whichTree = 1; break; case 310: whichTree = 2; break; case 311: whichTree = 3; break; case 897: whichTree = 7; break; case 292: whichTree = 8; break; default: return(true); } location.terrainFeatures.Add(placementTile, new Tree(whichTree, 0)); location.playSound("dirtyHit"); __result = true; return(false); }