예제 #1
0
        /// <summary>Bump the amount this NPC has received this item.</summary>
        /// <returns>Wether or not the gift exceeded the declining threshold.</returns>
        private static bool BumpGiftAmount(string npcName, Item item)
        {
            string itemId = item.ParentSheetIndex.ToString();

            if (!SaveState.GiftTasteDeclineBuffer.ContainsKey(npcName))
            {
                SaveState.GiftTasteDeclineBuffer.Add(npcName, new Dictionary <string, int>());
            }

            int existingAmount = 0;

            if (SaveState.GiftTasteDeclineBuffer[npcName].ContainsKey(itemId))
            {
                existingAmount = SaveState.GiftTasteDeclineBuffer[npcName][itemId];
            }

            int  newAmount       = existingAmount + 1;
            bool didExceedBuffer = newAmount >= ConfigHelper.Config.ReduceAfterXGifts;

            if (didExceedBuffer)
            {
                string logExceeded = "Gifting threshold (" + ConfigHelper.Config.ReduceAfterXGifts + ") reached for ";
                logExceeded += npcName + ", item " + NpcHelper.GetItemString(item);
                Logger.Trace(logExceeded);
                SaveState.GiftTasteDeclineBuffer[npcName].Remove(itemId);
            }
            else
            {
                Logger.Trace(npcName + " received item " + NpcHelper.GetItemString(item) + ". Total: " + newAmount);
                SaveState.GiftTasteDeclineBuffer[npcName][itemId] = newAmount;
            }

            return(didExceedBuffer);
        }
예제 #2
0
        /// <summary>Apply the current overwrites to the game.</summary>
        public static void Apply()
        {
            foreach (string npcName in SaveState.GiftTasteOverwrites.Keys)
            {
                NPC npc = Game1.getCharacterFromName(npcName);
                if (npc == null)
                {
                    Logger.Trace("Skipping unknown NPC \"" + npcName + "\".");
                    continue;
                }

                // .ToList because the save state is potentially "repaired" in this block
                foreach (string itemId in SaveState.GiftTasteOverwrites[npcName].Keys.ToList())
                {
                    Item item = new Object(int.Parse(itemId), 1);
                    if (item == null)
                    {
                        Logger.Trace("Skipping unknown item \"" + itemId + "\" for NPC \"" + npcName + "\".");
                        continue;
                    }

                    int currentTaste   = SaveState.GiftTasteOverwrites[npcName][itemId];
                    int actualSetTaste = NpcHelper.SetGiftTasteLevel(npc, item, currentTaste);
                    if (actualSetTaste != currentTaste)
                    {
                        // fix save state, it is not valid with the current configuration
                        SaveState.GiftTasteOverwrites[npcName][itemId] = actualSetTaste;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>Clear the list of gift taste differences.</summary>
        public static void ResetSaveState()
        {
            Logger.Trace("Resetting save state");
            NpcHelper.ResetGiftTastes();

            SaveState.GiftTasteOverwrites    = new Dictionary <string, Dictionary <string, int> >();
            SaveState.GiftTasteDeclineBuffer = new Dictionary <string, Dictionary <string, int> >();
        }
예제 #4
0
 /// <summary>NPCs got loaded.</summary>
 /// <param name="e">Event data.</param>
 public static void OnNpcListChanged(NpcListChangedEventArgs e)
 {
     if (!e.IsCurrentLocation)
     {
         return;
     }
     NpcHelper.StoreAmountOfGiftsReceived(e.Added);
 }
예제 #5
0
        /// <summary>After save game got loaded (or new one is created).</summary>
        public static void OnSaveLoaded()
        {
            NpcHelper.StoreDefaultGiftTastes();

            if (!Context.IsMainPlayer)
            {
                return;
            }

            SaveGameHelper.LoadFromFileOrInitialize();
            SaveGameHelper.Apply();
        }
예제 #6
0
        private void OnItemRemoved(Item plainItem)
        {
            if (!this.isInDialog)
            {
                return;
            }

            if (!(plainItem is StardewValley.Object item))
            {
                return;
            }
            if (!item.canBeGivenAsGift())
            {
                return;                                       // e.g. Tools or any placable object
            }
            IEnumerator <NPC> enumerator = Game1.player.currentLocation.characters.GetEnumerator();

            while (enumerator.MoveNext())
            {
                NPC npc = enumerator.Current;
                if (NpcHelper.AcceptsGifts(npc) && NpcHelper.HasJustReceivedGift(npc, item))
                {
                    Logger.Trace(npc.Name + " received gift #" + item.ParentSheetIndex + " (" + item.Name + ")");
                    SaveGameHelper.HandleReceivedGift(npc, item);
                    return;
                }
            }

            foreach (ItemDeliveryQuest quest in QuestLogHelper.GetDailyItemDeliveryQuests())
            {
                if (quest.deliveryItem.Value.ParentSheetIndex == item.ParentSheetIndex && quest.hasReward())
                {
                    Logger.Trace("Handed over quest item");
                    return;
                }
            }

            Logger.Trace("It appears a gift has been given to someone, but I can't determine to whom :(");
            Logger.Trace("Maybe it was a non-daily quest item? (" + item.Name + ")");
        }
예제 #7
0
        /// <summary>Update the buffer .</summary>
        /// <param name="npc">NPC.</param>
        /// <param name="item">Item.</param>
        public static void HandleReceivedGift(NPC npc, Item item)
        {
            string npcName = npc.Name;
            string itemId  = item.ParentSheetIndex.ToString();

            bool didBufferExceed = BumpGiftAmount(npcName, item);

            if (didBufferExceed)
            {
                int newGiftTaste = NpcHelper.GetReduceGiftTaste(npc, item);
                SetGiftTaste(npc.Name, itemId, newGiftTaste);
            }

            if (Context.IsMultiplayer)
            {
                // In single player, adjusting gift tastes is handled at the end of the day
                // so the player can see the actual reaction to that gift in the social tab.
                // But in Multiplayer, this delay causes some headaches when debugging some scenarios.
                // So just apply it right away. This way all players are also in sync.
                Apply();
            }

            SyncWithPeers();
        }
예제 #8
0
 /// <summary>Player changes location.</summary>
 public static void OnWarped()
 {
     NpcHelper.StoreAmountOfGiftsReceived(Game1.player.currentLocation.characters);
 }