Ejemplo n.º 1
0
        private void DoNpcGift(object sender, InventoryChangedEventArgs e)
        {
            SFarmer Player = Game1.player;
            var     day    = SDate.Now();

            foreach (GameLocation location in Game1.locations)
            {
                foreach (NPC npc in location.characters)
                {
                    if (!GaveNpcGift.ContainsKey(npc.Name))
                    {
                        if (Player.friendshipData.ContainsKey(npc.Name))
                        {
                            GaveNpcGift.Add(npc.Name, Player.friendshipData[npc.Name].GiftsToday);
                        }
                    }
                    else
                    {
                        if (npc.isBirthday(day.Season, day.Day))
                        {
                            GaveNpcGift[npc.Name] = Player.friendshipData[npc.Name].GiftsToday;
                        }
                    }
                }
            }

            /*
             * foreach(KeyValuePair<string, int> pair in GaveNpcGift)
             * {
             *  this.Monitor.Log($"Npc: {pair.Key} Gift Today: {pair.Value}");
             * }*/
        }
Ejemplo n.º 2
0
        /// <summary>Raised AFTER the player receives an item.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            // only update the inventory of the target player
            if (!e.IsLocalPlayer)
            {
                return;
            }

            IEnumerator <Item> enumerator = e.Added.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // not an item with a quality property, skip
                if (!(enumerator.Current is StardewValley.Object item))
                {
                    return;
                }

                // quality is already regular, nothing to do
                // otherwise the below code would "autosort" items to the first free slot when manually organizing the inventory
                if (item.Quality == 0)
                {
                    return;
                }

                // remove quality
                // because this happens only AFTER the item was added to the inventory,
                // make a best effort to stack the item with an already existing stack
                Game1.player.removeItemFromInventory(item);
                item.Quality = 0;
                Game1.player.addItemToInventory(item);
            }
        }
Ejemplo n.º 3
0
 /// <summary>Raised after items are added or removed to a player's inventory.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer)
     {
         this.AddLightsToInventoryItems();
     }
 }
        /// <summary>
        /// Handles the event raised after items are changed or removed from the Farmer's inventory
        /// </summary>
        /// <param name="sender">The sender of the InventoryChanged event</param>
        /// <param name="args">Event arguments for the InventoryChanged event</param>
        public void OnInventoryChanged(object sender, InventoryChangedEventArgs args)
        {
            // Short circuit if the pockey money hasn't increased
            if (Game1.player.Money <= PersistantFarmerData.PocketMoney)
            {
                return;
            }

            // Calculate all money gained from removed items or items that decreased their stack size
            int totalNewMoney = 0;

            totalNewMoney += ItemValueUtil.CalculateItemCollectionValue(args.Removed, false);
            totalNewMoney += ItemValueUtil.CalculateItemCollectionValue(args.QuantityChanged.Where(i => i.NewSize < i.OldSize), true);

            // Short circuit if the items removed don't have a value
            if (totalNewMoney == 0)
            {
                return;
            }

            // Get the share each player will receive
            int moneyPerPlayer = MoneySplitUtil.GetPerPlayerShare(totalNewMoney);

            // Correct the local player's money because they earned everyone's share
            MoneySplitUtil.CorrectLocalPlayer(totalNewMoney, moneyPerPlayer);

            // Tell all the other farmers to update their money too
            MoneyMessenger moneyMessenger = new MoneyMessenger();

            moneyMessenger.SendWalletNotification(moneyPerPlayer);
        }
Ejemplo n.º 5
0
        /// <summary>Raised after items are added or removed to a player's inventory.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private static void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            // replace mod items
            if (e.IsLocalPlayer)
            {
                IList <Item> inventory = Game1.player.Items;

                for (int i = 0; i < inventory.Count; ++i)
                {
                    var item = inventory[i];
                    if (item == null)
                    {
                        continue;
                    }

                    if (item.ParentSheetIndex == CobaltSprinklerObject.INDEX && !(item is CobaltSprinklerObject))
                    {
                        inventory[i] = new CobaltSprinklerObject();
                    }
                    else
                    {
                        continue;
                    }

                    Log.trace("Replacing a vanilla instance of custom item with my own. (Inventory)");
                    inventory[i].Stack = item.Stack;
                }
            }
        }
 /// <summary>Raised after items are added or removed to a player's inventory. NOTE: this event is currently only raised for the current player.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer)
     {
         this.PopulateRequiredBundles();
     }
 }
