/********* ** Private methods *********/ /// <summary>The method to call before <see cref="HoeDirt.plant"/>.</summary> private static bool Before_Plant(HoeDirt __instance, int index, int tileX, int tileY, Farmer who, bool isFertilizer, GameLocation location) { if (isFertilizer && DirtHelper.TryGetFertilizer(index, out FertilizerData fertilizer)) { // vanilla logic: basic/quality fertilizer must be applied before seed sprouts if (index is 368 or 369 && __instance.crop?.currentPhase.Value > 0) { return(false); } // custom logic: allow placing fertilizer unless already present if (__instance.HasFertilizer(fertilizer)) { return(false); } __instance.modData[fertilizer.Key] = fertilizer.Level.ToString(); if (fertilizer.Key == Mod.KeySpeed) { Mod.Instance.Helper.Reflection.GetMethod(__instance, "applySpeedIncreases").Invoke(who); } location.playSound("dirtyHit"); return(true); } return(true); }
/********* ** Private methods *********/ /// <summary>The method to call after <see cref="GameLocation.isTileOccupiedForPlacement"/>.</summary> private static void After_isTileOccupiedForPlacement(ref GameLocation __instance, ref bool __result, Vector2 tileLocation, Object toPlace = null) { if (!__result) { return; } // get fertilizer if (toPlace?.Category != SObject.fertilizerCategory || !DirtHelper.TryGetFertilizer(toPlace.ParentSheetIndex, out FertilizerData fertilizer)) { return; } // check if we can apply it if (!__instance.TryGetDirt(tileLocation, out HoeDirt dirt, includePots: false) || dirt.HasFertilizer(fertilizer)) { return; } // recheck vanilla conditions that would block fertilizer placement Rectangle tileRect = new Rectangle((int)tileLocation.X * Game1.tileSize, (int)tileLocation.Y * Game1.tileSize, Game1.tileSize, Game1.tileSize); bool isBlocked = __instance.isTileOccupiedByFarmer(tileLocation) != null || __instance.characters.Any(p => p.GetBoundingBox().Intersects(tileRect)); if (isBlocked) { return; } // mark tile unoccupied to allow placing fertilizer __result = false; }
/// <summary>The method to call before <see cref="HoeDirt.canPlantThisSeedHere"/>.</summary> private static bool Before_CanPlantThisSeedHere(HoeDirt __instance, int objectIndex, int tileX, int tileY, bool isFertilizer, ref bool __result) { if (isFertilizer && DirtHelper.TryGetFertilizer(objectIndex, out FertilizerData fertilizer)) { __result = !__instance.HasFertilizer(fertilizer); return(false); } return(true); }
private static bool CanBePlacedHereLogic(SObject __instance, GameLocation l, Vector2 tile) { if (l.TryGetDirt(tile, out HoeDirt dirt)) { if (__instance.ParentSheetIndex == 805) { return(true); } if (DirtHelper.TryGetFertilizer(__instance.ParentSheetIndex, out FertilizerData fertilizer) && dirt.HasFertilizer(fertilizer)) { return(true); } } return(false); }
private static bool TryToPlaceItemLogic(GameLocation location, Item item, int x, int y) { DirtHelper.TryGetFertilizer(item.ParentSheetIndex, out FertilizerData fertilizer); Vector2 tileLocation = new Vector2(x / 64, y / 64); if (!location.TryGetDirt(tileLocation, out HoeDirt dirt, includePots: false)) { return(true); } if (dirt.fertilizer.Value != 0) { if (dirt.HasFertilizer(fertilizer)) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:HoeDirt.cs.13916-2")); } return(true); } return(false); }