// Check if the player just pet his ... pet and apply buff private void ButtonReleased(object sender, ButtonReleasedEventArgs e) { if (Context.IsWorldReady && e.Button.IsActionButton() && !buffApplied) { //this.Monitor.Log(Game1.player.currentLocation.uniqueName); // Find the player's pet if (Game1.player.hasPet()) { StardewValley.Characters.Pet thePet = (StardewValley.Characters.Pet)Game1.getCharacterFromName(Game1.player.getPetName()); // Was it pet today (ie. just now)? If so, apply the buff if (this.Helper.Reflection.GetField <bool>(thePet, "wasPetToday").GetValue()) { if (Game1.player.catPerson) { fishBuff.millisecondsDuration = buffDuration; Game1.buffsDisplay.addOtherBuff(fishBuff); } else { forageBuff.millisecondsDuration = buffDuration; Game1.buffsDisplay.addOtherBuff(forageBuff); } buffApplied = true; } } } }
// Check if the player just pet his ... pet and apply buff private void ButtonReleased(object sender, ButtonReleasedEventArgs e) { if (Context.IsWorldReady && e.Button.IsActionButton() && !buffApplied) { //this.Monitor.Log(Game1.player.currentLocation.uniqueName); // Find the player's pet if (Game1.player.hasPet()) { Farmer farmer = Game1.player; StardewValley.Characters.Pet thePet = farmer.getPet(); // Was it pet today (ie. just now)? If so, apply the buff if (thePet.lastPetDay.ContainsKey(farmer.uniqueMultiplayerID) && thePet.lastPetDay[farmer.uniqueMultiplayerID] == Game1.Date.TotalDays) { if (Game1.player.catPerson) { fishBuff.millisecondsDuration = buffDuration; Game1.buffsDisplay.addOtherBuff(fishBuff); } else { forageBuff.millisecondsDuration = buffDuration; Game1.buffsDisplay.addOtherBuff(forageBuff); } buffApplied = true; } } } }
private void DogSpawn(StardewValley.Characters.Pet thePet = null, NPC theNPC = null) { // Spawn gift // Remove old gift if there's still one on the floor OverlaidDictionary obs = Game1.getLocationFromName("Farm").Objects; Vector2 spawnPos = new Vector2(tile.X, tile.Y); for (int i = 0; i < obs.Count(); i++) { Vector2 currentPos = obs.Keys.ElementAt(i); if (currentPos == spawnPos) { obs.Remove(obs.Keys.ElementAt(i)); } } Game1.getLocationFromName("Farm").dropObject(new StardewValley.Object(giftId, 1, false, -1, 0), spawnPos * 64f, Game1.viewport, true, (Farmer)null); //this.Monitor.Log("Object dropped!"); // Convert drop location to dirt (if we would do this beforehand, spawn would be impeded) Game1.getLocationFromName("Farm").terrainFeatures[tile] = new HoeDirt(); // Warp dog Vector2 warpPos = this.FindSafePosition(tile); // If we find a safe location near the treasure, warp the pet if (warpPos != tile) { if (theNPC == null) { thePet.Position = warpPos * 64f; } else if (thePet == null) { theNPC.Position = warpPos * 64f; } } this.Monitor.Log("Warped him ... most likely, to " + warpPos.X + "/" + warpPos.Y); warpedToday = true; Game1.playSound("dog_bark"); }
// Check if the player gets a gift public void AfterDayStarted(object sender, EventArgs e) { bool hasCat = false; bool hasDog = false; StardewValley.Characters.Pet theCat = null; StardewValley.Characters.Pet theDog = null; warpedToday = false; GameLocation theFarm = Game1.getLocationFromName("Farm"); tile = theFarm.getRandomTile(); // Find a free tile to generate dirt while (!theFarm.isTileLocationTotallyClearAndPlaceable(tile)) { //this.Monitor.Log("Searching for a clear tile..."); tile = theFarm.getRandomTile(); //this.Monitor.Log("Checking tile " + tile.X + "/" + tile.Y + " ..."); } // Look for a cat or a dog foreach (NPC pet in Game1.getLocationFromName("Farm").getCharacters()) { if (pet is StardewValley.Characters.Cat) { //this.Monitor.Log("Player has a cat (on farm)."); hasCat = true; theCat = (StardewValley.Characters.Pet)pet; } if (pet is StardewValley.Characters.Dog) { //this.Monitor.Log("Player has a dog (on farm)."); hasDog = true; theDog = (StardewValley.Characters.Pet)pet; } } foreach (NPC pet in Game1.getLocationFromName("FarmHouse").getCharacters()) { if (pet is StardewValley.Characters.Cat) { //this.Monitor.Log("Player has a cat (in house)."); hasCat = true; theCat = (StardewValley.Characters.Pet)pet; } if (pet is StardewValley.Characters.Dog) { //this.Monitor.Log("Player has a dog (in house)."); hasDog = true; theDog = (StardewValley.Characters.Pet)pet; } } if (hasCat) { // Determine gift chance int giftChance = 0; if (theCat.friendshipTowardFarmer.Value < THRESHOLD_1) { giftChance = GIFT_CHANCE_1; } else if (theCat.friendshipTowardFarmer.Value >= THRESHOLD_1 && theCat.friendshipTowardFarmer.Value < THRESHOLD_2) { giftChance = GIFT_CHANCE_2; } else if (theCat.friendshipTowardFarmer.Value >= THRESHOLD_2 && theCat.friendshipTowardFarmer.Value <= THRESHOLD_3) { giftChance = GIFT_CHANCE_3; } // if the player is a farmhand, relationship with the cat is broken. Use predetermined chance for farmhands if (!Game1.player.IsMainPlayer) { //this.Monitor.Log("Player is a farmhand."); giftChance = FARMHAND_CHANCE; } // Reset gifts given counter, max gifts per week -> 3 if (Game1.dayOfMonth % 7 == 0) { giftsGiven = 0; } giftToday = false; giftId = 0; //this.Monitor.Log("Did the cat give a gift?\nFriendship: " + catFriendship + "\nGift chance: " + giftChance + "\nGifts received this week: " + giftsGiven); // Draw a random gift ID. For clarity we do this in multiple steps // Step 1: Determine if cat gives a gift at all int random = Game1.random.Next(0, 100); //this.Monitor.Log("Random number: " + random + " --- must be larger than " + (100 - giftChance)); if (random > (100 - giftChance) && !Game1.isRaining && giftsGiven <= MAX_WEEKLY_GIFTS) { //this.Monitor.Log("Cat will give a gift ... maybe :3 (may still not happen if this is the second consecutive high tier gift)"); // Step 2: Determine quality: low = mid > high -> 40% / 40% / 20% int rand = Game1.random.Next(0, 100); // Pick a random item if (rand <= LOW_CHANCE) { //this.Monitor.Log("Low quality"); giftId = lowGifts.ElementAt(Game1.random.Next(lowGifts.Count - 1)); highTierYesterday = false; } else if (rand > LOW_CHANCE && rand <= (LOW_CHANCE + MID_CHANCE)) { //this.Monitor.Log("Medium quality"); giftId = midGifts.ElementAt(Game1.random.Next(midGifts.Count - 1)); highTierYesterday = false; } else if (rand > (100 - HI_CHANCE) && !highTierYesterday) { //this.Monitor.Log("High quality! :3"); giftId = hiGifts.ElementAt(Game1.random.Next(hiGifts.Count - 1)); highTierYesterday = true; } giftsGiven++; giftToday = true; } //else //this.Monitor.Log("No gift for you. You come back 10 years."); } else if (hasDog) { //this.Monitor.Log("Found a clear tile at " + tile.X + "/" + tile.Y); // Spawn gift at its location // Determine gift chance int giftChance = 0; if (theDog.friendshipTowardFarmer.Value < THRESHOLD_1) { giftChance = GIFT_CHANCE_1; } else if (theDog.friendshipTowardFarmer.Value >= THRESHOLD_1 && theDog.friendshipTowardFarmer.Value < THRESHOLD_2) { giftChance = GIFT_CHANCE_2; } else if (theDog.friendshipTowardFarmer.Value >= THRESHOLD_2 && theDog.friendshipTowardFarmer.Value <= THRESHOLD_3) { giftChance = GIFT_CHANCE_3; } // if the player is a farmhand, relationship with the dog is broken. Use predetermined chance for farmhands if (!Game1.player.IsMainPlayer) { //this.Monitor.Log("Player is a farmhand."); giftChance = FARMHAND_CHANCE; } // Reset gifts given counter, max gifts per week -> 3 if (Game1.dayOfMonth % 7 == 0) { giftsGiven = 0; } giftToday = false; giftId = 0; //this.Monitor.Log("Did the dog give a gift?\nFriendship: " + dogFriendship + "\nGift chance: " + giftChance + "\nGifts received this week: " + giftsGiven); // Draw a random gift ID. For clarity we do this in multiple steps // Step 1: Determine if cat gives a gift at all int random = Game1.random.Next(0, 100); //this.Monitor.Log("Random number: " + random + " --- must be larger than " + (100 - giftChance)); if (random > (100 - giftChance) && !Game1.isRaining && giftsGiven <= MAX_WEEKLY_GIFTS) { //this.Monitor.Log("Dog will give a gift ... maybe :3 (may still not happen if this is the second consecutive high tier gift)"); // Step 2: Determine quality: low = mid > high -> 40% / 40% / 20% int rand = Game1.random.Next(0, 100); // Pick a random item if (rand <= LOW_CHANCE) { //this.Monitor.Log("Low quality"); giftId = lowGifts.ElementAt(Game1.random.Next(lowGifts.Count - 1)); highTierYesterday = false; } else if (rand > LOW_CHANCE && rand <= (LOW_CHANCE + MID_CHANCE)) { //this.Monitor.Log("Medium quality"); giftId = midGifts.ElementAt(Game1.random.Next(midGifts.Count - 1)); highTierYesterday = false; } else if (rand > (100 - HI_CHANCE) && !highTierYesterday) { //this.Monitor.Log("High quality! :3"); giftId = hiGifts.ElementAt(Game1.random.Next(hiGifts.Count - 1)); highTierYesterday = true; } giftsGiven++; giftToday = true; } //else //this.Monitor.Log("No gift for you. You come back 10 years."); } //else //this.Monitor.Log("Player doesn't have a pet."); }
// If the cat gave a gift, warp him next to it the first time the player enters the farm public void Warped(object sender, EventArgs e) { if (Game1.currentLocation is Farm && giftToday && !warpedToday) { foreach (NPC pet in Game1.getLocationFromName("Farm").getCharacters()) { if (pet is StardewValley.Characters.Cat || pet is StardewValley.Characters.Dog) { //this.Monitor.Log("Found pet for warping."); thePet = (StardewValley.Characters.Pet)pet; } } if (thePet != null) { if (thePet is StardewValley.Characters.Cat) { // Have a chance of Dusty digging up something instead of the cat if (Game1.currentLocation.characters.Contains(Game1.getCharacterFromName("Dusty", true)) && Game1.random.Next(1, 10) > 8) { this.DogSpawn(null, Game1.getCharacterFromName("Dusty", true)); } else { int x = (int)Game1.player.Position.X / 64; int y = (int)Game1.player.Position.Y / 64; // Spawn gift // Remove old gift if there's still one on the floor OverlaidDictionary obs = Game1.getLocationFromName("Farm").Objects; Vector2 spawnPos = new Vector2(x, y + 1); for (int i = 0; i < obs.Count(); i++) { Vector2 currentPos = obs.Keys.ElementAt(i); if (currentPos == spawnPos) { obs.Remove(obs.Keys.ElementAt(i)); } } Game1.getLocationFromName("Farm").dropObject(new StardewValley.Object(giftId, 1, false, -1, 0), spawnPos * 64f, Game1.viewport, true, (Farmer)null); // Warp cat // Check if field is free Vector2 warpPos = new Vector2(x + 1, y + 2); Vector2 safePos = new Vector2(x + 1, y + 2); // If field is free, warp cat there if (Game1.getLocationFromName("Farm").isTileLocationTotallyClearAndPlaceableIgnoreFloors(warpPos)) { //this.Monitor.Log(warpPos.X + "/" + warpPos.Y + " is free, warping cat there"); thePet.Position = warpPos * 64f; } else { // Otherwise, find a nearby free location. If we find one, warp the cat there. Otherwise, just don't warp. safePos = this.FindSafePosition(warpPos); if (safePos != warpPos) { thePet.Position = safePos * 64f; } } // this.Monitor.Log("Warped him."); warpedToday = true; Game1.playSound("cat"); } } if (thePet is StardewValley.Characters.Dog) { // Have a chance of Dusty digging something up instead of the dog if (Game1.currentLocation.characters.Contains(Game1.getCharacterFromName("Dusty", true)) && Game1.random.Next(1, 10) > 8) { this.DogSpawn(null, Game1.getCharacterFromName("Dusty", true)); } else { this.DogSpawn(thePet, null); } } String dog = ""; if (thePet is StardewValley.Characters.Dog) { dog = " Search your farm carefully to find it!"; isCat = false; } msgDisplayed = true; Helper.Content.InvalidateCache(@"LooseSprites\Cursors.xnb"); HUDMessage msg = new HUDMessage(thePet.Name + " brought you a gift." + dog, 1); Game1.addHUDMessage(msg); } //else //this.Monitor.Log("Didn't find the pet."); } }