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); }
public static List<Item> CreateMeat(FarmAnimal farmAnimal) { List<Item> itemsToReturn = new List<Item>(); Animal animal; Animal? foundAnimal = AnimalExtension.GetAnimalFromType(farmAnimal.type.Value); if (foundAnimal == null || !CanGetMeatFrom(farmAnimal)) { return itemsToReturn; } else { animal = (Animal)foundAnimal; } AnimalItem animalItem = DataLoader.AnimalData.GetAnimalItem(farmAnimal); int minimumNumberOfMeat; int maxNumberOfMeat; int meatPrice; int debrisType; if (animal == Animal.Dinosaur) { if (DataLoader.ModConfig.DisableMeatFromDinosaur) { return itemsToReturn; } var meats = Enum.GetValues(typeof(Meat)); Meat meat = ((Meat)meats.GetValue(new Random((int)farmAnimal.myID.Value).Next(meats.Length))); meatPrice = DataLoader.MeatData.getMeatItem(meat).Price; minimumNumberOfMeat = 1; maxNumberOfMeat = 1 + (1300 / meatPrice); debrisType = (int)meat; } else if (animal == Animal.CustomAnimal) { MeatAnimalItem meatAnimalItem = (MeatAnimalItem) animalItem; debrisType = farmAnimal.meatIndex.Value; if (Enum.IsDefined(typeof(Meat), debrisType)) { meatPrice = DataLoader.MeatData.getMeatItem((Meat)debrisType).Price; } else { var objects = DataLoader.Helper.Content.Load<Dictionary<int, string>>("Data\\ObjectInformation", ContentSource.GameContent); meatPrice = Convert.ToInt32(objects[debrisType].Split('/')[1]); } minimumNumberOfMeat = meatAnimalItem.MinimalNumberOfMeat; maxNumberOfMeat = meatAnimalItem.MaximumNumberOfMeat; } else { MeatAnimalItem meatAnimalItem = (MeatAnimalItem) animalItem; Meat meat = animal.GetMeat(); meatPrice = DataLoader.MeatData.getMeatItem(meat).Price; minimumNumberOfMeat = meatAnimalItem.MinimalNumberOfMeat; maxNumberOfMeat = meatAnimalItem.MaximumNumberOfMeat; debrisType = (int)meat; } var numberOfMeat = minimumNumberOfMeat; numberOfMeat += (int)((farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (maxNumberOfMeat - minimumNumberOfMeat)); Random random = new Random((int)farmAnimal.myID.Value * 10000 + (int)Game1.stats.DaysPlayed); int[] quality = { 0, 0, 0, 0, 0 }; for (int i = 0; i < numberOfMeat; i++) { var produceQuality = ProduceQuality(random, farmAnimal); quality[produceQuality]++; } var tempTotal = meatPrice * quality[0] + meatPrice * quality[1] * 1.25 + meatPrice * quality[2] * 1.5 + meatPrice * quality[4] * 2; while (tempTotal < farmAnimal.getSellPrice() && quality[4] != numberOfMeat) { if (numberOfMeat < maxNumberOfMeat) { numberOfMeat++; quality[0]++; tempTotal += meatPrice; } else if (quality[0] > 0) { quality[0]--; quality[1]++; tempTotal += meatPrice * 0.25; } else if ((quality[1] > 0)) { quality[1]--; quality[2]++; tempTotal += meatPrice * 0.25; } else if ((quality[2] > 0)) { quality[2]--; quality[4]++; tempTotal += meatPrice * 0.50; } } for (; numberOfMeat > 0; --numberOfMeat) { Object newItem = new Object(Vector2.Zero, debrisType, 1); newItem.Quality = quality[4] > 0 ? 4 : quality[2] > 0 ? 2 : quality[1] > 0 ? 1 : 0; quality[newItem.Quality]--; itemsToReturn.Add(newItem); } if (animalItem is WoolAnimalItem woolAnimalItem) { int numberOfWools = farmAnimal.currentProduce.Value > 0 ? 1 : 0; numberOfWools += (int)(woolAnimalItem.MinimumNumberOfExtraWool + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (woolAnimalItem.MaximumNumberOfExtraWool - woolAnimalItem.MinimumNumberOfExtraWool)); for (; numberOfWools > 0; --numberOfWools) { Object newItem = new Object(Vector2.Zero, farmAnimal.defaultProduceIndex.Value, 1); newItem.Quality = ProduceQuality(random, farmAnimal); itemsToReturn.Add(newItem); } } if (animalItem is FeatherAnimalItem featherAnimalItem) { int numberOfFeather = (int)(featherAnimalItem.MinimumNumberOfFeatherChances + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (featherAnimalItem.MaximumNumberOfFeatherChances - featherAnimalItem.MinimumNumberOfFeatherChances)); float num1 = (int)farmAnimal.happiness.Value > 200 ? (float)farmAnimal.happiness.Value * 1.5f : ((int)farmAnimal.happiness.Value <= 100 ? (float)((int)farmAnimal.happiness.Value - 100) : 0.0f); for (; numberOfFeather > 0; --numberOfFeather) { if (random.NextDouble() < (double)farmAnimal.happiness.Value / 150.0) { if (random.NextDouble() < ((double)farmAnimal.friendshipTowardFarmer.Value + (double)num1) / 5000.0 + Game1.player.DailyLuck + (double)Game1.player.LuckLevel * 0.01) { Object newItem = new Object(Vector2.Zero, farmAnimal.deluxeProduceIndex.Value, 1); newItem.Quality = ProduceQuality(random, farmAnimal); itemsToReturn.Add(newItem); } } } } if (animalItem is FeetAnimalItem feetAnimalItem) { int numberOfFeet = (int)(feetAnimalItem.MinimumNumberOfFeetChances + (farmAnimal.getSellPrice() / ((double)farmAnimal.price.Value) - 0.3) * (feetAnimalItem.MaximumNumberOfFeetChances - feetAnimalItem.MinimumNumberOfFeetChances)); float num1 = (int)farmAnimal.happiness.Value > 200 ? (float)farmAnimal.happiness.Value * 1.5f : ((int)farmAnimal.happiness.Value <= 100 ? (float)((int)farmAnimal.happiness.Value - 100) : 0.0f); for (; numberOfFeet > 0; --numberOfFeet) { if (random.NextDouble() < (double)farmAnimal.happiness.Value / 150.0) { if (random.NextDouble() < ((double)farmAnimal.friendshipTowardFarmer.Value + (double)num1) / 5000.0 + Game1.player.DailyLuck + (double)Game1.player.LuckLevel * 0.01) { Object newItem = new Object(Vector2.Zero, farmAnimal.deluxeProduceIndex.Value, 1); newItem.Quality = ProduceQuality(random, farmAnimal); itemsToReturn.Add(newItem); } } } } if (AnimalContestController.CanChangeParticipant(farmAnimal)) { AnimalContestController.RemoveAnimalParticipant(farmAnimal); itemsToReturn.Add(ToolsFactory.GetParticipantRibbon()); } return itemsToReturn; }
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) })); } } } } }
public static bool checkAction(Pet __instance, Farmer who) { if (__instance.IsInvisible) { return(false); } if (!__instance.lastPetDay.ContainsKey(who.UniqueMultiplayerID)) { __instance.lastPetDay.Add(who.UniqueMultiplayerID, -1); } if (__instance.lastPetDay[who.UniqueMultiplayerID] == Game1.Date.TotalDays && AnimalContestController.CanChangeParticipant(__instance)) { __instance.playContentSound(); __instance.Halt(); __instance.CurrentBehavior = 0; __instance.OnNewBehavior(); __instance.Halt(); __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>() { new FarmerSprite.AnimationFrame(18, 200) }); who.Halt(); int currentFrame = who.FarmerSprite.currentFrame; switch (who.FacingDirection) { case 0: who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] { new FarmerSprite.AnimationFrame(62, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true) }); break; case 1: who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] { new FarmerSprite.AnimationFrame(58, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true) }); break; case 2: who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] { new FarmerSprite.AnimationFrame(54, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true) }); break; case 3: who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] { new FarmerSprite.AnimationFrame(58, 200, false, true, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true) }); break; } who.FarmerSprite.oldFrame = currentFrame; AnimalContestController.RemoveAnimalParticipant(__instance); Game1.player.addItemByMenuIfNecessary(ToolsFactory.GetParticipantRibbon()); return(false); } return(true); }