Ejemplo n.º 1
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 string __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 = "T";
             }
         }
         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);
             }
         }
     }
 }
Ejemplo n.º 2
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)
        {
            // get tile config
            var config = LocationPatcher.Config.TryGetForLocation(location, out PerLocationConfig? locationConfig)
                ? locationConfig.ForceTillable
                : null;

            if (config?.IsAnyEnabled() != true)
            {
                return(false);
            }

            // 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
            });
Ejemplo n.º 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 (!__result && LocationPatcher.Config.TryGetForLocation(__instance, out PerLocationConfig? config) && config.GrowCrops && config.GrowCropsOutOfSeason && !LocationPatcher.IsGameClearingTilledDirt())
     {
         __result = true;
     }
 }