예제 #1
0
        /*********
        ** 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;
        }
예제 #3
0
 /// <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);
 }
예제 #4
0
 /// <summary>The method to call before <see cref="HoeDirt.seasonUpdate"/>.</summary>
 private static void Before_SeasonUpdate(HoeDirt __instance, bool onLoad)
 {
     if (!onLoad && !__instance.currentLocation.SeedsIgnoreSeasonsHere() && (__instance.crop == null || __instance.crop.dead.Value || !__instance.crop.seasonsToGrowIn.Contains(Game1.currentLocation.GetSeasonForLocation())))
     {
         foreach (string key in DirtHelper.GetFertilizerTypes())
         {
             __instance.modData.Remove(key);
         }
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        private static void DrawMultiFertilizer(SpriteBatch spriteBatch, Texture2D tex, Vector2 pos, Rectangle?sourceRect, Color col, float rot, Vector2 origin, float scale, SpriteEffects fx, float depth, HoeDirt __instance)
        {
            List <FertilizerData> fertilizers = new List <FertilizerData>();

            foreach (string type in DirtHelper.GetFertilizerTypes())
            {
                if (__instance.TryGetFertilizer(type, out FertilizerData fertilizer))
                {
                    fertilizers.Add(fertilizer);
                }
            }

            foreach (FertilizerData fertilizer in fertilizers)
            {
                spriteBatch.Draw(Game1.mouseCursors, pos, new Rectangle(173 + fertilizer.SpriteIndex / 3 * 16, 462 + fertilizer.SpriteIndex % 3 * 16, 16, 16), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 1.89E-08f);
            }

            // Draw custom fertilizer, if needed.
            if (__instance.fertilizer.Value > 0)
            {
                spriteBatch.Draw(tex, pos, sourceRect, col, rot, origin, scale, fx, depth);
            }
        }