Exemplo n.º 1
0
        public static bool Prefix(ref StardewValley.Menus.PurchaseAnimalsMenu __instance, ref SpriteBatch b)
        {
            var purchaseAnimalsMenu = new Decorators.PurchaseAnimalsMenu(__instance);
            var farmAnimal          = new Decorators.FarmAnimal(purchaseAnimalsMenu.GetAnimalBeingPurchased());

            if (!BellsAndWhistles.IsFaded() && purchaseAnimalsMenu.IsOnFarm())
            {
                var str = Content.FormatMoneyString(farmAnimal.GetPrice());
                var x   = Game.GetViewport().Width / 2 - Content.GetWidthOfString(str) / 2;
                var y   = (int)(18.0 * SpriteText.fontPixelZoom * 2.0);
                BellsAndWhistles.DrawScroll(b, str, x, y);
            }

            return(true);
        }
        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);
        }