示例#1
0
        private void RenderingHud(object sender, RenderingHudEventArgs e)
        {
            if (CurrentHoveredBuilding != null && Game1.activeClickableMenu == null &&
                (Config.EnableDebugMode || Config.EnableHoverTip) && AnimalHouseBuildings.Any(
                    ab => CurrentHoveredBuilding.buildingType.Contains(ab) &&
                    CurrentHoveredBuilding.indoors.Value != null))
            {
                Translation tipText = I18N.Get("upgrade_tooltip_text", new
                {
                    current_building = CurrentHoveredBuilding.buildingType.Value,
                    max_animals      = ((AnimalHouse)CurrentHoveredBuilding.indoors.Value).animalLimit
                });
                IClickableMenu.drawHoverText(Game1.spriteBatch, tipText, Game1.smallFont);
            }

            if (CurrentHoveredBuilding != null)
            {
                int p = (CurrentHoveredBuilding.buildingType.Value.Contains("Deluxe Barn")
                    ? Config.MaxBarnPopulation
                    : Config.MaxCoopPopulation);
                AnimalHouse obj = CurrentHoveredBuilding.indoors.Value as AnimalHouse;
                if ((obj == null || obj.animalLimit.Value != p) &&
                    CurrentHoveredBuilding.buildingType.Value.Contains("Deluxe") &&
                    !CurrentHoveredBuilding.buildingType.Value.Contains("Cabin") &&
                    !CurrentHoveredBuilding.buildingType.Value.Contains("Silo") &&
                    !CurrentHoveredBuilding.buildingType.Value.Contains("Mill") &&
                    Game1.activeClickableMenu == null)
                {
                    Game1.mouseCursor = 4;
                }
            }
        }
示例#2
0
        private void DoFeeding(Farm loc)
        {
            if (loc == null)
            {
                return;
            }

            foreach (Building b2 in loc.buildings.Where(b =>
                                                        b.buildingType.Value.Contains("Deluxe Barn") || b.buildingType.Value.Contains("Deluxe Coop")))
            {
                AnimalHouse ah = b2.indoors.Value as AnimalHouse;
                if (ah == null)
                {
                    break;
                }

                foreach (KeyValuePair <long, FarmAnimal> a in ah.animals.Pairs)
                {
                    if (a.Value.fullness.Value != byte.MaxValue && Game1.getFarm().piecesOfHay.Value >= 1)
                    {
                        a.Value.fullness.Value         = byte.MaxValue;
                        a.Value.daysSinceLastFed.Value = 1;
                        Game1.getFarm().piecesOfHay.Value--;
                        if (Config.EnableDebugMode)
                        {
                            Monitor.Log($"Fed: {a.Value.Name}, new Fullness: {a.Value.fullness.Value}");
                        }
                    }
                }
            }
        }
