Exemple #1
0
        public static bool DoFunction(MilkPail __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            string inseminationSyringeId = __instance.modData[InseminationSyringeKey];

            BaseToolDoFunction(__instance, location, x, y, power, who);
            __instance.CurrentParentTileIndex    = InitialParentTileIndex;
            __instance.indexOfMenuItemView.Value = IndexOfMenuItemView;

            Animals.TryGetValue(inseminationSyringeId, out FarmAnimal animal);
            if (animal != null)
            {
                who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f);
                int daysUtillBirth = ((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.Value;
                if (!DataLoader.ModConfig.DisableContestBonus && AnimalContestController.HasFertilityBonus(animal))
                {
                    daysUtillBirth -= (int)Math.Round(daysUtillBirth / 10.0, MidpointRounding.AwayFromZero);
                }
                PregnancyController.AddPregnancy(animal, daysUtillBirth);
                animal.allowReproduction.Value = false;
                --__instance.attachments[0].Stack;
                if (__instance.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName }));
                    __instance.attachments[0] = null;
                }
                Animals[inseminationSyringeId] = (FarmAnimal)null;
            }

            if (Game1.activeClickableMenu == null)
            {
                who.CanMove = true;
                who.completelyStopAnimatingOrDoingAction();
            }
            else
            {
                who.Halt();
            }
            who.UsingTool      = false;
            who.canReleaseTool = true;

            DataLoader.Helper.Reflection.GetMethod(__instance, "finish").Invoke();
            return(false);
        }
        public static bool DoFunction(MilkPail __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            if (!IsParticipantRibbon(__instance))
            {
                return(true);
            }

            string participantRibbonId = __instance.modData[ParticipantRibbonKey];

            BaseToolDoFunction(__instance, location, x, y, power, who);
            __instance.CurrentParentTileIndex    = InitialParentTileIndex;
            __instance.indexOfMenuItemView.Value = IndexOfMenuItemView;

            Animals.TryGetValue(participantRibbonId, out FarmAnimal animal);
            if (animal != null)
            {
                AnimalContestController.MakeAnimalParticipant(animal);
                Game1.player.removeItemFromInventory(__instance);
            }
            else
            {
                Pets.TryGetValue(participantRibbonId, out Pet pet);
                if (pet != null)
                {
                    AnimalContestController.MakeAnimalParticipant(pet);
                    Game1.player.removeItemFromInventory(__instance);
                }
            }

            Animals[participantRibbonId] = null;
            Pets[participantRibbonId]    = null;

            if (Game1.activeClickableMenu == null)
            {
                who.CanMove = true;
            }
            else
            {
                who.Halt();
            }
            who.UsingTool      = false;
            who.canReleaseTool = true;

            DataLoader.Helper.Reflection.GetMethod(__instance, "finish").Invoke();

            return(false);
        }
Exemple #3
0
        public static Item GetInseminationSyringe()
        {
            Tool inseminationSyringe = new MilkPail()
            {
                Name = "Insemination Syringe",
                InitialParentTileIndex = InseminationSyringeOverrides.InitialParentTileIndex,
                IndexOfMenuItemView    = InseminationSyringeOverrides.IndexOfMenuItemView,
                CurrentParentTileIndex = InseminationSyringeOverrides.InitialParentTileIndex
            };

            AnimalHusbandryModEntry.ModHelper.Reflection.GetField <NetInt>(inseminationSyringe, "numAttachmentSlots").GetValue().Value = 1;
            inseminationSyringe.attachments.SetCount(1);
            string inseminationSyringeId = Game1.random.Next().ToString();

            inseminationSyringe.modData.Add(InseminationSyringeOverrides.InseminationSyringeKey, inseminationSyringeId);
            return(inseminationSyringe);
        }
Exemple #4
0
        public static Item GetFeedingBasket()
        {
            Tool feedingBasket = new MilkPail()
            {
                Name = "Feeding Basket",
                InitialParentTileIndex = FeedingBasketOverrides.InitialParentTileIndex,
                IndexOfMenuItemView    = FeedingBasketOverrides.IndexOfMenuItemView,
                CurrentParentTileIndex = FeedingBasketOverrides.InitialParentTileIndex
            };

            AnimalHusbandryModEntry.ModHelper.Reflection.GetField <NetInt>(feedingBasket, "numAttachmentSlots").GetValue().Value = 1;
            feedingBasket.attachments.SetCount(1);
            string feedingBasketId = Game1.random.Next().ToString();

            feedingBasket.modData.Add(FeedingBasketOverrides.FeedingBasketKey, feedingBasketId);
            return(feedingBasket);
        }
        public static bool drawAttachments(MilkPail __instance, SpriteBatch b, int x, int y)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            if (__instance.attachments[0] != null)
            {
                b.Draw(Game1.menuTexture, new Vector2(x, y), Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 10), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.86f);
                __instance.attachments[0].drawInMenu(b, new Vector2(x, y), 1f);
            }
            else
            {
                b.Draw(Game1.menuTexture, new Vector2(x, y), Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, AttachmentMenuTile), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.86f);
            }
            return(false);
        }
        public static bool drawAttachments(MilkPail __instance, SpriteBatch b, int x, int y)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            if (__instance.attachments[0] != null)
            {
                b.Draw(Game1.menuTexture, new Vector2((float)x, (float)y), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 10, -1, -1)), Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.86f);
                __instance.attachments[0].drawInMenu(b, new Vector2((float)x, (float)y), 1f);
            }
            else
            {
                b.Draw(Game1.menuTexture, new Vector2((float)x, (float)y), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, AttachmentMenuTile, -1, -1)), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.86f);
            }
            return(false);
        }
        public static bool canThisBeAttached(MilkPail __instance, SObject o, ref bool __result)
        {
            if (!IsFeedingBasket(__instance))
            {
                return(true);
            }

            if (o == null ||
                o.Category == SObject.VegetableCategory ||
                o.Category == SObject.FruitsCategory ||
                TreatsController.IsLikedTreat(o.ParentSheetIndex) ||
                TreatsController.IsLikedTreat(o.Category)
                )
            {
                __result = true;
                return(false);
            }
            __result = false;
            return(false);
        }
        public static bool attach(MilkPail __instance, StardewValley.Object o, ref StardewValley.Object __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            if (o != null)
            {
                StardewValley.Object @object = __instance.attachments[0];
                if (@object != null && @object.canStackWith((Item)o))
                {
                    @object.Stack = o.addToStack(@object);
                    if (@object.Stack <= 0)
                    {
                        @object = (StardewValley.Object)null;
                    }
                }
                __instance.attachments[0] = o;
                Game1.playSound("button1");
                __result = @object;
                return(false);
            }
            else
            {
                if (__instance.attachments[0] != null)
                {
                    StardewValley.Object attachment = __instance.attachments[0];
                    __instance.attachments[0] = (StardewValley.Object)null;
                    Game1.playSound("dwop");
                    __result = attachment;
                    return(false);
                }
            }
            __result = (StardewValley.Object)null;
            return(false);
        }
        public static bool attach(MilkPail __instance, SObject o, ref SObject __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            if (o != null)
            {
                var tmp = __instance.attachments[0];
                if (tmp != null && tmp.canStackWith(o))
                {
                    tmp.Stack = o.addToStack(tmp);
                    if (tmp.Stack <= 0)
                    {
                        tmp = null;
                    }
                }
                __instance.attachments[0] = o;
                Game1.playSound("button1");
                __result = tmp;
                return(false);
            }
            else
            {
                if (__instance.attachments[0] != null)
                {
                    var attachment = __instance.attachments[0];
                    __instance.attachments[0] = null;
                    Game1.playSound("dwop");
                    __result = attachment;
                    return(false);
                }
            }
            __result = null;
            return(false);
        }
