private void HarvestTruffles(AnimalTasks stats) { Farm farm = Game1.getFarm(); SFarmer farmer = Game1.player; List <Vector2> itemsToRemove = new List <Vector2>(); // Iterate over the objects, and add them to inventory. foreach (KeyValuePair <Vector2, Object> keyvalue in farm.Objects.Pairs) { Object obj = keyvalue.Value; if (obj.Name == "Truffle") { bool doubleHarvest = false; if (Game1.player.professions.Contains(16)) { obj.Quality = 4; } double randomNum = Game1.random.NextDouble(); bool doubleChance = (this.Checker.Equals("pet")) ? (randomNum < 0.4) : (randomNum < 0.2); if (Game1.player.professions.Contains(13) && doubleChance) { obj.Stack = 2; doubleHarvest = true; } if (this.AddItemToInventory(obj, farmer)) { itemsToRemove.Add(keyvalue.Key); farmer.gainExperience(2, 7); stats.TrufflesHarvested++; if (doubleHarvest) { stats.TrufflesHarvested++; farmer.gainExperience(2, 7); } } else { this.Monitor.Log("Inventory full, could not add animal product.", LogLevel.Trace); } } } // Now remove the items foreach (Vector2 itemLocation in itemsToRemove) { farm.removeObject(itemLocation, false); } }
private void HarvestCoops(AnimalTasks stats) { Farm farm = Game1.getFarm(); SFarmer farmer = Game1.player; foreach (Building building in farm.buildings) { if (building is Coop) { List <Vector2> itemsToRemove = new List <Vector2>(); foreach (KeyValuePair <Vector2, Object> keyvalue in building.indoors.Value.Objects.Pairs) { Object obj = keyvalue.Value; this.Monitor.Log($"Found coop object: {obj.Name} / {obj.Category}/{obj.isAnimalProduct()}", LogLevel.Trace); if (obj.isAnimalProduct() || obj.ParentSheetIndex == 107) { if (this.AddItemToInventory(obj, farmer)) { itemsToRemove.Add(keyvalue.Key); stats.ProductsHarvested++; farmer.gainExperience(0, 5); } else { this.Monitor.Log("Inventory full, could not add animal product.", LogLevel.Trace); } } } // Remove the object that were picked up. foreach (Vector2 itemLocation in itemsToRemove) { building.indoors.Value.removeObject(itemLocation, false); } } } }
private void ShowMessage(int numActions, int totalCost, bool doesPlayerHaveEnoughCash, bool gatheringOnly, AnimalTasks stats) { stats.NumActions = numActions; stats.TotalCost = totalCost; string message = ""; if (this.Checker.ToLower() == "pet") { if (Game1.player.hasPet()) { if (Game1.player.catPerson) { message += "Meow.."; } else { message += "Woof."; } } else { message += "Your imaginary pet has taken care of your animals."; } HUDMessage msg = new HUDMessage(message); Game1.addHUDMessage(msg); } else { if (this.Checker.ToLower() == "spouse") { if (Game1.player.isMarried()) { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(1, "Xdialog"), stats, this.Config); } else { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(2, "Xdialog"), stats, this.Config); } if (totalCost > 0 && this.CostPerAnimal > 0) { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(3, "Xdialog"), stats, this.Config); } HUDMessage msg = new HUDMessage(message); Game1.addHUDMessage(msg); } else if (gatheringOnly) { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(4, "Xdialog"), stats, this.Config); if (totalCost > 0 && this.CostPerAnimal > 0) { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(3, "Xdialog"), stats, this.Config); } HUDMessage msg = new HUDMessage(message); Game1.addHUDMessage(msg); } else { NPC character = Game1.getCharacterFromName(this.Checker); if (character != null) { //this.isCheckerCharacter = true; string portrait = ""; if (character.Name.Equals("Shane")) { portrait = "$8"; } message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetRandomMessage("greeting"), stats, this.Config); message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(5, "Xdialog"), stats, this.Config); if (this.CostPerAnimal > 0) { if (doesPlayerHaveEnoughCash) { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(6, "Xdialog"), stats, this.Config); } else { message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetRandomMessage("unfinishedmoney"), stats, this.Config); } } else { //message += portrait + "#$e#"; } message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetRandomMessage("smalltalk"), stats, this.Config); message += portrait + "#$e#"; character.CurrentDialogue.Push(new Dialogue(message, character)); Game1.drawDialogue(character); } else { //message += checker + " has performed " + numActions + " for your animals."; message += this.DialogueManager.PerformReplacement(this.DialogueManager.GetMessageAt(7, "Xdialog"), stats, this.Config); HUDMessage msg = new HUDMessage(message); Game1.addHUDMessage(msg); } } } }
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); } }