Beispiel #1
0
        private static void addNewHatchedAnimal(string name)
        {
            Building   building   = parentAnimal.home;
            FarmAnimal farmAnimal = new FarmAnimal(parentAnimal.type.Value, DataLoader.Helper.Multiplayer.GetNewID(), (long)Game1.player.UniqueMultiplayerID)
            {
                Name        = name,
                displayName = name,

                home = building,
            };

            farmAnimal.parentId.Value     = parentAnimal.myID.Value;
            farmAnimal.homeLocation.Value = new Vector2((float)building.tileX.Value, (float)building.tileY.Value);
            farmAnimal.setRandomPosition(farmAnimal.home.indoors.Value);
            (building.indoors.Value as AnimalHouse).animals.Add(farmAnimal.myID.Value, farmAnimal);
            (building.indoors.Value as AnimalHouse).animalsThatLiveHere.Add(farmAnimal.myID.Value);

            PregnancyItem pregnacyItem = PregnancyController.GetPregnancyItem(parentAnimal.myID.Value);

            parentAnimal.allowReproduction.Value = pregnacyItem.AllowReproductionBeforeInsemination;
            PregnancyController.RemovePregnancyItem(pregnacyItem.Id);
            parentAnimal = null;

            Game1.exitActiveMenu();
        }
Beispiel #2
0
        public AnimalQueryMenuExtended(FarmAnimal farmAnimal) : base(farmAnimal)
        {
            _farmAnimal = farmAnimal;
            if (Context.IsMainPlayer && !DataLoader.ModConfig.DisablePregnancy)
            {
                if (PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value))
                {
                    this.allowReproductionButton = null;
                    pregnantStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.pixelZoom * 3,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth + Game1.pixelZoom,
                            Game1.pixelZoom * 11, Game1.pixelZoom * 11), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(34, 29, 11, 11), 4f, false);
                }
            }

            if (Context.IsMainPlayer && !DataLoader.ModConfig.DisableTreats && TreatsController.CanReceiveTreat(farmAnimal))
            {
                if (TreatsController.IsReadyForTreat(farmAnimal))
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites,
                        new Microsoft.Xna.Framework.Rectangle(240, 0, 16, 16), 4f, false);
                }
                else
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(16, 28, 16, 16), 4f, false);
                }
            }

            if (AnimalContestController.IsParticipant(farmAnimal))
            {
                animalContestIndicator = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 4 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites, new Microsoft.Xna.Framework.Rectangle(256, 0, 16, 16), 4f, false);
            }

            if (!DataLoader.ModConfig.DisableMeat && MeatController.CanGetMeatFrom(farmAnimal))
            {
                if (!this._farmAnimal.isBaby())
                {
                    meatButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 3 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites, new Microsoft.Xna.Framework.Rectangle(0, 28, 16, 16), 4f, false);
                }
            }

            _parentName     = DataLoader.Helper.Reflection.GetField <String>(this, "parentName").GetValue();
            _textBox        = DataLoader.Helper.Reflection.GetField <TextBox>(this, "textBox").GetValue();
            _movingAnimal   = DataLoader.Helper.Reflection.GetField <bool>(this, "movingAnimal");
            _confirmingSell = DataLoader.Helper.Reflection.GetField <bool>(this, "confirmingSell");
            _lovelLevel     = DataLoader.Helper.Reflection.GetField <double>(this, "loveLevel");
            _hoverText      = DataLoader.Helper.Reflection.GetField <string>(this, "hoverText");
        }
Beispiel #3
0
        public static FarmAnimal GetAnimal(long id)
        {
            FarmAnimal animal = Utility.getAnimal(id);

            if (animal != null)
            {
                return(animal);
            }
            else
            {
                AnimalHusbandryModEntry.monitor.Log($"The animal id '{id}' was not found in the game and its pregnancy data is being discarted.", LogLevel.Warn);
                PregnancyController.RemovePregnancyItem(id);
                return(null);
            }
        }