Exemple #10
0
        public static bool Prefix(MilkPail __instance, GameLocation location, int x, int y, int power, Farmer who, FarmAnimal ___animal, ref Farmer ___lastUser)
        {
            if (___animal is LunarAnimal lanimal && location is LunarLocation)
            {
                baseDoFunction(__instance, location, x, y, power, who, ref ___lastUser);
                who.Stamina -= 4f;
                __instance.CurrentParentTileIndex = 6;
                __instance.IndexOfMenuItemView    = 6;
                if (___animal != null && ( int )___animal.currentProduce > 0 && ( int )___animal.age >= ( byte )___animal.ageWhenMature && ___animal.toolUsedForHarvest.Equals(__instance.BaseName) && who.addItemToInventoryBool(new CustomObject(DynamicGameAssets.Mod.Find(ItemIds.GalaxyMilk) as ObjectPackData)
                {
                    Quality = ___animal.produceQuality
                }))
                {
                    Utility.RecordAnimalProduce(___animal, ___animal.currentProduce);
                    Game1.playSound("coin");
                    ___animal.currentProduce.Value = -1;
                    who.gainExperience(0, 5);
                }
                Mod.instance.Helper.Reflection.GetMethod(__instance, "finish").Invoke();
                return(false);
            }

            return(true);
        }
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsParticipantRibbon(__instance))
            {
                return(true);
            }

            string participantRibbonId = __instance.modData[ParticipantRibbonKey];

            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            if (!DataLoader.ModConfig.DisableAnimalContest)
            {
                if (location is Farm farm)
                {
                    foreach (FarmAnimal farmAnimal in farm.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[participantRibbonId] = farmAnimal;
                            break;
                        }
                    }
                    if (!Animals.ContainsKey(participantRibbonId) || Animals[participantRibbonId] == null)
                    {
                        foreach (Pet localPet in farm.characters.Where(i => i is Pet))
                        {
                            if (localPet.GetBoundingBox().Intersects(rectangle))
                            {
                                Pets[participantRibbonId] = localPet;
                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse animalHouse)
                {
                    foreach (FarmAnimal farmAnimal in animalHouse.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[participantRibbonId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is FarmHouse)
                {
                    foreach (Pet localPet in location.characters.Where(i => i is Pet))
                    {
                        if (localPet.GetBoundingBox().Intersects(rectangle))
                        {
                            Pets[participantRibbonId] = localPet;
                            break;
                        }
                    }
                }
            }

            string dialogue = "";

            Animals.TryGetValue(participantRibbonId, out FarmAnimal animal);
            if (animal != null)
            {
                if (animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.CantBeBaby");
                }
                else if (AnimalContestController.HasParticipated(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.HasAlreadyParticipatedContest", new { animalName = animal.displayName });
                }
                else if (AnimalContestController.IsNextParticipant(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant", new { animalName = animal.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipant() is Character participant)
                {
                    string participantName = participant.displayName;
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                else
                {
                    animal.doEmote(8, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        animal.makeSound();
                    }
                    animal.pauseTimer = 200;
                }
            }
            Pets.TryGetValue(participantRibbonId, out Pet pet);
            if (pet != null)
            {
                if (AnimalContestController.IsNextParticipant(pet))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant",
                                                   new { animalName = pet.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipant() is Character character)
                {
                    string participantName = character.displayName;
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                else
                {
                    pet.doEmote(8, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        pet.playContentSound();
                    }
                    pet.Halt();
                    pet.CurrentBehavior = 0;
                    pet.Halt();
                    pet.Sprite.setCurrentAnimation(
                        new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 200)
                    });
                }
            }
            if (dialogue.Length > 0)
            {
                if (who != null && Game1.player.Equals(who))
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                }

                Pets[participantRibbonId]    = pet = null;
                Animals[participantRibbonId] = animal = null;
            }

            who.Halt();
            int currentFrame = who.FarmerSprite.CurrentFrame;

            if (animal != null || pet != null)
            {
                switch (who.FacingDirection)
                {
                case 0:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(62, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 1:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 2:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(54, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 3:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 200, false, true, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;
                }
            }
            else
            {
                who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                    new FarmerSprite.AnimationFrame(currentFrame, 0, false, who.FacingDirection == 3, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                });
            }
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;

            __result = true;
            return(false);
        }
 private static bool IsInseminationSyringe(MilkPail tool)
 {
     return(tool.modData.ContainsKey(InseminationSyringeKey));
 }
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsFeedingBasket(__instance))
            {
                return(true);
            }

            string feedingBasketId = __instance.modData[FeedingBasketKey];

            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            // Added this because for some wierd reason the current value appears subtracted by 5 the first time the tool is used.
            __instance.CurrentParentTileIndex = InitialParentTileIndex;

            if (!DataLoader.ModConfig.DisableTreats)
            {
                if (location is Farm farm)
                {
                    foreach (FarmAnimal farmAnimal in farm.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[feedingBasketId] = farmAnimal;
                            break;
                        }
                    }
                    if (!Animals.ContainsKey(feedingBasketId) || Animals[feedingBasketId] == null)
                    {
                        foreach (Pet localPet in farm.characters.Where(i => i is Pet))
                        {
                            if (localPet.GetBoundingBox().Intersects(rectangle))
                            {
                                Pets[feedingBasketId] = localPet;
                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse animalHouse)
                {
                    foreach (FarmAnimal farmAnimal in animalHouse.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[feedingBasketId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is FarmHouse)
                {
                    foreach (Pet localPet in location.characters.Where(i => i is Pet))
                    {
                        if (localPet.GetBoundingBox().Intersects(rectangle))
                        {
                            Pets[feedingBasketId] = localPet;
                            break;
                        }
                    }
                }
            }

            Animals.TryGetValue(feedingBasketId, out FarmAnimal animal);
            if (animal != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    }
                    Animals[feedingBasketId] = animal = null;
                }
                else if (!TreatsController.CanReceiveTreat(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsLikedTreat(animal, __instance.attachments[0]))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (__instance.attachments[0].Category == SObject.MilkCategory && !animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.OnlyBabiesCanEatMilk");
                }
                else if (!TreatsController.IsReadyForTreat(animal))
                {
                    if (TreatsController.GetTreatItem(animal)?.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = animal.displayName });
                    }
                    else
                    {
                        int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(animal);
                        if (daysUntilNextTreat > 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = animal.displayName, numberOfDays = daysUntilNextTreat });
                        }
                        else if (daysUntilNextTreat == 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = animal.displayName });
                        }
                    }
                }
                else
                {
                    animal.pauseTimer = 1000;
                }


                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Animals[feedingBasketId] = animal = null;
                }
            }
            Pets.TryGetValue(feedingBasketId, out Pet pet);
            if (pet != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    }
                    Pets[feedingBasketId] = pet = null;
                }
                else if (!TreatsController.IsLikedTreat(pet, __instance.attachments[0]))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsReadyForTreat(pet))
                {
                    int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(pet);

                    if (DataLoader.AnimalData.Pet.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = pet.displayName });
                    }
                    else if (daysUntilNextTreat > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = pet.displayName, numberOfDays = daysUntilNextTreat });
                    }
                    else if (daysUntilNextTreat == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = pet.displayName });
                    }
                }
                else
                {
                    pet.Halt();
                    pet.FacingDirection = 2;
                    pet.CurrentBehavior = 2;
                    DataLoader.Helper.Reflection.GetField <int>(pet, "_currentBehavior").SetValue(2);
                    pet.Halt();
                    pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 200)
                    });
                    pet.Sprite.loop = true;
                }

                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Pets[feedingBasketId] = pet = null;
                }
            }

            who.Halt();
            int currentFrame = who.FarmerSprite.currentFrame;

            if (animal != null || pet != null)
            {
                switch (who.FacingDirection)
                {
                case 0:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(62, 900, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 1:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 900, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 2:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(54, 900, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 3:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 900, false, true, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;
                }
            }
            else
            {
                who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                    new FarmerSprite.AnimationFrame(currentFrame, 0, false, who.FacingDirection == 3, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                });
            }
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;

            if (animal != null || pet != null)
            {
                Rectangle boundingBox;
                boundingBox = animal != null?animal.GetBoundingBox() : pet.GetBoundingBox();

                double numX = boundingBox.Center.X;
                double numY = boundingBox.Center.Y;

                Vector2 vectorBasket = new Vector2((float)numX - 32, (float)numY);
                Vector2 vectorFood   = new Vector2((float)numX - 24, (float)numY - 10);
                var     foodScale    = Game1.pixelZoom * 0.75f;

                TemporaryAnimatedSprite basketSprite = new TemporaryAnimatedSprite(Game1.toolSpriteSheetName,
                                                                                   Game1.getSourceRectForStandardTileSheet(Game1.toolSpriteSheet, __instance.CurrentParentTileIndex, 16, 16),
                                                                                   750.0f, 1, 1, vectorBasket, false, false, ((float)boundingBox.Bottom + 0.1f) / 10000f, 0.0f,
                                                                                   Color.White, Game1.pixelZoom, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                location.temporarySprites.Add(basketSprite);
                TemporaryAnimatedSprite foodSprite = new TemporaryAnimatedSprite(Game1.objectSpriteSheetName,
                                                                                 Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.attachments[0].ParentSheetIndex,
                                                                                                                         16, 16), 500.0f, 1, 1, vectorFood, false, false, ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f,
                                                                                 Color.White, foodScale, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                location.temporarySprites.Add(foodSprite);

                for (int index = 0; index < 8; ++index)
                {
                    Rectangle standardTileSheet = Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,
                                                                                          __instance.attachments[0].ParentSheetIndex, 16, 16);
                    standardTileSheet.X += 8;
                    standardTileSheet.Y += 8;

                    standardTileSheet.Width  = Game1.pixelZoom;
                    standardTileSheet.Height = Game1.pixelZoom;
                    TemporaryAnimatedSprite temporaryAnimatedSprite2 =
                        new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, standardTileSheet, 400f, 1, 0,
                                                    vectorFood + new Vector2(12, 12), false, false,
                                                    ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f, Color.White, (float)foodScale, 0.0f,
                                                    0.0f, 0.0f, false)
                    {
                        motion       = new Vector2((float)Game1.random.Next(-30, 31) / 10f, (float)Game1.random.Next(-6, -3)),
                        acceleration = new Vector2(0.0f, 0.5f),
                        delayBeforeAnimationStart = 600
                    };
                    location.temporarySprites.Add(temporaryAnimatedSprite2);
                }

                if (animal != null)
                {
                    FarmAnimal tempAnimal = animal;
                    Game1.delayedActions.Add(new DelayedAction(300, new DelayedAction.delayedBehavior(() => {
                        if (tempAnimal.buildingTypeILiveIn.Contains("Barn"))
                        {
                            tempAnimal.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new FarmerSprite.AnimationFrame(16, 100),
                                new FarmerSprite.AnimationFrame(17, 100),
                                new FarmerSprite.AnimationFrame(18, 100),
                                new FarmerSprite.AnimationFrame(19, 100),
                                new FarmerSprite.AnimationFrame(19, 100, secondaryArm: false, flip: false, (f) =>
                                {
                                    tempAnimal.doEmote(20, true);
                                    tempAnimal.Sprite.CurrentAnimation = null;
                                    tempAnimal.Sprite.loop             = true;
                                    tempAnimal.Sprite.currentFrame     = 0;
                                    tempAnimal.faceDirection(2);
                                })
                            });
                        }
                        else
                        {
                            tempAnimal.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new FarmerSprite.AnimationFrame(24, 100),
                                new FarmerSprite.AnimationFrame(25, 100),
                                new FarmerSprite.AnimationFrame(26, 100),
                                new FarmerSprite.AnimationFrame(27, 100),
                                new FarmerSprite.AnimationFrame(27, 100, secondaryArm: false, flip: false, (f) =>
                                {
                                    tempAnimal.doEmote(20, true);
                                    tempAnimal.Sprite.CurrentAnimation = null;
                                    tempAnimal.Sprite.loop             = true;
                                    tempAnimal.Sprite.currentFrame     = 0;
                                    tempAnimal.faceDirection(2);
                                })
                            });
                        }
                        tempAnimal.Sprite.loop = false;
                    })));
                }
                else if (pet != null)
                {
                    pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 300),
                        new FarmerSprite.AnimationFrame(17, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(0, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(17, 100, secondaryArm: false, flip: false, (f) => pet.doEmote(20, true), true),
                        new FarmerSprite.AnimationFrame(18, 300, false, false, pet.hold, true)
                    });
                    pet.Sprite.loop = false;
                }
                if (who != null && Game1.player.Equals(who))
                {
                    DelayedAction.playSoundAfterDelay("eat", 600, location);
                }
            }
            __result = true;
            return(false);
        }
        public static bool DoFunction(MilkPail __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            if (!IsFeedingBasket(__instance))
            {
                return(true);
            }

            string feedingBasketId = __instance.modData[FeedingBasketKey];

            BaseToolDoFunction(__instance, location, x, y, power, who);
            __instance.CurrentParentTileIndex    = InitialParentTileIndex;
            __instance.indexOfMenuItemView.Value = IndexOfMenuItemView;

            Animals.TryGetValue(feedingBasketId, out FarmAnimal animal);
            if (animal != null)
            {
                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    double professionAjust = 1.0;
                    if (!animal.isCoopDweller() && who.professions.Contains(3) || animal.isCoopDweller() && who.professions.Contains(2))
                    {
                        professionAjust += DataLoader.ModConfig.PercentualAjustOnFriendshipInscreaseFromProfessions;
                    }
                    animal.friendshipTowardFarmer.Value = Math.Min(1000, animal.friendshipTowardFarmer.Value + (int)Math.Ceiling(professionAjust * __instance.attachments[0].Price * (1.0 + __instance.attachments[0].Quality * 0.25) / (animal.price.Value / 1000.0)));
                }
                if (!DataLoader.ModConfig.DisableMoodInscreseWithTreats)
                {
                    animal.happiness.Value = byte.MaxValue;
                }

                if (DataLoader.ModConfig.EnableTreatsCountAsAnimalFeed)
                {
                    animal.fullness.Value = byte.MaxValue;
                }

                TreatsController.FeedAnimalTreat(animal, __instance.attachments[0]);

                if (__instance.attachments[0].Category == SObject.MilkCategory)
                {
                    animal.age.Value = Math.Min(animal.ageWhenMature.Value - 1, animal.age.Value + 1);
                }

                --__instance.attachments[0].Stack;
                if (__instance.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName }));
                    __instance.attachments[0] = null;
                }
            }
            if (Pets.TryGetValue(feedingBasketId, out Pet pet) && pet != null)
            {
                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    pet.friendshipTowardFarmer.Value = Math.Min(Pet.maxFriendship, pet.friendshipTowardFarmer.Value + 6);
                }
                TreatsController.FeedAnimalTreat(pet, __instance.attachments[0]);

                --__instance.attachments[0].Stack;
                if (__instance.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName }));
                    __instance.attachments[0] = null;
                }
            }
            Animals[feedingBasketId] = (FarmAnimal)null;
            Pets[feedingBasketId]    = (Pet)null;

            if (Game1.activeClickableMenu == null)
            {
                who.CanMove = true;
                who.completelyStopAnimatingOrDoingAction();
            }
            else
            {
                who.Halt();
            }
            who.UsingTool      = false;
            who.canReleaseTool = true;

            DataLoader.Helper.Reflection.GetMethod(__instance, "finish").Invoke();

            return(false);
        }