示例#3
0
        public static void InterceptIncubatorEggs()
        {
            if (!Game1.IsMasterGame)
            {
                return;
            }

            foreach (GameLocation location in Game1.locations)
            {
                if (location is BuildableGameLocation buildableGameLocation)
                {
                    foreach (Building building in buildableGameLocation.buildings)
                    {
                        if (building is Coop coop)
                        {
                            AnimalHouse animalHouse = coop.indoors.Value as AnimalHouse;

                            // Seems that this is dead legacy code, we still keep it to support either way of hatching, in case future game code changes back to this.
                            if (animalHouse.incubatingEgg.Y == EasterEggItem.PARENT_SHEET_INDEX && animalHouse.incubatingEgg.X == 1)
                            {
                                animalHouse.incubatingEgg.X = 0;
                                animalHouse.incubatingEgg.Y = -1;
                                animalHouse.map.GetLayer("Front").Tiles[1, 2].TileIndex = 45;
                                long newId = ModEntry.GetMultiplayer().getNewID();
                                animalHouse.animals.Add(newId, new FarmAnimal("Rabbit", newId, coop.owner.Value));
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public static void CheckEggHatched(Farmer who, AnimalHouse animalHouse)
        {
            if (who != Game1.player)
            {
                return;
            }

            foreach (StardewValley.Object @object in animalHouse.objects.Values)
            {
                if (@object.bigCraftable.Value && @object.Name.Contains("Incubator") && @object.heldObject.Value != null && @object.heldObject.Value.ParentSheetIndex == EasterEggItem.PARENT_SHEET_INDEX && @object.MinutesUntilReady <= 0 && !animalHouse.isFull())
                {
                    @object.heldObject.Value = null;
                    @object.ParentSheetIndex = 101;

                    Game1.exitActiveMenu();
                    if (animalHouse.currentEvent != null)
                    {
                        animalHouse.currentEvent.CurrentCommand = animalHouse.currentEvent.eventCommands.Length - 1;
                        animalHouse.currentEvent = new Event("none/-1000 -1000/farmer 2 9 0/pause 750/end");
                    }

                    Game1.drawDialogueNoTyping(I18N.EasterEggHatchedMessage);
                    Game1.afterDialogues = new Game1.afterFadeFunction(() => {
                        Game1.activeClickableMenu = new NamingMenu(new NamingMenu.doneNamingBehavior((string name) => {
                            AddNewHatchedRabbit(who, animalHouse, name);
                        }), Game1.content.LoadString("Strings\\StringsFromCSFiles:Event.cs.1236"), null);
                    });
                }
            }
        }
示例#5
0
        protected override GameLocation getIndoors(string nameOfIndoorsWithoutUnique)
        {
            GameLocation indoors = new AnimalHouse("Maps\\" + nameOfIndoorsWithoutUnique, buildingType);

            indoors.IsFarm            = true;
            indoors.isStructure.Value = true;
            indoors.uniqueName.Value  = nameOfIndoorsWithoutUnique + StardewValley.Util.GuidHelper.NewGuid().ToString();
            if (!(nameOfIndoorsWithoutUnique == "Barn2"))
            {
                if (nameOfIndoorsWithoutUnique == "Barn3")
                {
                    (indoors as AnimalHouse).animalLimit.Value = 12;
                }
            }
            else
            {
                (indoors as AnimalHouse).animalLimit.Value = 8;
            }
            foreach (Warp warp in indoors.warps)
            {
                warp.TargetX = humanDoor.X + (int)tileX;
                warp.TargetY = humanDoor.Y + (int)tileY + 1;
            }
            if ((bool)animalDoorOpen)
            {
                yPositionOfAnimalDoor.Value = openAnimalDoorPosition;
            }
            return(indoors);
        }
示例#6
0
        public static void check(GameLocation loc)
        {
            checkNPCs(loc);

            if (loc is Farm)
            {
                Farm farm = loc as Farm;
                foreach (KeyValuePair <long, FarmAnimal> animal in farm.animals)
                {
                    checkAnimal(animal.Value);
                    if (checkMissing.Contains(animal.Key))
                    {
                        checkMissing.Remove(animal.Key);
                    }
                }
            }
            else if (loc is AnimalHouse)
            {
                AnimalHouse house = loc as AnimalHouse;
                foreach (KeyValuePair <long, FarmAnimal> animal in house.animals)
                {
                    checkAnimal(animal.Value);
                    if (checkMissing.Contains(animal.Key))
                    {
                        checkMissing.Remove(animal.Key);
                    }
                }
            }
        }
示例#7
0
        protected override GameLocation getIndoors(string nameOfIndoorsWithoutUnique)
        {
            GameLocation indoors = new AnimalHouse("Maps\\" + nameOfIndoorsWithoutUnique, buildingType);

            indoors.IsFarm            = true;
            indoors.isStructure.Value = true;
            indoors.uniqueName.Value  = nameOfIndoorsWithoutUnique + StardewValley.Util.GuidHelper.NewGuid().ToString();
            if (!(nameOfIndoorsWithoutUnique == "Coop2"))
            {
                if (nameOfIndoorsWithoutUnique == "Coop3")
                {
                    (indoors as AnimalHouse).animalLimit.Value = 12;
                }
            }
            else
            {
                (indoors as AnimalHouse).animalLimit.Value = 8;
            }
            foreach (Warp warp in indoors.warps)
            {
                warp.TargetX = humanDoor.X + (int)tileX;
                warp.TargetY = humanDoor.Y + (int)tileY + 1;
            }
            if ((bool)animalDoorOpen)
            {
                yPositionOfAnimalDoor.Value = openAnimalDoorPosition;
            }
            if ((indoors as AnimalHouse).incubatingEgg.Y > 0)
            {
                indoors.map.GetLayer("Front").Tiles[1, 2].TileIndex += ((Game1.player.ActiveObject.ParentSheetIndex != 180 && Game1.player.ActiveObject.ParentSheetIndex != 182) ? 1 : 2);
            }
            return(indoors);
        }
        /// <summary>Get the best target farm animal for a tool.</summary>
        /// <param name="tool">The tool to check.</param>
        /// <param name="location">The location to check.</param>
        /// <param name="tile">The tile to check.</param>
        /// <remarks>Derived from <see cref="Shears.beginUsing"/> and <see cref="Utility.GetBestHarvestableFarmAnimal"/>.</remarks>
        protected FarmAnimal GetBestHarvestableFarmAnimal(Tool tool, GameLocation location, Vector2 tile)
        {
            // get animals in the location
            IEnumerable <FarmAnimal> animals = location switch
            {
                Farm farm => farm.animals.Values,
                AnimalHouse house => house.animals.Values,
                                     _ => location.characters.OfType <FarmAnimal>()
            };

            // get best harvestable animal
            Vector2    useAt  = this.GetToolPixelPosition(tile);
            FarmAnimal animal = Utility.GetBestHarvestableFarmAnimal(
                animals: animals,
                tool: tool,
                toolRect: new Rectangle((int)useAt.X, (int)useAt.Y, Game1.tileSize, Game1.tileSize)
                );

            if (animal == null || animal.toolUsedForHarvest.Value != tool.BaseName || animal.currentProduce.Value <= 0 || animal.age.Value < animal.ageWhenMature.Value)
            {
                return(null);
            }

            return(animal);
        }
示例#9
0
        private void OnDayStarted(object sender, DayStartedEventArgs e)
        {
            GameLocation loc = Game1.getFarm();

            if (loc == null)
            {
                return;
            }
            IEnumerator <Building> enumerator = Game1.getFarm().buildings.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Building b = enumerator.Current;
                    if (b != null)
                    {
                        AnimalHouse bb = b.indoors.Value as AnimalHouse;
                        if (!Game1.isRaining && !Game1.isSnowing)
                        {
                            b.animalDoorOpen.Value = true;
                        }
                    }
                }
            }
            finally
            {
                enumerator.Dispose();
            }
        }
示例#10
0
        private void UpdateObjectInfoList(AnimalHouse animalHouse)
        {
            this.ObjectInfoList.RemoveAll(soi => soi.Location == animalHouse);
            foreach (KeyValuePair <Vector2, StardewValley.Object> o in animalHouse.Objects.Pairs)
            {
                if (o.Value.Name.Equals("Hay"))
                {
                    var soi = new StardewObjectInfo();
                    soi.Coordinate = o.Key * Game1.tileSize + new Vector2(Game1.tileSize / 2, Game1.tileSize / 2);
                    soi.Location   = animalHouse;
                }
            }

            var houseWidth  = animalHouse.map.Layers[0].LayerWidth;
            var houseHeight = animalHouse.map.Layers[0].LayerHeight;

            for (int tileX = 0; tileX < houseWidth; tileX++)
            {
                for (int tileY = 0; tileY < houseWidth; tileY++)
                {
                    bool tileIsTrough = animalHouse.doesTileHaveProperty(tileX, tileY, "Trough", "Back") != null;
                    if (tileIsTrough)
                    {
                        bool tileHasHay = animalHouse.Objects.ContainsKey(new Vector2(tileX, tileY));
                        var  soi        = new StardewObjectInfo();
                        soi.Coordinate = new Vector2((tileX + 0.5f) * Game1.tileSize, (tileY + 0.5f) * Game1.tileSize);
                        soi.Location   = animalHouse;
                        soi.NeedAction = !tileHasHay;
                        this.ObjectInfoList.Add(soi);
                    }
                }
            }
        }
示例#11
0
        /*********
        ** Private methods
        *********/

        /// <summary>
        /// Raised when the save is loaded.
        /// </summary>
        /// <param name="sender">object that sent the call.</param>
        /// <param name="e">the event data.</param>
        private void OnSaveLoad(object sender, SaveLoadedEventArgs e)
        {
            //load the current data from the information in memory.
            //the int[] stores 0 = standard produce, 1 = deluxe produce
            Dictionary <string, int[]> farmAnimalDataProduceTable = new Dictionary <string, int[]>();

            PopulateAnimalProduceDictionary(ref farmAnimalDataProduceTable);
            if (Game1.IsMasterGame)
            {
                //do nothing on non-main machines for now.
                Farm farm = Game1.getFarm();
                foreach (StardewValley.Buildings.Building thisBuilding in farm.buildings)
                {
                    this.Monitor.Log("Checking inside " + thisBuilding.nameOfIndoors);
                    if (thisBuilding.indoors.Value != null && (thisBuilding.buildingType.Contains("Barn") || thisBuilding.buildingType.Contains("Coop")))
                    {
                        //loop through the animals inside this building.
                        AnimalHouse thisInside = (AnimalHouse)thisBuilding.indoors.Value;
                        foreach (FarmAnimal thisAnimal in thisInside.animals.Values)
                        {
                            if (thisAnimal.defaultProduceIndex.Value != farmAnimalDataProduceTable[thisAnimal.type.Value][0] || thisAnimal.deluxeProduceIndex.Value != farmAnimalDataProduceTable[thisAnimal.type.Value][1])
                            {
                                //fix the standard item.
                                if (thisAnimal.defaultProduceIndex.Value != farmAnimalDataProduceTable[thisAnimal.type.Value][0])
                                {
                                    this.Monitor.Log(thisAnimal.Name + " the " + thisAnimal.type.Value + " producing: basic item " + thisAnimal.defaultProduceIndex.Value + " but should be producing basic item " + farmAnimalDataProduceTable[thisAnimal.type.Value][0].ToString() + ". Fixed.");
                                    if (thisAnimal.currentProduce == thisAnimal.defaultProduceIndex)
                                    {
                                        //update current product to the current defaultProduceIndex
                                        //Helper.Reflection.GetField<Netcode.NetInt>(thisAnimal, "currentProduce").SetValue(new Netcode.NetInt(farmAnimalDataProduceTable[thisAnimal.type.Value][0]));
                                        Helper.Reflection.GetField <Netcode.NetInt>(thisAnimal, "currentProduce").GetValue().Value = farmAnimalDataProduceTable[thisAnimal.type.Value][0];
                                    }
                                    //Helper.Reflection.GetField<Netcode.NetInt>(thisAnimal, "defaultProduceIndex").SetValue(new Netcode.NetInt(farmAnimalDataProduceTable[thisAnimal.type.Value][0]));
                                    Helper.Reflection.GetField <Netcode.NetInt>(thisAnimal, "defaultProduceIndex").GetValue().Value = farmAnimalDataProduceTable[thisAnimal.type.Value][0];
                                }

                                //fix the delux item.
                                if (thisAnimal.deluxeProduceIndex.Value != farmAnimalDataProduceTable[thisAnimal.type.Value][1])
                                {
                                    this.Monitor.Log(thisAnimal.Name + " the " + thisAnimal.type.Value + " producing deluxe item " + thisAnimal.deluxeProduceIndex.Value + " but should be producing deluxe item " + farmAnimalDataProduceTable[thisAnimal.type.Value][1].ToString() + ". Fixed.");
                                    if (thisAnimal.currentProduce == thisAnimal.deluxeProduceIndex)
                                    {
                                        //update current product to the current deluxeProduceIndex
                                        //Helper.Reflection.GetField<Netcode.NetInt>(thisAnimal, "currentProduce").SetValue(new Netcode.NetInt(farmAnimalDataProduceTable[thisAnimal.type.Value][1]));
                                        Helper.Reflection.GetField <Netcode.NetInt>(thisAnimal, "currentProduce").GetValue().Value = farmAnimalDataProduceTable[thisAnimal.type.Value][1];
                                    }
                                    //Helper.Reflection.GetField<Netcode.NetInt>(thisAnimal, "deluxeProduceIndex").SetValue(new Netcode.NetInt(farmAnimalDataProduceTable[thisAnimal.type.Value][1]));
                                    Helper.Reflection.GetField <Netcode.NetInt>(thisAnimal, "deluxeProduceIndex").GetValue().Value = farmAnimalDataProduceTable[thisAnimal.type.Value][1];
                                }
                            }
                            else
                            {
                                this.Monitor.Log("Checking an animal: " + thisAnimal.Name + " the " + thisAnimal.type.Value + " produces the correct items");
                            }
                        }
                    }
                }
                this.Monitor.Log("Done fixing animals that needed fixing");
            }
        }
示例#12
0
        public static void addAnimal(string loc, FarmAnimal animal)
        {
            Log.debug("DEBUG:Adding farm animal");
            AnimalHouse home = (AnimalHouse)Game1.getLocationFromName(loc);

            (home as AnimalHouse).animals.Add(animal.myID, animal);
            (home as AnimalHouse).animalsThatLiveHere.Add(animal.myID);

            if (!Multiplayer.COOP)
            {
                Log.warn("NOT IMPLEMENTED:ANIMAL ADDITION");
                return;
            }

            BuildableGameLocation farm = ( BuildableGameLocation )Game1.getLocationFromName("Farm");
            Building buildingAt        = null;

            foreach (Building building in farm.buildings)
            {
                if (building.tileX == animal.homeLocation.X && building.tileY == animal.homeLocation.Y)
                {
                    buildingAt = building;
                    break;
                }
            }
            if (buildingAt != null)
            {
                animal.home = buildingAt;
            }

            animals[animal.myID] = new FarmAnimalState(animal);
        }
示例#13
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            // Ignore if player hasn't loaded a save yet
            if (!Context.IsWorldReady)
            {
                return;
            }

            // We only care about action buttons
            if (!e.Button.IsActionButton())
            {
                return;
            }

            // We only care if the player is holding an object ...
            if (Game1.player.ActiveObject == null)
            {
                return;
            }

            // ... and that object is sort-of edible
            if (Game1.player.ActiveObject.Edibility <= CharacterTreat.INEDIBLE_THRESHOLD)
            {
                return;
            }

            //Vector2 index = new Vector2((float)((Game1.getOldMouseX() + Game1.viewport.X) / 64), (float)((Game1.getOldMouseY() + Game1.viewport.Y) / 64));
            Location tileLocation = new Location((int)e.Cursor.GrabTile.X, (int)e.Cursor.GrabTile.Y);

            Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(tileLocation.X * 64, tileLocation.Y * 64, 64, 64);

            bool intersected = false;

            if (Game1.player.currentLocation is AnimalHouse)
            {
                AnimalHouse animalHouse = Game1.player.currentLocation as AnimalHouse;

                intersected = this.AttemptToGiveTreatToFarmAnimals(animalHouse.animals, rectangle);
            }
            else if (Game1.player.currentLocation is Farm)
            {
                Farm farm = Game1.player.currentLocation as Farm;

                intersected = this.AttemptToGiveTreatToFarmAnimals(farm.animals, rectangle);
            }

            if (!intersected)
            {
                intersected = this.AttemptToGiveTreatToHorsesAndPets(rectangle);
            }

            // Always suppress the button if we intersected as an attempt to treat
            // Blocks weird behaviour of mounting if you meant to treat a horse that was already treated
            if (intersected)
            {
                this.Helper.Input.Suppress(e.Button);
            }
        }
 public static bool AnimalHouse_incubator_Prefix(AnimalHouse __instance)
 {
     if (__instance.incubatingEgg.Y <= 0 && Game1.player.ActiveObject != null && Game1.player.ActiveObject.name.Contains("Familiar Egg"))
     {
         Monitor.Log($"Tried adding familiar egg to incubator");
         return(false);
     }
     return(true);
 }
        public FarmAnimal RandomizeLocation(AnimalHouse animalHouse)
        {
            Building Building = animalHouse.getBuilding();

            this.home = Building;
            this.homeLocation.Set(new Vector2((float)Building.tileX, (float)Building.tileY));
            this.setRandomPosition(this.home.indoors);

            return(this);
        }
 /// <summary>
 ///     Checks whether there's an animal at the tile represented by this node.
 /// </summary>
 /// <returns>Returns true if there's an animal here. Returns false otherwise.</returns>
 public bool ContainsAnimal()
 {
     return(this.graph.GameLocation switch
     {
         AnimalHouse animalHouse => animalHouse.animals.Values.Any(
             animal => animal.getTileX() == this.X && animal.getTileY() == this.Y),
         Farm farm => farm.animals.Values.Any(
             animal => animal.getTileX() == this.X && animal.getTileY() == this.Y),
         _ => false
     });
示例#17
0
        public BarnMachine(Barn barn, GameLocation location) : base(barn, location, BaseMachine.GetTileAreaFor(barn))
        {
            if (barn.indoors.Value is AnimalHouse)
            {
                this.AnimalHouse = (AnimalHouse)barn.indoors.Value;
            }

            this.UnprocessedAnimals = new List <FarmAnimal>();
            this.FindUnprocessedAnimals();
        }
 public static FarmAnimal GetSelectedAnimal(this AnimalHouse house, Rectangle rectangle)
 {
     foreach (FarmAnimal farmAnimal in house.animals.Values)
     {
         if (farmAnimal.GetBoundingBox().Intersects(rectangle))
         {
             return(farmAnimal);
         }
     }
     return(null);
 }
示例#19
0
        //Private methods that's used by the Saved method
        private int AvailableSpace(Building building)
        {
            AnimalHouse animalHome     = building.indoors.Value as AnimalHouse;
            var         availableSpace = animalHome?.animalLimit.Value - animalHome?.animalsThatLiveHere.Count;

            if (availableSpace == null)
            {
                return(0);
            }
            return((int)availableSpace);
        }
示例#20
0
        public bool setUp()
        {
            int num = this.whichQuestion;

            if (num != 1)
            {
                if (num == 2)
                {
                    FarmAnimal farmAnimal = null;
                    foreach (Building current in Game1.getFarm().buildings)
                    {
                        if ((current.owner.Equals(Game1.uniqueIDForThisGame) || !Game1.IsMultiplayer) && current.buildingType.Contains("Barn") && !current.buildingType.Equals("Barn") && !(current.indoors as AnimalHouse).isFull() && Game1.random.NextDouble() < (double)(current.indoors as AnimalHouse).animalsThatLiveHere.Count * 0.0055)
                        {
                            farmAnimal       = Utility.getAnimal((current.indoors as AnimalHouse).animalsThatLiveHere[Game1.random.Next((current.indoors as AnimalHouse).animalsThatLiveHere.Count)]);
                            this.animalHouse = (current.indoors as AnimalHouse);
                            break;
                        }
                    }
                    if (farmAnimal != null && !farmAnimal.isBaby() && farmAnimal.allowReproduction)
                    {
                        Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\Events:AnimalBirth", new object[]
                        {
                            farmAnimal.displayName,
                            farmAnimal.shortDisplayType()
                        }));
                        Game1.messagePause = true;
                        this.animal        = farmAnimal;
                        return(false);
                    }
                }
                return(true);
            }
            Response[] answerChoices = new Response[]
            {
                new Response("Yes", Game1.content.LoadString("Strings\\Events:HaveBabyAnswer_Yes", new object[0])),
                new Response("Not", Game1.content.LoadString("Strings\\Events:HaveBabyAnswer_No", new object[0]))
            };
            if (!Game1.getCharacterFromName(Game1.player.spouse, false).isGaySpouse())
            {
                Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\Events:HaveBabyQuestion", new object[]
                {
                    Game1.player.name
                }), answerChoices, new GameLocation.afterQuestionBehavior(this.answerPregnancyQuestion), Game1.getCharacterFromName(Game1.player.spouse, false));
            }
            else
            {
                Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\Events:HaveBabyQuestion_Adoption", new object[]
                {
                    Game1.player.name
                }), answerChoices, new GameLocation.afterQuestionBehavior(this.answerPregnancyQuestion), Game1.getCharacterFromName(Game1.player.spouse, false));
            }
            Game1.messagePause = true;
            return(false);
        }