Ejemplo n.º 7
0
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            _monitor.VerboseLog("OnInventoryChanged");
            if (!e.IsLocalPlayer || e.Added.Count() != 1)
            {
                return;
            }

            var addedItem = e.Added.Single();

            if (addedItem is CustomChest)
            {
                return;
            }

            if (!CustomChestFactory.ShouldBeCustomChest(addedItem))
            {
                return;
            }

            _monitor.VerboseLog("OnInventoryChanged: converting");

            var index = Game1.player.Items.IndexOf(addedItem);

            Game1.player.Items[index] = addedItem.ToCustomChest();
        }
Ejemplo n.º 8
0
 private void InventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer && e.Removed.Count() == 1 && e.Added.Count() == 0 && e.QuantityChanged.Count() == 0)
     {
         var item = e.Removed.Single() as StardewValley.Object;
         if (item == null || item.ParentSheetIndex != lastPlaced?.ParentSheetIndex)
         {
             return;
         }
         if (e.Player.hasItemInInventoryNamed(item.Name))
         {
             foreach (var it in e.Player.Items.Select((x, i) => new { Value = x, Index = i }))
             {
                 var idx = it.Index;
                 var itm = it.Value;
                 if (itm?.Name == item.Name)
                 {
                     e.Player.Items[e.Player.CurrentToolIndex] = itm;
                     e.Player.Items[idx] = null;
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
 private static void Player_InventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     // Checks gamepad (snappy) menu interactions for purchasing cooking tool upgrades from Clint's upgrade tools menu
     // This causes a 'pop' sound to play, but it's otherwise all we need.
     if (BlacksmithCheck())
     {
         foreach (Item item in e.Added)
         {
             if (item is StardewValley.Tools.GenericTool tool)
             {
                 Log.D($"Checking tool upgrade (InventoryChanged) for {item?.Name}",
                       Config.DebugMode);
                 if (IsThisCookingTool(tool))
                 {
                     // Set up the frying pan upgrade
                     BlacksmithPrepareFryingPanUpgrade(tool);
                     // Remove item added to inventory
                     Game1.player.removeItemFromInventory(tool);
                     // Remove new item received popup
                     var message = Game1.hudMessages.FirstOrDefault(message => message?.type == tool.DisplayName);
                     Game1.hudMessages.Remove(message);
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 public static void InventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer)
     {
         OnInventoryChanged?.Invoke(e);
     }
 }
Ejemplo n.º 11
0
        private void inventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            // If updating on inventory add is disabled, return
            if (!Config.updateOnItemAddedToInventory)
            {
                return;
            }

            // Loop through any added items and update each weapon
            if (!iMadeThis)
            {
                foreach (Item i in e.Added)
                {
                    if (i != null && i is MeleeWeapon)
                    {
                        int weaponIndex = ((MeleeWeapon)i).InitialParentTileIndex;
                        Game1.player.removeItemFromInventory(i);
                        Game1.player.addItemToInventory(new MeleeWeapon(weaponIndex));
                    }
                }
                iMadeThis = true;
            }
            else
            {
                iMadeThis = false;
            }
        }
Ejemplo n.º 12
0
 private void OnInventoryChanged(object?sender, InventoryChangedEventArgs e)
 {
     if (CanUpdate() && e.IsLocalPlayer)
     {
         UpdateStage(e.Player, e.Added);
     }
 }
Ejemplo n.º 13
0
 /// <summary>Raised after items are added or removed to a player's inventory.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void Player_InventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     // After the user places down a grass starter, fix the color of the newly placed grass
     if (e.IsLocalPlayer && Game1.GetSeasonForLocation(Game1.currentLocation) == "winter" && (e.Removed.Any(item => item.ParentSheetIndex == grassStarterItemId) || e.QuantityChanged.Any(change => change.Item.ParentSheetIndex == grassStarterItemId)))
     {
         this.FixGrassColor();
     }
 }
Ejemplo n.º 14
0
 private void Player_InventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     e.Added.Where(a => e.IsLocalPlayer && !(a is Tool) && (a?.netName?.Value?.Contains("SeedBag") ?? false) || (a?.netName?.Value?.Contains(i18n.Get("Name")) ?? false)).ToList().ForEach(s =>
     {
         e.Player.removeItemFromInventory(s);
         e.Player.addItemToInventory(SeedBagTool.GetNew(Helper.GetPlatoHelper()));
     });
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Is called, when an inventory changed event occures.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">Event arguments.</param>
 private void OnInventoryChanged(Object sender, InventoryChangedEventArgs e)
 {
     // The easiest way is to redraw all screens
     if (engine != null)
     {
         Refresh();
     }
 }
Ejemplo n.º 16
0
 /// <summary>The method called after the player's inventory changes.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="args">The event arguments.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs args)
 {
     // Try updating new pans.
     foreach (Item item in args.Added)
     {
         UpdatePan(item);
     }
 }
Ejemplo n.º 17
0
 /// <summary>Raised after items are added or removed to a player's inventory.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     // After the user places down a grass starter, fix the color of the newly placed grass
     if (e.IsLocalPlayer && Game1.IsWinter && e.Removed.Any(item => item.ParentSheetIndex == 297))
     {
         this.FixGrassColor();
     }
 }
Ejemplo n.º 18
0
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs args)
        {
            Farmer player = args.Player;

            foreach (Item item in args.Added)
            {
                player.Items.Remove(item);
            }
        }
Ejemplo n.º 19
0
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     foreach (Item item in e.Added)
     {
         if (item.Name != "White Turnip")
         {
             continue;
         }
     }
 }
Ejemplo n.º 20
0
 /// <summary>Raised after items are added or removed to a player's inventory.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer && Game1.activeClickableMenu is GameMenu gameMenu && !oldMenu)
     {
         int craftingTabNum = gameMenu.getTabNumberFromName("crafting");
         if (gameMenu.currentTab == craftingTabNum)
         {
             List <IClickableMenu> pages = this.Helper.Reflection.GetFieldValue <List <IClickableMenu> >(gameMenu, "pages");
             ((BetterCraftingPage)pages[craftingTabNum]).UpdateInventory();
         }
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Raised after items are added or removed to a player's inventory.
        /// NOTE: This event is currently only raised for the current player.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            var logMessage = "No change";

            if (!Config.Active)
            {
                return;
            }
            if (!e.IsLocalPlayer)
            {
                return;
            }

            var curPlayer = e.Player;

            if (e.Added.Any())
            {
                foreach (var i in e.Added)
                {
                    logMessage = $"{curPlayer.Name}: Received [{i.Name}] x{i.Stack}";

                    if (!Config.TrashItems.Contains(i.Name))
                    {
                        continue;
                    }

                    if (Config.UseShippingBin)
                    {
                        MoveItemToShippingBin(curPlayer, i);
                    }
                    else
                    {
                        RemoveItemFromInventory(curPlayer, i);
                    }
                }
            }
            else if (e.Removed.Any())
            {
                foreach (var i in e.Removed)
                {
                    logMessage = $"{curPlayer.Name}: Lost [{i.Name}] x{i.Stack}";
                }
            }
            else if (e.QuantityChanged.Any())
            {
                foreach (var i in e.QuantityChanged)
                {
                    logMessage = $"{curPlayer.Name}: [{i.Item.Name}] changed from [{i.OldSize}] to [{i.NewSize}]";
                }
            }

            this.Monitor.Log(logMessage);
        }
Ejemplo n.º 22
0
 private void onInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (!e.Player.knowsRecipe("Frosty Stardrop"))
     {
         foreach (var item in e.Added)
         {
             if (item is StardewValley.Object obj && obj.ParentSheetIndex == ja.GetObjectId("Frosty Stardrop Piece"))
             {
                 e.Player.craftingRecipes.Add("Frosty Stardrop", 0);
             }
         }
     }
 }
