private void SpaceEventsOnBeforeGiftGiven(object sender, EventArgsBeforeReceiveObject e) { // Ignore gifts that aren't going to be accepted if (!e.Npc.canReceiveThisItemAsGift(e.Gift) || !Game1.player.friendshipData.ContainsKey(e.Npc.Name) || Game1.player.friendshipData[e.Npc.Name].GiftsThisWeek > 1 || Game1.player.friendshipData[e.Npc.Name].GiftsToday > 0) { return; } // Patch in unique gift dialogue for easter egg deliveries if (e.Gift.Name != EasterEggItem && e.Gift.Name != EasterBasketItem) { return; } if (e.Gift.Name == EasterBasketItem) { ++Game1.player.CurrentItem.Stack; } TempGiftTasteDialogue = new KeyValuePair <string, string>(e.Npc.Name, Game1.NPCGiftTastes[e.Npc.Name]); var str = i18n.Get($"talk.egg_gift.{e.Npc.Name.ToLower()}"); if (!str.HasValue()) { throw new KeyNotFoundException(); } Game1.NPCGiftTastes[e.Npc.Name] = UpdateEntry( Game1.NPCGiftTastes[e.Npc.Name], new[] { (string)str }, false, false, 2); // Remove the patch on the next tick, after the unique gift dialogue has been loaded and drawn Helper.Events.GameLoop.UpdateTicked += Event_UndoGiftChanges; }
private static void DoPostGiftStuff(Farmer gifter, NPC giftee, EventArgsBeforeReceiveObject e) { e.Cancel = true; gifter.reduceActiveItemByOne(); gifter.currentLocation.localSound("give_gift"); gifter.friendshipData["Torts"].GiftsToday++; gifter.friendshipData["Torts"].GiftsThisWeek++; gifter.friendshipData["Torts"].LastGiftDate = new WorldDate(Game1.Date); giftee.CurrentDialogue.Clear(); giftee.CurrentDialogue.Push(new Dialogue("...", giftee)); Game1.drawDialogue(giftee); }
private static void BeforeGiftGiven(object sender, EventArgsBeforeReceiveObject e) { NPC giftee = e.Npc; if (giftee.Name != "Torts") { return; } Farmer gifter = Game1.player; if (gifter.friendshipData["Torts"].GiftsToday == 1) { Game1.drawObjectDialogue(Game1.parseText(Game1.content.LoadString("Strings\\StringsFromCSFiles:NPC.cs.3981", giftee.displayName))); e.Cancel = true; return; } if (gifter.friendshipData["Torts"].GiftsThisWeek == 2) { Game1.drawObjectDialogue(Game1.parseText(Game1.content.LoadString("Strings\\StringsFromCSFiles:NPC.cs.3987", giftee.displayName, 2))); e.Cancel = true; return; } StardewValley.Object gift = e.Gift; switch (gift.Name) { case MISTBLOOM: Game1.weatherForTomorrow = Game1.weather_rain; break; case FOXTAIL: gifter.team.sharedDailyLuck.Value = 0.12; break; case LOVERPIE: gifter.mailReceived.Add(LOVERFLAG); break; case FAIRYFISH: gifter.mailReceived.Add(FAIRYFLAG); break; case NIGHTBLACK: gifter.mailReceived.Add(METEORFLAG); break; default: return; } DoPostGiftStuff(gifter, giftee, e); }
private void SpaceEvents_BeforeGiftGiven(object sender, EventArgsBeforeReceiveObject e) { // Ignore NPC gifts that aren't going to be accepted if (!e.Npc.canReceiveThisItemAsGift(e.Gift) || !Game1.player.friendshipData.ContainsKey(e.Npc.Name) || Game1.player.friendshipData[e.Npc.Name].GiftsThisWeek > 1 || Game1.player.friendshipData[e.Npc.Name].GiftsToday > 0) { return; } if (e.Gift.Name == AssetPrefix + WrappedGiftName) { // Cancel the wrapped gift NPC gift e.Cancel = true; Item actualGift = this.UnpackItem(modData: e.Gift.modData, recipientName: null); if (!(actualGift is StardewValley.Object o) || o.bigCraftable.Value || !o.canBeGivenAsGift() || actualGift.Stack > 1) { // Ignore actual gifts that are invalid NPC gifts, eg. Tools // Ignore actual gifts wrapped as part of large stacks, as items are typically only able to be given as gifts one-at-a-time Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Event.cs.1803")); Game1.playSound("cancel"); return; } // Redeliver the NPC gift as the actual gift e.Npc.receiveGift(o: actualGift as StardewValley.Object, giver: Game1.player, updateGiftLimitInfo: true, friendshipChangeMultiplier: 1, showResponse: true); // Add bonus friendship for having given them a wrapped gift Game1.player.changeFriendship(amount: GiftWrapFriendshipBoost, n: e.Npc); // Remove wrapped gift from inventory Game1.player.removeItemFromInventory(e.Gift); } }