示例#21
0
        public Incubator(AnimalHouse animalHouse)
        {
            StardewValley.Object @object = this.FindInAnimalHouse(animalHouse);

            if (@object == null)
            {
                throw new ArgumentException("Could not find an incubator", "animalHouse");
            }

            this.Self        = @object;
            this.AnimalHouse = animalHouse;
        }
        public StardewValley.FarmAnimal AddToAnimalHouse(AnimalHouse animalHouse)
        {
            // !!! @WARNING
            // !!! We have to convert to a base Farm Animal due to exceptions
            // !!! thrown by the day's save XML functions
            StardewValley.FarmAnimal BaseFarmAnimal = this.ToFarmAnimal();

            animalHouse.animals.Add(BaseFarmAnimal.myID, BaseFarmAnimal);
            animalHouse.animalsThatLiveHere.Add(BaseFarmAnimal.myID);

            return(BaseFarmAnimal);
        }
示例#23
0
 public static bool ReturnHome(SDV.FarmAnimal animal)
 {
     if (!HasHome(animal))
     {
         return(false);
     }
     AnimalHouse.AddAnimal(animal.home, animal);
     SetRandomPositionInHome(animal);
     SetRandomFacingDirection(animal);
     animal.controller = null;
     return(true);
 }
示例#24
0
        public static bool CheckBuildingLimit(FarmAnimal animal)
        {
            AnimalHouse animalHouse = (AnimalHouse)animal.home.indoors.Value;

            int?limit = null;

            switch (animalHouse.Name)
            {
            case "Deluxe Barn":
            {
                limit = DataLoader.AnimalBuildingData.DeluxeBarnPregnancyLimit;
                break;
            }

            case "Big Barn":
            {
                limit = DataLoader.AnimalBuildingData.BigBarnPregnancyLimit;
                break;
            }

            case "Barn":
            {
                limit = DataLoader.AnimalBuildingData.BarnPregnancyLimit;
                break;
            }

            case "Deluxe Coop":
            {
                limit = DataLoader.AnimalBuildingData.DeluxeCoopPregnancyLimit;
                break;
            }

            case "Big Coop":
            {
                limit = DataLoader.AnimalBuildingData.BigCoopPregnancyLimit;
                break;
            }

            case "Coop":
            {
                limit = DataLoader.AnimalBuildingData.CoopPregnancyLimit;
                break;
            }

            default:
            {
                limit = null;
                break;
            }
            }
            return(limit != null && animalHouse.animalsThatLiveHere.Count(a => IsAnimalPregnant(Utility.getAnimal(a))) >= limit);
        }
