Ejemplo n.º 1
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 override bool beginUsing(GameLocation location, int x, int y, StardewValley.Farmer who)
        {
            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 (Context.IsMainPlayer && !DataLoader.ModConfig.DisablePregnancy)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            this._animal = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            this._animal = farmAnimal;
                            break;
                        }
                    }
                }
            }

            if (this._animal != null)
            {
                string dialogue = "";
                if (this.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.Empty"));
                    this._animal = null;
                }
                else if (AnimalExtension.GetAnimalFromType(this._animal.type.Value) == null)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = this._animal.displayName });
                }
                else if (IsEggAnimal(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = this._animal.displayName });
                }
                else if (this._animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.TooYoung", new { animalName = this._animal.displayName });
                }
                else if (PregnancyController.IsAnimalPregnant(this._animal.myID.Value))
                {
                    int daysUtillBirth = PregnancyController.GetPregnancyItem(this._animal.myID.Value).DaysUntilBirth;
                    if (daysUtillBirth > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.AlreadyPregnant", new { animalName = this._animal.displayName, numberOfDays = daysUtillBirth });
                    }
                    else
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.ReadyForBirth", new { animalName = this._animal.displayName });
                    }
                }
                else if (!CheckCorrectProduct(this._animal, this.attachments[0]))
                {
                    var    data        = DataLoader.Helper.Content.Load <Dictionary <int, string> >(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
                    string produceName = data[this._animal.defaultProduceIndex.Value].Split('/')[4];
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
                }
                else if (PregnancyController.CheckBuildingLimit(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.BuildingLimit", new { buildingType = this._animal.displayHouse });
                }
                else
                {
                    this._animal.doEmote(16, true);
                    if (this._animal.sound.Value != null)
                    {
                        Cue animalSound = Game1.soundBank.GetCue(this._animal.sound.Value);
                        animalSound.Play();
                    }
                    DelayedAction.playSoundAfterDelay("fishingRodBend", 300);
                    DelayedAction.playSoundAfterDelay("fishingRodBend", 1200);
                    this._animal.pauseTimer = 1500;
                }
                if (dialogue.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    this._animal = null;
                }
            }



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

            if (this._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;

            return(true);
        }