Beispiel #4
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (Game1.globalFade)
            {
                return;
            }
            if (_movingAnimal.GetValue())
            {
                Building buildingAt = (Game1.getLocationFromName("Farm") as Farm).getBuildingAt(new Vector2((float)((x + Game1.viewport.X) / Game1.tileSize), (float)((y + Game1.viewport.Y) / Game1.tileSize)));
                if
                (
                    buildingAt != null &&
                    buildingAt.buildingType.Value.Contains(this._farmAnimal.buildingTypeILiveIn.Value) &&
                    !((AnimalHouse)buildingAt.indoors.Value).isFull() &&
                    !buildingAt.Equals((object)this._farmAnimal.home) &&
                    PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value) &&
                    PregnancyController.CheckBuildingLimit(((AnimalHouse)buildingAt.indoors.Value))
                )
                {
                    if (this.okButton != null && this.okButton.containsPoint(x, y))
                    {
                        Game1.globalFadeToBlack(new Game1.afterFadeFunction(this.prepareForReturnFromPlacement), 0.02f);
                        Game1.playSound("smallSelect");
                    }
                    Game1.showRedMessage(DataLoader.i18n.Get("Menu.AnimalQueryMenu.PregnancyBuildingLimit", new { buildingType = this._farmAnimal.displayHouse }));
                    return;
                }
            }
            else if (this.confirmingMeat)
            {
                if (this.yesButton.containsPoint(x, y))
                {
                    (this._farmAnimal.home.indoors.Value as AnimalHouse)?.animalsThatLiveHere.Remove(this._farmAnimal.myID.Value);
                    this._farmAnimal.health.Value = -1;
                    int num1 = this._farmAnimal.frontBackSourceRect.Width / 2;
                    for (int index = 0; index < num1; ++index)
                    {
                        int num2 = Game1.random.Next(25, 200);
                        Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(5, this._farmAnimal.position + new Vector2((float)Game1.random.Next(-Game1.tileSize / 2, this._farmAnimal.frontBackSourceRect.Width * 3), (float)Game1.random.Next(-Game1.tileSize / 2, this._farmAnimal.frontBackSourceRect.Height * 3)), new Color((int)byte.MaxValue - num2, (int)byte.MaxValue, (int)byte.MaxValue - num2), 8, false, Game1.random.NextDouble() < 0.5 ? 50f : (float)Game1.random.Next(30, 200), 0, Game1.tileSize, -1f, Game1.tileSize, Game1.random.NextDouble() < 0.5 ? 0 : Game1.random.Next(0, 600))
                        {
                            scale  = (float)Game1.random.Next(2, 5) * 0.25f,
                            alpha  = (float)Game1.random.Next(2, 5) * 0.25f,
                            motion = new Vector2(0.0f, (float)-Game1.random.NextDouble())
                        });
                    }
                    Game1.playSound("newRecipe");
                    Game1.playSound("money");
                    Game1.exitActiveMenu();
                    Game1.player.Stamina -= ((float)4f - (float)Game1.player.FarmingLevel * 0.2f);
                    Game1.player.Stamina -= ((float)4f - (float)Game1.player.FarmingLevel * 0.2f);
                    Game1.player.gainExperience(0, 5);
                    MeatController.AddItemsToInventoryByMenuIfNecessary(MeatController.CreateMeat(this._farmAnimal));
                }
                else
                {
                    if (!this.noButton.containsPoint(x, y))
                    {
                        return;
                    }
                    this.confirmingMeat = false;
                    Game1.playSound("smallSelect");
                    if (!Game1.options.SnappyMenus)
                    {
                        return;
                    }
                    this.currentlySnappedComponent = this.getComponentWithID(103);
                    this.snapCursorToCurrentSnappedComponent();
                }
                return;
            }
            else if (!_confirmingSell.GetValue())
            {
                if (this.meatButton?.containsPoint(x, y) ?? false)
                {
                    this.confirmingMeat = true;
                    ClickableTextureComponent textureComponent1 = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(Game1.viewport.Width / 2 - Game1.tileSize - 4, Game1.viewport.Height / 2 - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46, -1, -1), 1f, false);
                    textureComponent1.myID            = 111;
                    textureComponent1.rightNeighborID = 105;
                    this.yesButton = textureComponent1;
                    ClickableTextureComponent textureComponent2 = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(Game1.viewport.Width / 2 + 4, Game1.viewport.Height / 2 - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 47, -1, -1), 1f, false);
                    textureComponent2.myID           = 105;
                    textureComponent2.leftNeighborID = 111;
                    this.noButton = textureComponent2;
                    Game1.playSound("smallSelect");
                    if (!Game1.options.SnappyMenus)
                    {
                        return;
                    }
                    this.populateClickableComponentList();
                    this.currentlySnappedComponent = (ClickableComponent)this.noButton;
                    this.snapCursorToCurrentSnappedComponent();
                }
                else if (this.animalContestIndicator?.containsPoint(x, y) ?? false && AnimalContestController.CanChangeParticipant(this._farmAnimal))
                {
                    this.animalContestIndicator = null;
                    AnimalContestController.RemoveAnimalParticipant(this._farmAnimal);
                    Game1.player.addItemByMenuIfNecessary(new ParticipantRibbon());
                }
            }

            base.receiveLeftClick(x, y, playSound);
        }