示例#25
0
        private StardewValley.Object FindInAnimalHouse(AnimalHouse animalHouse)
        {
            // Try to get the reference for the incubator object
            foreach (StardewValley.Object @object in animalHouse.objects.Values)
            {
                if (@object.bigCraftable && @object.Name.Contains(Incubator.INCUBATOR) && @object.heldObject != null)
                {
                    return(@object);
                }
            }

            return(null);
        }
示例#26
0
        public static bool AnimalHouseToolAction(ref AnimalHouse __instance, ref Tool t, ref int tileX, ref int tileY)
        {
            try
            {
                return(HarmonyPatchExecutors.AnimalHouseToolActionExecutor(ref __instance, ref t, ref tileX, ref tileY));
            }
            catch (Exception e)
            {
                ModEntry.ModMonitor.Log($"Failed in { nameof(AnimalHouseToolAction) }:\n{ e }", LogLevel.Error);

                return(true);
            }
        }
示例#27
0
        private static void destroyAnimal(FarmAnimal animal)
        {
            AnimalHouse home = (AnimalHouse)animal.home.indoors;

            (home as AnimalHouse).animals.Remove(animal.myID);
            (home as AnimalHouse).animalsThatLiveHere.Remove(animal.myID);

            animals.Remove(animal.myID);
            if (checkMissing.Contains(animal.myID))
            {
                checkMissing.Remove(animal.myID);
            }
        }