Exemple #15
0
        public static bool Prefix(MilkPail __instance, GameLocation location, int x, int y, Farmer who, ref bool __result, ref FarmAnimal ___animal)
        {
            if (location is not LunarLocation)
            {
                return(true);
            }

            x = ( int )who.GetToolLocation().X;
            y = ( int )who.GetToolLocation().Y;
            Rectangle r = new Rectangle(x - 32, y - 32, 64, 64);

            if (location is Farm)
            {
                ___animal = Utility.GetBestHarvestableFarmAnimal((location as Farm).animals.Values, __instance, r);
            }
            else if (location is AnimalHouse)
            {
                ___animal = Utility.GetBestHarvestableFarmAnimal((location as AnimalHouse).animals.Values, __instance, r);
            }
            else if (location is IAnimalLocation aloc)
            {
                ___animal = Utility.GetBestHarvestableFarmAnimal(aloc.Animals.Values, __instance, r);
            }
            if (___animal != null && ( int )___animal.currentProduce > 0 && ( int )___animal.age >= ( byte )___animal.ageWhenMature && ___animal.toolUsedForHarvest.Equals(__instance.BaseName) && who.couldInventoryAcceptThisObject(___animal.currentProduce, 1))
            {
                ___animal.doEmote(20);
                ___animal.friendshipTowardFarmer.Value = Math.Min(1000, ( int )___animal.friendshipTowardFarmer + 5);
                who.currentLocation.localSound("Milking");
                ___animal.pauseTimer = 1500;
            }
            else if (___animal != null && ( int )___animal.currentProduce > 0 && ( int )___animal.age >= ( byte )___animal.ageWhenMature)
            {
                if (who != null && Game1.player.Equals(who))
                {
                    if (!___animal.toolUsedForHarvest.Equals(__instance.BaseName))
                    {
                        if (!(___animal.toolUsedForHarvest == null) && !___animal.toolUsedForHarvest.Equals("null"))
                        {
                            Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14167", ___animal.toolUsedForHarvest));
                        }
                    }
                    else if (!who.couldInventoryAcceptThisObject(___animal.currentProduce, 1))
                    {
                        Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588"));
                    }
                }
            }
            else if (who != null && Game1.player.Equals(who))
            {
                DelayedAction.playSoundAfterDelay("fishingRodBend", 300);
                DelayedAction.playSoundAfterDelay("fishingRodBend", 1200);
                string toSay = "";
                if (___animal != null && !___animal.toolUsedForHarvest.Equals(__instance.BaseName))
                {
                    toSay = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14175", ___animal.displayName);
                }
                if (___animal != null && ___animal.isBaby() && ___animal.toolUsedForHarvest.Equals(__instance.BaseName))
                {
                    toSay = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14176", ___animal.displayName);
                }
                if (___animal != null && ( int )___animal.age >= ( byte )___animal.ageWhenMature && ___animal.toolUsedForHarvest.Equals(__instance.BaseName))
                {
                    toSay = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14177", ___animal.displayName);
                }
                if (toSay.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(toSay, 1000);
                }
            }
            who.Halt();
            int g = who.FarmerSprite.CurrentFrame;

            who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4);
            who.FarmerSprite.oldFrame = g;
            who.UsingTool             = true;
            who.CanMove = false;
            __result    = true;
            return(false);
        }