Ejemplo n.º 23
0
        /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void CheckInventory(object sender, InventoryChangedEventArgs e)
        {
            // ignore if player hasn't loaded a save yet or it's not the local player
            if (!Context.IsWorldReady || !e.IsLocalPlayer)
            {
                return;
            }
            if (bestItem.Value != null && !e.Player.Items.Contains(bestItem.Value))
            {
                RestoreLastItem(e.Player);
            }

            CheckNeededBundleItems();
        }
Ejemplo n.º 24
0
 /// <summary>The method invoked when the local player's inventory changes.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     if (e.IsLocalPlayer)
     {
         foreach (var item in e.Added.Where(p => p.Category == -4))
         {
             foreach (var fish in Parser.GetFishData().Where(p => !p.Caught && p.Name == item.Name))
             {
                 Game1.addHUDMessage(new HUDMessage($"{fish.Name}'s data has been added to the Dex", 2));
                 fish.Caught = true;
             }
         }
     }
 }
Ejemplo n.º 25
0
        private void Player_InventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            // Handles when the last of a stackable item is removed from inventory
            foreach (Item item in e.Removed)
            {
                HandleUseRememberTotem(item);
            }

            // Handles when any item is removed from inventory
            foreach (ItemStackSizeChange item in e.QuantityChanged)
            {
                HandleUseRememberTotem(item.Item);
            }
        }