示例#28
0
        public static FarmAnimal BirthAnimal(AnimalHouse animalHouseInstance, int eggID)
        {
            FarmAnimal farmAnimal = null;

            // ... then hatch egg before game can.
            long newId = smapiHelper.Multiplayer.GetNewID();

            if (ModEntry.IsCustomEgg(eggID))
            {
                string type = "White Chicken";
                if (!ModEntry.modEntry.modData.customEggsAndHatchedAnimals.ContainsKey(eggID))
                {
                    // Attempt to convert chicken eggs from old ID system
                    eggID = ModEntry.ConvertFromOldID(eggID);
                }
                if (ModEntry.modEntry.modData.customEggsAndHatchedAnimals.ContainsKey(eggID))
                {
                    type = eggsAndHatchedAnimals[eggID];
                    // Allow for variants
                    string[] splitType = type.Split(new string[] { ", " }, StringSplitOptions.None);
                    if (splitType.Length > 1)
                    {
                        type = splitType[ModEntry.modEntry.rand.Next(0, splitType.Length)];
                    }
                }

                farmAnimal = new FarmAnimal(type, newId, (long)Game1.player.uniqueMultiplayerID);
                if (ModEntry.modEntry.customChickenTextures.ContainsKey(type))
                {
                    farmAnimal.type.Value  = type;
                    farmAnimal.displayType = null;
                    farmAnimal.reloadData();
                    ModEntry.modEntry.ReplaceCustomAnimalSound(farmAnimal);
                }

                animalHouseInstance.incubatingEgg.X = 0;
                animalHouseInstance.incubatingEgg.Y = -1;

                animalHouseInstance.animals.Add(farmAnimal.myID, farmAnimal);
                animalHouseInstance.animalsThatLiveHere.Add((long)farmAnimal.myID);

                Building building = animalHouseInstance.getBuilding();
                if (building != null)
                {
                    farmAnimal.home = building;
                    farmAnimal.homeLocation.Value = new Vector2((float)(int)((NetFieldBase <int, NetInt>)building.tileX), (float)(int)((NetFieldBase <int, NetInt>)building.tileY));
                    farmAnimal.setRandomPosition((GameLocation)((NetFieldBase <GameLocation, NetRef <GameLocation> >)farmAnimal.home.indoors));
                }
            }
            return(farmAnimal);
        }