Exemple #16
0
        //JsonSerializer a = new JsonSerializer();

        public void loadData()
        {
            config = instance.Helper.Data.ReadJsonFile <ModData>($"data/{Constants.SaveFolderName}.json") ?? new ModData();

            List <List <string> > itemInfo = config.itemInfo;

            maxTab = config.maxTab;

            cost = config.cost;

            int y = 0;
            int z = 1;

            invs[0] = Game1.player.Items;
            invs.Add(new List <Item>());

            for (int i = 0; i < itemInfo.Count; i++)
            {
                if (y == 36)
                {
                    invs.Add(new List <Item>());
                    z++;
                    y = 0;
                }

                if (itemInfo[i][0] == "null")
                {
                    invs[z].Add((null));
                }
                else if (itemInfo[i][0] == "toolz")
                {
                    Tool x = (Tool)null;

                    if (itemInfo[i][1] == "0")
                    {
                        x = new Axe();
                        x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "1")
                    {
                        x = new Hoe();
                    }
                    else if (itemInfo[i][1] == "2")
                    {
                        x = new FishingRod(int.Parse(itemInfo[i][2]));
                    }
                    else if (itemInfo[i][1] == "3")
                    {
                        x = new Pickaxe();
                        x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "4")
                    {
                        x = new WateringCan();
                        x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "5")
                    {
                        x = new MeleeWeapon(int.Parse(itemInfo[i][3])); //sprite index??
                        x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "6")
                    {
                        x = new Slingshot();
                        x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "7")
                    {
                        x = new Lantern();
                        //x.UpgradeLevel = int.Parse(itemInfo[i][2]);
                    }
                    else if (itemInfo[i][1] == "8")
                    {
                        x = new MagnifyingGlass();
                    }
                    else if (itemInfo[i][1] == "9")
                    {
                        x = new MilkPail();
                    }
                    else if (itemInfo[i][1] == "10")
                    {
                        x = new Pan();
                    }
                    else if (itemInfo[i][1] == "11")
                    {
                        x = new Raft();
                    }
                    else if (itemInfo[i][1] == "12")
                    {
                        x = new Seeds(itemInfo[i][2], int.Parse(itemInfo[i][3]));
                    }
                    else if (itemInfo[i][1] == "13")
                    {
                        x = new Shears();
                    }
                    else if (itemInfo[i][1] == "14")
                    {
                        x = new Sword(itemInfo[i][2], int.Parse(itemInfo[i][3]));
                    }
                    else if (itemInfo[i][1] == "15")
                    {
                        x = new Wand();
                    }

                    invs[z].Add(x);
                }
                else
                {
                    StardewValley.Object x = new StardewValley.Object(int.Parse(itemInfo[i][0]), int.Parse(itemInfo[i][1]));

                    //x.SpecialVariable = int.Parse(itemInfo[i][2]);
                    //x.Category = int.Parse(itemInfo[i][3]);
                    //x.Name = itemInfo[i][4];
                    //x.DisplayName = itemInfo[i][5];

                    invs[z].Add((Item)(x));
                }

                y++;
            }
        }