Beispiel #5
0
 public override void performHoverAction(int x, int y)
 {
     base.performHoverAction(x, y);
     if (_movingAnimal.GetValue())
     {
         Vector2  tile             = new Vector2((float)((x + Game1.viewport.X) / Game1.tileSize), (float)((y + Game1.viewport.Y) / Game1.tileSize));
         Farm     locationFromName = Game1.getLocationFromName("Farm") as Farm;
         Building buildingAt       = locationFromName.getBuildingAt(tile);
         if (buildingAt != null)
         {
             if (buildingAt.color.Equals(Color.LightGreen * 0.8f) &&
                 PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value) &&
                 PregnancyController.CheckBuildingLimit((buildingAt.indoors.Value as AnimalHouse)))
             {
                 buildingAt.color.Value = Color.Red * 0.8f;
             }
         }
     }
     else
     {
         if (this.meatButton != null)
         {
             if (this.meatButton.containsPoint(x, y))
             {
                 this.meatButton.scale = Math.Min(4.1f, this.meatButton.scale + 0.05f);
                 _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ExchangeAnimalForMeat"));
             }
             else
             {
                 this.meatButton.scale = Math.Max(4f, this.sellButton.scale - 0.05f);
             }
         }
         if (this.pregnantStatus != null)
         {
             if (this.pregnantStatus.containsPoint(x, y))
             {
                 int daysUtilBirth = PregnancyController.GetPregnancyItem(this._farmAnimal.myID.Value).DaysUntilBirth;
                 if (daysUtilBirth > 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.DaysUntilBirth", new { numberOfDays = daysUtilBirth }));
                 }
                 else
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ReadyForBirth"));
                 }
             }
         }
         if (this.treatStatus != null)
         {
             if (this.treatStatus.containsPoint(x, y))
             {
                 int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(this._farmAnimal);
                 if (daysUntilNextTreat > 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreatInDays", new { numberOfDays = daysUntilNextTreat }));
                 }
                 else if (daysUntilNextTreat == 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreatTomorrow"));
                 }
                 else
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreat"));
                 }
             }
         }
         if (this.animalContestIndicator != null)
         {
             if (this.animalContestIndicator.containsPoint(x, y))
             {
                 if (AnimalContestController.CanChangeParticipant(this._farmAnimal))
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ChangeParticipant"));
                 }
                 else if (AnimalContestController.HasParticipated(this._farmAnimal) && AnimalContestController.HasWon(this._farmAnimal))
                 {
                     SDate date = AnimalContestController.GetParticipantDate(this._farmAnimal);
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.Winner", new { contestDate = Utility.getDateStringFor(date.Day, Utility.getSeasonNumber(date.Season), date.Year) }));
                 }
                 else
                 {
                     SDate date = AnimalContestController.GetParticipantDate(this._farmAnimal);
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ContestParticipant", new { contestDate = Utility.getDateStringFor(date.Day, Utility.getSeasonNumber(date.Season), date.Year) }));
                 }
             }
         }
     }
 }
