private static void HandleFindProduce(ref Decorators.FarmAnimal moddedAnimal, ref Location moddedLocation)
        {
            var moddedPlayer = new Farmer(Game.GetPlayer());

            if (!IsValidLocation(moddedLocation) || !CanFindProduce(moddedAnimal, moddedPlayer) ||
                Random.NextDouble() >= 0.0002 || !HasNoImpediments(moddedAnimal, moddedLocation))
            {
                return;
            }
            if (moddedPlayer.IsCurrentLocation(moddedLocation.GetOriginal()))
            {
                BellsAndWhistles.PlaySound("dirtyHit", 450);
                BellsAndWhistles.PlaySound("dirtyHit", 900);
                BellsAndWhistles.PlaySound("dirtyHit", 1350);
            }

            if (Game.IsCurrentLocation(moddedLocation.GetOriginal()))
            {
                moddedAnimal.AnimateFindingProduce();
            }
            else
            {
                moddedAnimal.FindProduce(moddedPlayer.GetOriginal());
            }
        }
Exemple #2
0
 private static bool ShouldStopFindingProduce(ref Decorators.FarmAnimal moddedAnimal)
 {
     return(Random.Seed((int)(moddedAnimal.GetUniqueId() / 2L +
                              Game.GetDaysPlayed() +
                              Game.GetTimeOfDay())).NextDouble() >
            moddedAnimal.GetFriendship() / 1500.0);
 }
Exemple #3
0
        public static bool Prefix(ref StardewValley.FarmAnimal __instance, ref Farmer who)
        {
            var moddedAnimal = new Decorators.FarmAnimal(__instance);

            AttemptToSpawnProduce(ref moddedAnimal, Game.GetMasterPlayer());
            if (ShouldStopFindingProduce(ref moddedAnimal))
            {
                moddedAnimal.SetCurrentProduce(-1);
            }
            return(false);
        }
        public static bool Prefix(
            ref StardewValley.Menus.PurchaseAnimalsMenu __instance,
            ref int x,
            ref int y,
            ref bool playSound)
        {
            var moddedMenu = new Decorators.PurchaseAnimalsMenu(__instance);

            if (!IsActionable(moddedMenu) || IsClosingMenu(moddedMenu, x, y))
            {
                return(true);
            }
            var moddedPlayer = new Farmer(Game.GetPlayer());

            return(moddedMenu.IsOnFarm()
        ? HandleOnFarm(ref moddedMenu, x, y, moddedPlayer)
        : HandleStockSelection(ref moddedMenu, x, y, moddedPlayer));
        }
Exemple #5
0
        private static bool AttemptToSpawnProduce(ref Decorators.FarmAnimal moddedAnimal, Farmer who)
        {
            var translatedVector2 =
                StardewValley.Utility.getTranslatedVector2(moddedAnimal.GetTileLocation(), moddedAnimal.GetFacingDirection(),
                                                           1f);
            var currentProduce = moddedAnimal.GetCurrentProduce();

            if (!Paritee.StardewValley.Core.Characters.FarmAnimal.IsProduceAnItem(currentProduce))
            {
                return(false);
            }
            var @object = new StardewValley.Object(Vector2.Zero, currentProduce, null, false, true, false, true)
            {
                Quality = moddedAnimal.GetProduceQuality()
            };

            Location.SpawnObject(Game.GetFarm(), translatedVector2, @object);
            return(true);
        }
Exemple #6
0
        public static SDV.FarmAnimal CreateFarmAnimal(
            string type,
            long ownerId,
            string name   = null,
            Building home = null,
            long myId     = 0)
        {
            if (myId == 0L)
            {
                myId = Game.GetNewId();
            }
            var farmAnimal = new SDV.FarmAnimal(type, myId, ownerId)
            {
                Name        = name,
                displayName = name,
                home        = home
            };
            var animal = farmAnimal;

            UpdateFromData(animal, type);
            return(animal);
        }
        private static bool HandleOnFarm(
            ref Decorators.PurchaseAnimalsMenu moddedMenu,
            int x,
            int y,
            Farmer moddedPlayer)
        {
            if (moddedMenu.IsNamingAnimal())
            {
                return(true);
            }
            var viewport   = Game.GetViewport();
            var buildingAt = Game.GetFarm().getBuildingAt(new Vector2((x + viewport.X) / 64, (y + viewport.Y) / 64));

            if (buildingAt == null)
            {
                return(true);
            }
            var animalBeingPurchased = moddedMenu.GetAnimalBeingPurchased();
            var moddedAnimal         = new Decorators.FarmAnimal(animalBeingPurchased);

            if (!moddedAnimal.CanLiveIn(buildingAt) || new Building(buildingAt).IsFull() || !moddedAnimal.CanBeNamed())
            {
                return(true);
            }
            var priceOfAnimal = moddedMenu.GetPriceOfAnimal();

            if (!moddedPlayer.CanAfford(priceOfAnimal))
            {
                return(true);
            }
            moddedAnimal.AddToBuilding(buildingAt);
            moddedMenu.SetAnimalBeingPurchased(animalBeingPurchased);
            moddedMenu.SetNewAnimalHome(null);
            moddedMenu.SetNamingAnimal(false);
            moddedPlayer.SpendMoney(priceOfAnimal);
            PurchasedAnimalBellsAndWhistles(moddedAnimal);
            return(false);
        }
        private static bool HandleNightTimeRoutine(
            ref Decorators.FarmAnimal moddedAnimal,
            ref Location moddedLocation)
        {
            if (Game.GetTimeOfDay() < 1700 || !moddedLocation.IsOutdoors() || moddedAnimal.HasController() ||
                Random.NextDouble() >= 0.002)
            {
                return(false);
            }
            if (moddedLocation.AnyFarmers())
            {
                moddedLocation.RemoveAnimal(moddedAnimal.GetOriginal());
                moddedAnimal.ReturnHome();
                return(true);
            }

            if (Paritee.StardewValley.Core.Characters.FarmAnimal.UnderMaxPathFindingPerTick())
            {
                Paritee.StardewValley.Core.Characters.FarmAnimal.IncreasePathFindingThisTick();
                moddedAnimal.SetFindHomeDoorPathController(moddedLocation.GetOriginal());
            }

            return(false);
        }