示例#29
0
        protected override GameLocation getIndoors()
        {
            if (this.indoors != null)
            {
                this.nameOfIndoorsWithoutUnique = this.indoors.name;
            }
            string nameOfIndoorsWithoutUnique = this.nameOfIndoorsWithoutUnique;

            if (!(nameOfIndoorsWithoutUnique == "Big Coop"))
            {
                if (nameOfIndoorsWithoutUnique == "Deluxe Coop")
                {
                    this.nameOfIndoorsWithoutUnique = "Coop3";
                }
            }
            else
            {
                this.nameOfIndoorsWithoutUnique = "Coop2";
            }
            GameLocation gameLocation = new AnimalHouse(Game1.game1.xTileContent.Load <Map>("Maps\\" + this.nameOfIndoorsWithoutUnique), this.buildingType);

            gameLocation.IsFarm        = true;
            gameLocation.isStructure   = true;
            nameOfIndoorsWithoutUnique = this.nameOfIndoorsWithoutUnique;
            if (!(nameOfIndoorsWithoutUnique == "Big Coop"))
            {
                if (nameOfIndoorsWithoutUnique == "Deluxe Coop")
                {
                    (gameLocation as AnimalHouse).animalLimit = 12;
                }
            }
            else
            {
                (gameLocation as AnimalHouse).animalLimit = 8;
            }
            foreach (Warp expr_E0 in gameLocation.warps)
            {
                expr_E0.TargetX = this.humanDoor.X + this.tileX;
                expr_E0.TargetY = this.humanDoor.Y + this.tileY + 1;
            }
            if (this.animalDoorOpen)
            {
                this.yPositionOfAnimalDoor = Coop.openAnimalDoorPosition;
            }
            if ((gameLocation as AnimalHouse).incubatingEgg.Y > 0)
            {
                gameLocation.map.GetLayer("Front").Tiles[1, 2].TileIndex += ((Game1.player.ActiveObject.ParentSheetIndex == 180 || Game1.player.ActiveObject.ParentSheetIndex == 182) ? 2 : 1);
            }
            return(gameLocation);
        }
示例#30
0
        public static bool CheckBuildingLimit(AnimalHouse animalHouse)
        {
            int?limit = null;

            switch (animalHouse.Name)
            {
            case "Deluxe Barn":
            {
                limit = DataLoader.AnimalBuildingData.DeluxeBarnPregnancyLimit;
                break;
            }

            case "Big Barn":
            {
                limit = DataLoader.AnimalBuildingData.BigBarnPregnancyLimit;
                break;
            }

            case "Barn":
            {
                limit = DataLoader.AnimalBuildingData.BarnPregnancyLimit;
                break;
            }

            case "Deluxe Coop":
            {
                limit = DataLoader.AnimalBuildingData.DeluxeCoopPregnancyLimit;
                break;
            }

            case "Big Coop":
            {
                limit = DataLoader.AnimalBuildingData.BigCoopPregnancyLimit;
                break;
            }

            case "Coop":
            {
                limit = DataLoader.AnimalBuildingData.CoopPregnancyLimit;
                break;
            }

            default:
            {
                limit = null;
                break;
            }
            }
            return(limit != null && animalHouse.animalsThatLiveHere.Count(a => IsAnimalPregnant(a)) >= limit);
        }