Ejemplo n.º 26
0
 /// <summary>Raised after items are added or removed to a player's inventory.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
 {
     // If the inventory changes while this even is hooked, we need to check if any SObject instances are in it, so we can replace them
     if (e.IsLocalPlayer)
     {
         for (int c = 0; c < Game1.player.Items.Count; c++)
         {
             if (Game1.player.Items[c] is SObject obj)
             {
                 this.Monitor.Log($"Reverting object: {obj.Name}:{obj.Stack}", LogLevel.Trace);
                 Game1.player.Items[c] = obj.Revert();
             }
         }
     }
 }
Ejemplo n.º 27
0
        /// <inheritdoc cref="IPlayerEvents.InventoryChanged"/>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            bool usedStaircase =
                e.IsLocalPlayer &&
                Game1.currentLocation is MineShaft &&
                (
                    e.Removed.Any(this.IsStaircase) ||
                    e.QuantityChanged.Any(p => p.NewSize < p.OldSize && this.IsStaircase(p.Item))
                );

            if (usedStaircase)
            {
                this.FixLadders();
            }
        }
Ejemplo n.º 28
0
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            foreach (var addedItem in e.Added)
            {
                // This check seems to be false for picked up grabbers...
                if (!(addedItem is VersatileGrabber grabber))
                {
                    continue;
                }

                // At this point it should be of type Versatile Grabber
                ModMonitor.Log("Versatile grabber found in inventory, converting to SObject", LogLevel.Debug);

                int index = Game1.player.Items.IndexOf(addedItem);
                Game1.player.Items[index] = grabber.ToObject();
            }
        }
Ejemplo n.º 29
0
        /// <summary>Player changes location.</summary>
        /// <param name="onItemRemoved">Callback.</param>
        /// <param name="e">Event data.</param>
        public static void OnInventoryChanged(Action <Item> onItemRemoved, InventoryChangedEventArgs e)
        {
            if (!e.IsLocalPlayer)
            {
                return;
            }

            IEnumerator <ItemStackSizeChange> quantityChanged = e.QuantityChanged.GetEnumerator();

            while (quantityChanged.MoveNext())
            {
                if (quantityChanged.Current.NewSize < quantityChanged.Current.OldSize)
                {
                    onItemRemoved(quantityChanged.Current.Item);
                }
            }
        }
Ejemplo n.º 30
0
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            if (!Game1.inMine || Game1.currentLocation.Name.Contains("UndergroundMine"))
                return;

            int mineLevel = Game1.mine.mineLevel;
            if (Game1.mine.objects.Any() && mineLevel == 10 && _bossInventoryState[0] == 1)
            {
                _bossInventoryState.Remove(0);
                List<Treasure> treasureList = new List<Treasure>();
                foreach (var mo in Game1.mine.objects.Pairs.ToList())
                {
                    Item mineItem = mo.Value;
                    treasureList.Add(new Treasure(mineItem.ParentSheetIndex, mineItem.Stack));
                }
                _bossInventory.Add(0, treasureList);
            }
        }
Ejemplo n.º 31
0
		/// <summary>
		/// Raises the inventory changed event.
		/// </summary>
		/// <param name="sender">Sender of event.</param>
		/// <param name="e">Inventory changed event arguments.</param>
		public void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
		{
			this.RaiseDisplayChanged("VisibleInventory");
		}
Ejemplo n.º 32
0
		/// <summary>
		/// Is called, when an inventory changed event occures.
		/// </summary>
		/// <param name="sender">Sender.</param>
		/// <param name="e">Event arguments.</param>
		private void OnInventoryChanged(Object sender, InventoryChangedEventArgs e)
		{
			// The easiest way is to redraw all screens
			if (engine != null)
				Refresh ();
		}
Ejemplo n.º 33
0
 void MonitorInventory(object sender, InventoryChangedEventArgs e)
 {
     Player parent = (sender as Inventory).Parent as Player;
     if (parent == null) return;
     parent.CancelTrade();
 }