Exemple #17
0
 private static bool IsFeedingBasket(MilkPail tool)
 {
     return(tool.modData.ContainsKey(FeedingBasketKey));
 }
Exemple #18
0
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            string inseminationSyringeId = __instance.modData[InseminationSyringeKey];

            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            if (!DataLoader.ModConfig.DisablePregnancy)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
            }

            Animals.TryGetValue(inseminationSyringeId, out FarmAnimal animal);
            if (animal != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.Empty"));
                    Animals[inseminationSyringeId] = null;
                }
                else if (AnimalExtension.GetAnimalFromType(animal.type.Value) == null)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (IsEggAnimal(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = animal.displayName });
                }
                else if (!((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.HasValue)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.TooYoung", new { animalName = animal.displayName });
                }
                else if (PregnancyController.IsAnimalPregnant(animal))
                {
                    int daysUntilBirth = animal.GetDaysUntilBirth().Value;
                    if (daysUntilBirth > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.AlreadyPregnant", new { animalName = animal.displayName, numberOfDays = daysUntilBirth });
                    }
                    else
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.ReadyForBirth", new { animalName = animal.displayName });
                    }
                }
                else if (!CheckCorrectProduct(animal, __instance.attachments[0]))
                {
                    var    data        = DataLoader.Helper.Content.Load <Dictionary <int, string> >(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
                    string produceName = data[animal.defaultProduceIndex.Value].Split('/')[4];
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
                }
                else if (PregnancyController.CheckBuildingLimit(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.BuildingLimit", new { buildingType = animal.displayHouse });
                }
                else
                {
                    animal.doEmote(16, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        if (animal.sound.Value != null)
                        {
                            ICue animalSound = Game1.soundBank.GetCue(animal.sound.Value);
                            animalSound.Play();
                        }

                        DelayedAction.playSoundAfterDelay("fishingRodBend", 300, location);
                        DelayedAction.playSoundAfterDelay("fishingRodBend", 1200, location);
                    }
                    animal.pauseTimer = 1500;
                }
                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Animals[inseminationSyringeId] = null;
                }
            }

            who.Halt();
            int currentFrame = who.FarmerSprite.currentFrame;

            if (animal != null)
            {
                who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4);
            }
            else
            {
                who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                    new FarmerSprite.AnimationFrame(currentFrame, 0, false, who.FacingDirection == 3, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                });
            }
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;

            __result = true;
            return(false);
        }
        public static void LoadContentPacks(object sender, EventArgs e)
        {
            foreach (IContentPack contentPack in MailFrameworkModEntry.ModHelper.ContentPacks.GetOwned())
            {
                if (File.Exists(Path.Combine(contentPack.DirectoryPath, "mail.json")))
                {
                    bool hasTranslation = contentPack.Translation.GetTranslations().Any();

                    MailFrameworkModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
                    List <MailItem> mailItems = contentPack.ReadJsonFile <List <MailItem> >("mail.json");
                    foreach (MailItem mailItem in mailItems)
                    {
                        Dictionary <int, string> objects    = null;
                        Dictionary <int, string> bigObjects = null;
                        Dictionary <int, string> furnitures = null;
                        Dictionary <int, string> weapons    = null;
                        Dictionary <int, string> boots      = null;

                        //Populate all Indexes based on the given name. Ignore the letter otherwise.
                        if (mailItem.CollectionConditions != null && mailItem.CollectionConditions.Any(c =>
                        {
                            if (c.Name != null && c.Collection != Collection.Crafting)
                            {
                                objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/ObjectInformation"), ContentSource.GameContent);
                                KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(c.Name + "/"));
                                if (pair.Value != null)
                                {
                                    c.Index = pair.Key;
                                }
                                else
                                {
                                    MailFrameworkModEntry.ModMonitor.Log($"No object found with the name '{c.Name}' for a condition for letter '{mailItem.Id}'.\n This letter will be ignored.", LogLevel.Warn);
                                    MailDao.RemoveLetter(new Letter(mailItem.Id, null, null));
                                    return(true);
                                }
                            }
                            return(false);
                        }))
                        {
                            continue;
                        }

                        bool Condition(Letter l) =>
                        (!Game1.player.mailReceived.Contains(l.Id) || mailItem.Repeatable) &&
                        (mailItem.Recipe == null || !Game1.player.cookingRecipes.ContainsKey(mailItem.Recipe)) &&
                        (mailItem.Date == null || SDate.Now() >= new SDate(Convert.ToInt32(mailItem.Date.Split(' ')[0]), mailItem.Date.Split(' ')[1], Convert.ToInt32(mailItem.Date.Split(' ')[2].Replace("Y", "")))) &&
                        (mailItem.Days == null || mailItem.Days.Contains(SDate.Now().Day)) &&
                        (mailItem.Seasons == null || mailItem.Seasons.Contains(SDate.Now().Season)) &&
                        (mailItem.Weather == null || (Game1.isRaining && "rainy".Equals(mailItem.Weather)) || (!Game1.isRaining && "sunny".Equals(mailItem.Weather))) &&
                        (mailItem.FriendshipConditions == null || (mailItem.FriendshipConditions.TrueForAll(f => Game1.player.getFriendshipHeartLevelForNPC(f.NpcName) >= f.FriendshipLevel)) &&
                         mailItem.FriendshipConditions.TrueForAll(f => f.FriendshipStatus == null || (Game1.player.friendshipData.ContainsKey(f.NpcName) && f.FriendshipStatus.Any(s => s == Game1.player.friendshipData[f.NpcName].Status)))) &&
                        (mailItem.SkillConditions == null || mailItem.SkillConditions.TrueForAll(s => Game1.player.getEffectiveSkillLevel((int)s.SkillName) >= s.SkillLevel)) &&
                        (mailItem.StatsConditions == null || (mailItem.StatsConditions.TrueForAll(s => s.StatsLabel == null || Game1.player.stats.getStat(s.StatsLabel) >= s.Amount) && mailItem.StatsConditions.TrueForAll(s => s.StatsName == null || MailFrameworkModEntry.ModHelper.Reflection.GetProperty <uint>(Game1.player.stats, s.StatsName.ToString()).GetValue() >= s.Amount))) &&
                        (mailItem.CollectionConditions == null || (mailItem.CollectionConditions.TrueForAll(c =>
                                                                                                            (c.Collection == Collection.Shipped && Game1.player.basicShipped.ContainsKey(c.Index) && Game1.player.basicShipped[c.Index] >= c.Amount) ||
                                                                                                            (c.Collection == Collection.Fish && Game1.player.fishCaught.ContainsKey(c.Index) && Game1.player.fishCaught[c.Index][0] >= c.Amount) ||
                                                                                                            (c.Collection == Collection.Artifacts && Game1.player.archaeologyFound.ContainsKey(c.Index) && Game1.player.archaeologyFound[c.Index][0] >= c.Amount) ||
                                                                                                            (c.Collection == Collection.Minerals && Game1.player.mineralsFound.ContainsKey(c.Index) && Game1.player.mineralsFound[c.Index] >= c.Amount) ||
                                                                                                            (c.Collection == Collection.Cooking && Game1.player.recipesCooked.ContainsKey(c.Index) && Game1.player.recipesCooked[c.Index] >= c.Amount) ||
                                                                                                            (c.Collection == Collection.Crafting && Game1.player.craftingRecipes.ContainsKey(c.Name) && Game1.player.craftingRecipes[c.Name] >= c.Amount)
                                                                                                            ))) &&
                        (mailItem.RandomChance == null || new Random((int)(((ulong)Game1.stats.DaysPlayed * 1000000000000000) + (((ulong)l.Id.GetHashCode()) % 1000000000 * 1000000) + Game1.uniqueIDForThisGame % 1000000)).NextDouble() < mailItem.RandomChance) &&
                        (mailItem.Buildings == null || (mailItem.RequireAllBuildings ? mailItem.Buildings.TrueForAll(b => Game1.getFarm().isBuildingConstructed(b)) : mailItem.Buildings.Any(b => Game1.getFarm().isBuildingConstructed(b)))) &&
                        (mailItem.MailReceived == null || (mailItem.RequireAllMailReceived ? !mailItem.MailReceived.Except(Game1.player.mailReceived).Any() : mailItem.MailReceived.Intersect(Game1.player.mailReceived).Any())) &&
                        (mailItem.MailNotReceived == null || !mailItem.MailNotReceived.Intersect(Game1.player.mailReceived).Any()) &&
                        (mailItem.EventsSeen == null || (mailItem.RequireAllEventsSeen ? !mailItem.EventsSeen.Except(Game1.player.eventsSeen).Any() : mailItem.EventsSeen.Intersect(Game1.player.eventsSeen).Any())) &&
                        (mailItem.EventsNotSeen == null || !mailItem.EventsNotSeen.Intersect(Game1.player.eventsSeen).Any()) &&
                        (mailItem.RecipeKnown == null || (mailItem.RequireAllRecipeKnown ? mailItem.RecipeKnown.All(r => Game1.player.knowsRecipe(r)) : mailItem.RecipeKnown.Any(r => Game1.player.knowsRecipe(r)))) &&
                        (mailItem.RecipeNotKnown == null || mailItem.RecipeNotKnown.All(r => !Game1.player.knowsRecipe(r))) &&
                        (mailItem.ExpandedPrecondition == null || (ConditionsCheckerApi != null && ConditionsCheckerApi.CheckConditions(mailItem.ExpandedPrecondition))) &&
                        (mailItem.ExpandedPreconditions == null || (ConditionsCheckerApi != null && ConditionsCheckerApi.CheckConditions(mailItem.ExpandedPreconditions))) &&
                        (mailItem.HouseUpgradeLevel == null || mailItem.HouseUpgradeLevel <= Game1.player.HouseUpgradeLevel)
                        ;

                        if (mailItem.Attachments != null && mailItem.Attachments.Count > 0)
                        {
                            List <Item> attachments = new List <Item>();
                            mailItem.Attachments.ForEach(i =>
                            {
                                if (i == null)
                                {
                                    return;
                                }
                                switch (i.Type)
                                {
                                case ItemType.Object:
                                    if (i.Name != null)
                                    {
                                        objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/ObjectInformation"), ContentSource.GameContent);
                                        KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No object found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }

                                    if (i.Index.HasValue)
                                    {
                                        attachments.Add(new StardewValley.Object(Vector2.Zero, i.Index.Value, i.Stack ?? 1));
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach an object for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.BigObject:
                                case ItemType.BigCraftable:
                                    if (i.Name != null)
                                    {
                                        bigObjects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/BigCraftablesInformation"), ContentSource.GameContent);
                                        KeyValuePair <int, string> pair = bigObjects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No big craftable found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }

                                    if (i.Index.HasValue)
                                    {
                                        Item item = new StardewValley.Object(Vector2.Zero, i.Index.Value);
                                        if (i.Stack.HasValue)
                                        {
                                            item.Stack = i.Stack.Value;
                                        }
                                        attachments.Add(item);
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a big craftable for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.Tool:
                                    Tool tool = null;
                                    switch (i.Name)
                                    {
                                    case "Axe":
                                        tool = new Axe();
                                        break;

                                    case "Hoe":
                                        tool = new Hoe();
                                        break;

                                    case "Watering Can":
                                        tool = new WateringCan();
                                        break;

                                    case "Scythe":
                                        tool = new MeleeWeapon(47);
                                        break;

                                    case "Golden Scythe":
                                        tool = new MeleeWeapon(53);
                                        break;

                                    case "Pickaxe":
                                        tool = new Pickaxe();
                                        break;

                                    case "Milk Pail":
                                        tool = new MilkPail();
                                        break;

                                    case "Shears":
                                        tool = new Shears();
                                        break;

                                    case "Fishing Rod":
                                        tool = new FishingRod(i.UpgradeLevel);
                                        break;

                                    case "Pan":
                                        tool = new Pan();
                                        break;

                                    case "Return Scepter":
                                        tool = new Wand();
                                        break;

                                    default:
                                        MailFrameworkModEntry.ModMonitor.Log($"Tool with name {i.Name} not found for letter {mailItem.Id}.", LogLevel.Warn);
                                        break;
                                    }
                                    if (tool != null)
                                    {
                                        if (!NoUpgradeLevelTools.Contains(i.Name))
                                        {
                                            tool.UpgradeLevel = i.UpgradeLevel;
                                        }
                                        attachments.Add(tool);
                                    }
                                    break;

                                case ItemType.Ring:
                                    objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >("Data\\ObjectInformation", ContentSource.GameContent);
                                    if (i.Name != null)
                                    {
                                        KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No ring found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }
                                    if (i.Index.HasValue)
                                    {
                                        if (objects[i.Index.Value].Split('/')[3] == "Ring")
                                        {
                                            attachments.Add(new Ring(i.Index.Value));
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"A valid ring is required to attach an ring for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach an ring for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.Furniture:
                                    if (i.Name != null)
                                    {
                                        furnitures ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Furniture"), ContentSource.GameContent);
                                        KeyValuePair <int, string> pair = furnitures.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No furniture found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }

                                    if (i.Index.HasValue)
                                    {
                                        attachments.Add(Furniture.GetFurnitureInstance(i.Index.Value));
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a furniture for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.Weapon:
                                    if (i.Name != null)
                                    {
                                        weapons ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Weapons"), ContentSource.GameContent);
                                        KeyValuePair <int, string> pair = weapons.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No weapon found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }

                                    if (i.Index.HasValue)
                                    {
                                        int index = i.Index.Value;
                                        attachments.Add(SlingshotIndexes.Contains(index) ? (Item) new Slingshot(index) : (Item) new MeleeWeapon(index));
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a weapon for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.Boots:
                                    if (i.Name != null)
                                    {
                                        boots ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Boots"), ContentSource.GameContent);
                                        KeyValuePair <int, string> pair = boots.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/"));
                                        if (pair.Value != null)
                                        {
                                            i.Index = pair.Key;
                                        }
                                        else
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"No boots found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                        }
                                    }

                                    if (i.Index.HasValue)
                                    {
                                        attachments.Add(new Boots(i.Index.Value));
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a boots for letter {mailItem.Id}.", LogLevel.Warn);
                                    }
                                    break;

                                case ItemType.DGA:
                                    if (DgaApi != null)
                                    {
                                        try
                                        {
                                            object dgaObject = DgaApi.SpawnDGAItem(i.Name);
                                            if (dgaObject is StardewValley.Item dgaItem)
                                            {
                                                if (dgaItem is StardewValley.Object)
                                                {
                                                    dgaItem.Stack = i.Stack ?? 1;
                                                }
                                                else
                                                {
                                                    dgaItem.Stack = 1;
                                                }

                                                attachments.Add(dgaItem);
                                            }
                                            else
                                            {
                                                MailFrameworkModEntry.ModMonitor.Log($"No DGA item found with the ID {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MailFrameworkModEntry.ModMonitor.Log($"Error trying to create item with the DGA ID {i.Name} for letter {mailItem.Id}.", LogLevel.Warn);
                                            MailFrameworkModEntry.ModMonitor.Log(ex.Message, LogLevel.Trace);
                                        }
                                    }
                                    else
                                    {
                                        MailFrameworkModEntry.ModMonitor.Log($"No DGA API found, so item with the ID {i.Name} for letter {mailItem.Id} will be ignored.", LogLevel.Warn);
                                    }
                                    break;

                                default:
                                    MailFrameworkModEntry.ModMonitor.Log($"Invalid attachment type '{i.Type}' found in letter {mailItem.Id}.", LogLevel.Warn);
                                    break;
                                }
                            });
                            MailDao.SaveLetter(
                                new Letter(
                                    mailItem.Id
                                    , hasTranslation && mailItem.Text != null ? contentPack.Translation.Get(mailItem.Text) : mailItem.Text
                                    , attachments
                                    , Condition
                                    , (l) =>
                            {
                                Game1.player.mailReceived.Add(l.Id);
                                if (mailItem.AdditionalMailReceived != null)
                                {
                                    Game1.player.mailReceived.AddRange(mailItem.AdditionalMailReceived);
                                }
                            }
                                    , mailItem.WhichBG
                                    )
                            {
                                TextColor     = mailItem.TextColor,
                                Title         = hasTranslation && mailItem.Title != null ? contentPack.Translation.Get(mailItem.Title) : mailItem.Title,
                                GroupId       = mailItem.GroupId,
                                LetterTexture = mailItem.LetterBG != null ? GetTextureAsset(contentPack, mailItem.LetterBG) : null,
                                UpperRightCloseButtonTexture = mailItem.UpperRightCloseButton != null ? GetTextureAsset(contentPack, mailItem.UpperRightCloseButton) : null,
                                AutoOpen = mailItem.AutoOpen,
                            });
                        }
                        else
                        {
                            MailDao.SaveLetter(
                                new Letter(
                                    mailItem.Id
                                    , hasTranslation && mailItem.Text != null ? contentPack.Translation.Get(mailItem.Text) : mailItem.Text
                                    , mailItem.Recipe
                                    , Condition
                                    , (l) =>
                            {
                                Game1.player.mailReceived.Add(l.Id);
                                if (mailItem.AdditionalMailReceived != null)
                                {
                                    Game1.player.mailReceived.AddRange(mailItem.AdditionalMailReceived);
                                }
                            }
                                    , mailItem.WhichBG
                                    )
                            {
                                TextColor     = mailItem.TextColor,
                                Title         = hasTranslation && mailItem.Title != null ? contentPack.Translation.Get(mailItem.Title) : mailItem.Title,
                                GroupId       = mailItem.GroupId,
                                LetterTexture = mailItem.LetterBG != null ? GetTextureAsset(contentPack, mailItem.LetterBG) : null,
                                UpperRightCloseButtonTexture = mailItem.UpperRightCloseButton != null ? GetTextureAsset(contentPack, mailItem.UpperRightCloseButton) : null,
                                AutoOpen = mailItem.AutoOpen,
                            });
                        }
                    }
                }
                else
                {
                    MailFrameworkModEntry.ModMonitor.Log($"Ignoring content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an mail.json file.", LogLevel.Warn);
                }
            }
        }
 private static bool IsParticipantRibbon(MilkPail tool)
 {
     return(tool.modData.ContainsKey(ParticipantRibbonKey));
 }