示例#1
0
 /*********
 ** Private methods
 *********/
 /****
 ** Patches
 ****/
 /// <summary>A method called via Harmony after <see cref="GameLocation.CanPlantSeedsHere"/> or <see cref="GameLocation.CanPlantTreesHere"/>.</summary>
 /// <param name="__instance">The farm instance.</param>
 /// <param name="__result">The return value to use for the method.</param>
 private static void After_CanPlantSeedsOrTreesHere(GameLocation __instance, ref bool __result)
 {
     if (LocationPatcher.TryGetConfig(__instance, out PerLocationConfig config) && config.GrowCrops)
     {
         __result = true;
     }
 }
示例#2
0
 /// <summary>A method called via Harmony after <see cref="GameLocation.doesTileHaveProperty"/>.</summary>
 /// <param name="__instance">The farm instance.</param>
 /// <param name="xTile">The x-coordinate of the map tile.</param>
 /// <param name="yTile">The y-coordinate of the map tile.</param>
 /// <param name="propertyName">The property name to match.</param>
 /// <param name="layerName">The map layer name to check.</param>
 /// <param name="__result">The return value to use for the method.</param>
 private static void After_DoesTileHaveProperty(GameLocation __instance, int xTile, int yTile, string propertyName, string layerName, ref bool __result)
 {
     if (!Context.IsWorldReady || !__instance.farmers.Any())
     {
         return; // don't affect game logic for spawning ores, etc
     }
     if (propertyName == "Diggable" && layerName == "Back")
     {
         try
         {
             if (LocationPatcher.ShouldMakeTillable(__instance, xTile, yTile))
             {
                 __result = true;
             }
         }
         catch (Exception ex)
         {
             if (!LocationPatcher.LoggedTileError)
             {
                 LocationPatcher.LoggedTileError = true;
                 LocationPatcher.Monitor.Log($"Failed overriding {nameof(GameLocation)}.{nameof(GameLocation.doesTileHaveProperty)} for {__instance.Name} ({xTile}, {yTile}): {ex}", LogLevel.Error);
             }
         }
     }
 }
示例#3
0
 /// <summary>A method called via Harmony after <see cref="GameLocation.SeedsIgnoreSeasonsHere"/>.</summary>
 /// <param name="__instance">The farm instance.</param>
 /// <param name="__result">The return value to use for the method.</param>
 private static void After_SeedsIgnoreSeasonsHere(GameLocation __instance, ref bool __result)
 {
     if (LocationPatcher.TryGetConfig(__instance, out PerLocationConfig config) && config.GrowCrops && config.GrowCropsOutOfSeason)
     {
         __result = true;
     }
 }
示例#4
0
        /****
        ** Methods
        ****/
        /// <summary>Get whether to override tilling for a given tile.</summary>
        /// <param name="location">The game location to check.</param>
        /// <param name="xTile">The x-coordinate of the map tile.</param>
        /// <param name="yTile">The y-coordinate of the map tile.</param>
        private static bool ShouldMakeTillable(GameLocation location, int xTile, int yTile)
        {
            ModConfigForceTillable config = LocationPatcher.Config.ForceTillable;

            // get tile
            Tile tile = location.Map.GetLayer("Back")?.Tiles[xTile, yTile];

            if (tile?.TileSheet == null || LocationPatcher.GetProperty(tile, "Diggable") != null)
            {
                return(false);
            }

            // get config for tile type
            string type = LocationPatcher.GetProperty(tile, "Type") ?? LocationPatcher.GetFallbackTileType(tile.TileSheet.ImageSource, tile.TileIndex);

            return(type switch
            {
                "Dirt" => config.Dirt,
                "Grass" => config.Grass,
                "Stone" => config.Stone,
                _ => config.Other
            });