@@ -2651,6 +2651,8 @@ private void GiveItem(Item item, int destSlot, bool sendUpdate, BagSlot[]? bagSl
26512651 var remainingQuantity = item . Quantity ;
26522652 if ( bagSlots != default && destSlot < 0 )
26532653 {
2654+ List < Bag > bagsUpdated = new List < Bag > ( ) ;
2655+
26542656 foreach ( var bagSlot in bagSlots )
26552657 {
26562658 if ( remainingQuantity < 1 )
@@ -2664,9 +2666,28 @@ private void GiveItem(Item item, int destSlot, bool sendUpdate, BagSlot[]? bagSl
26642666 ) ;
26652667 bagSlot . Quantity += insertableQuantity ;
26662668 remainingQuantity -= insertableQuantity ;
2669+
2670+ bagsUpdated . Add ( bagSlot . ParentBag ) ;
2671+ }
2672+
2673+ foreach ( var bagUpdated in bagsUpdated )
2674+ {
2675+ // Save the bag changes
2676+ bagUpdated . Save ( ) ;
2677+ if ( IsInBag && InBag . Id == bagUpdated . Id )
2678+ {
2679+ // Refresh the player's UI if they had the bag opened.
2680+ PacketSender . SendOpenBag ( this , bagUpdated . SlotCount , bagUpdated ) ;
2681+ }
26672682 }
26682683 }
26692684
2685+ // Did placing stacks in the bags take care of business?
2686+ if ( remainingQuantity < 1 )
2687+ {
2688+ return ;
2689+ }
2690+
26702691 // Decide how we're going to handle this item.
26712692 var existingSlots = FindInventoryItemSlots ( item . Descriptor . Id ) ;
26722693 var updateSlots = new List < int > ( ) ;
@@ -2763,7 +2784,7 @@ private void GiveItem(Item item, int destSlot, bool sendUpdate, BagSlot[]? bagSl
27632784 else
27642785 {
27652786 var newSlot = FindOpenInventorySlot ( ) ;
2766- newSlot . Set ( item ) ;
2787+ newSlot . Set ( new Item ( item . ItemId , remainingQuantity , item . Properties ) ) ;
27672788 updateSlots . Add ( newSlot . Slot ) ;
27682789 }
27692790 }
@@ -7198,6 +7219,8 @@ public bool TryChangeName(string newName)
71987219 private bool JsonInShop => InShop != null ;
71997220
72007221 [ JsonIgnore , NotMapped ] public Bag InBag ;
7222+
7223+ [ JsonIgnore , NotMapped ] public bool IsInBag => InBag != null ;
72017224
72027225 [ JsonIgnore , NotMapped ] public ShopBase InShop ;
72037226
0 commit comments