private void IterateOverAnimals() { SFarmer farmer = Game1.player; AnimalTasks stats = new AnimalTasks(); foreach (FarmAnimal animal in this.GetAnimals()) { try { if (!animal.wasPet.Value && this.PettingEnabled) { animal.pet(Game1.player); stats.AnimalsPet++; this.Monitor.Log($"Petting animal: {animal.Name}", LogLevel.Trace); } if (this.GrowUpEnabled && animal.isBaby()) { this.Monitor.Log($"Aging animal to mature+1 days: {animal.Name}", LogLevel.Trace); animal.age.Value = animal.ageWhenMature.Value + 1; animal.reload(animal.home); stats.Aged++; } if (this.MaxFullnessEnabled && animal.fullness.Value < byte.MaxValue) { this.Monitor.Log($"Feeding animal: {animal.Name}", LogLevel.Trace); animal.fullness.Value = byte.MaxValue; stats.Fed++; } if (this.MaxHappinessEnabled && animal.happiness.Value < byte.MaxValue) { this.Monitor.Log($"Maxing Happiness of animal {animal.Name}", LogLevel.Trace); animal.happiness.Value = byte.MaxValue; stats.MaxHappiness++; } if (this.MaxFriendshipEnabled && animal.friendshipTowardFarmer.Value < 1000) { this.Monitor.Log($"Maxing Friendship of animal {animal.Name}", LogLevel.Trace); animal.friendshipTowardFarmer.Value = 1000; stats.MaxFriendship++; } if (animal.currentProduce.Value > 0 && this.HarvestEnabled) { this.Monitor.Log($"Has produce: {animal.Name} {animal.currentProduce}", LogLevel.Trace); if (animal.type.Value == "Pig") { if (this.TakeTrufflesFromPigs) { Object toAdd = new Object(animal.currentProduce.Value, 1, false, -1, animal.produceQuality.Value); this.AddItemToInventory(toAdd, farmer); animal.currentProduce.Value = 0; stats.TrufflesHarvested++; } } else { Object toAdd = new Object(animal.currentProduce.Value, 1, false, -1, animal.produceQuality.Value); this.AddItemToInventory(toAdd, farmer); animal.currentProduce.Value = 0; stats.ProductsHarvested++; } } } catch (Exception ex) { this.Monitor.Log($"Exception onKeyReleased: {ex}", LogLevel.Error); } } this.HarvestTruffles(stats); this.HarvestCoops(stats); int actions = stats.GetTaskCount(); bool gatheringOnly = stats.JustGathering(); if (actions > 0 && this.CostPerAnimal > 0) { int totalCost = actions * this.CostPerAnimal; bool doesPlayerHaveEnoughCash = Game1.player.Money >= totalCost; Game1.player.Money = Math.Max(0, Game1.player.Money - totalCost); if (this.MessagesEnabled) { this.ShowMessage(actions, totalCost, doesPlayerHaveEnoughCash, gatheringOnly, stats); } this.Monitor.Log($"Animal sitter performed {actions} actions. Total cost: {totalCost}g", LogLevel.Trace); } else if (actions == 0 && this.CostPerAnimal > 0) { if (this.MessagesEnabled) { HUDMessage msg = new HUDMessage("There's nothing to do for the animals right now."); Game1.addHUDMessage(msg); } this.Monitor.Log("There's nothing to do for the animals right now.", LogLevel.Trace); } }