Beispiel #6
0
        public AnimalQueryMenuExtended(FarmAnimal farmAnimal) : base(farmAnimal)
        {
            _farmAnimal = farmAnimal;
            if (!DataLoader.ModConfig.DisablePregnancy)
            {
                if (PregnancyController.IsAnimalPregnant(this._farmAnimal))
                {
                    pregnantStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.pixelZoom * 3,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth + Game1.pixelZoom,
                            Game1.pixelZoom * 11, Game1.pixelZoom * 11), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(34, 29, 11, 11), 4f, false)
                    {
                        myID            = region_allowReproductionButton,
                        downNeighborID  = region_okButton,
                        upNeighborID    = region_sellButton,
                        rightNeighborID = region_treatStatus
                    };
                    this.okButton.upNeighborID     = region_allowReproductionButton;
                    this.sellButton.downNeighborID = region_allowReproductionButton;
                    if (Game1.options.SnappyMenus)
                    {
                        this.allClickableComponents.Remove(this.allowReproductionButton);
                        this.allClickableComponents.Add(pregnantStatus);
                    }
                    this.allowReproductionButton = null;
                }
            }

            if (!DataLoader.ModConfig.DisableTreats && TreatsController.CanReceiveTreat(farmAnimal))
            {
                if (TreatsController.IsReadyForTreat(farmAnimal))
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites,
                        new Microsoft.Xna.Framework.Rectangle(240, 0, 16, 16), 4f, false)
                    {
                        myID           = region_treatStatus,
                        leftNeighborID = region_allowReproductionButton
                    };
                }
                else
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(16, 28, 16, 16), 4f, false)
                    {
                        myID           = region_treatStatus,
                        leftNeighborID = region_allowReproductionButton
                    };
                }
                if (this.allowReproductionButton != null)
                {
                    this.allowReproductionButton.rightNeighborID = region_treatStatus;
                }
                if (Game1.options.SnappyMenus)
                {
                    this.allClickableComponents.Add(treatStatus);
                }
            }

            if (AnimalContestController.HasWon(farmAnimal))
            {
                animalContestIndicator = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 4 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites, new Microsoft.Xna.Framework.Rectangle(AnimalContestController.HasFertilityBonus(this._farmAnimal) ? 48 : 64, 29, 16, 15), 4f, false)
                {
                    myID           = region_animalConstestIndicator,
                    leftNeighborID = region_moveHomeButton
                };
                this.moveHomeButton.rightNeighborID = region_animalConstestIndicator;
                if (Game1.options.SnappyMenus)
                {
                    this.allClickableComponents.Add(animalContestIndicator);
                }
            }
            else if (farmAnimal.GetDayParticipatedContest() != null)
            {
                animalContestIndicator = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 4 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites, new Microsoft.Xna.Framework.Rectangle(256, 0, 16, 16), 4f, false)
                {
                    myID           = region_animalConstestIndicator,
                    leftNeighborID = region_moveHomeButton
                };
                this.moveHomeButton.rightNeighborID = region_animalConstestIndicator;
                if (Game1.options.SnappyMenus)
                {
                    this.allClickableComponents.Add(animalContestIndicator);
                }
            }

            if (!DataLoader.ModConfig.DisableMeat && MeatController.CanGetMeatFrom(farmAnimal))
            {
                if (!this._farmAnimal.isBaby())
                {
                    meatButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 3 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites, new Microsoft.Xna.Framework.Rectangle(0, 28, 16, 16), 4f, false)
                    {
                        myID           = region_meatButton,
                        leftNeighborID = region_sellButton
                    };
                }
                this.sellButton.rightNeighborID = region_meatButton;
                if (Game1.options.SnappyMenus)
                {
                    this.allClickableComponents.Add(meatButton);
                }
            }

            if (this.animalContestIndicator != null)
            {
                this.moveHomeButton.rightNeighborID = region_animalConstestIndicator;
                if (this.meatButton != null)
                {
                    this.meatButton.upNeighborID = region_animalConstestIndicator;
                    this.animalContestIndicator.downNeighborID = region_meatButton;
                }
                else if (this.treatStatus != null)
                {
                    this.treatStatus.upNeighborID = region_animalConstestIndicator;
                    this.animalContestIndicator.downNeighborID = region_treatStatus;
                }
            }

            if (this.meatButton != null)
            {
                this.sellButton.rightNeighborID = region_meatButton;
                if (this.treatStatus != null)
                {
                    this.treatStatus.upNeighborID  = region_meatButton;
                    this.meatButton.downNeighborID = region_treatStatus;
                }
            }

            if (this.treatStatus != null)
            {
                if (this.pregnantStatus == null && this.allowReproductionButton == null)
                {
                    this.treatStatus.downNeighborID = region_okButton;
                    if (this.meatButton == null && this.animalContestIndicator == null)
                    {
                        this.treatStatus.upNeighborID  = region_sellButton;
                        this.okButton.upNeighborID     = region_treatStatus;
                        this.sellButton.downNeighborID = region_treatStatus;
                    }
                }
            }

            _parentName     = DataLoader.Helper.Reflection.GetField <String>(this, "parentName").GetValue();
            _textBox        = DataLoader.Helper.Reflection.GetField <TextBox>(this, "textBox").GetValue();
            _movingAnimal   = DataLoader.Helper.Reflection.GetField <bool>(this, "movingAnimal");
            _confirmingSell = DataLoader.Helper.Reflection.GetField <bool>(this, "confirmingSell");
            _lovelLevel     = DataLoader.Helper.Reflection.GetField <double>(this, "loveLevel");
            _hoverText      = DataLoader.Helper.Reflection.GetField <string>(this, "hoverText");
        }