ModernUO/Projects/UOContent/Mobiles
Kamron Batman d857f03b68
fix: bound and purge NPC vendor buyback stock (#2677)
## Summary

Stacked on #2676. Review that first; this PR's diff is against it.

Items players sell to NPC vendors go into the vendor's buyback (`ShopBuy`) pack. That pack was purged only when someone opened the buy menu, so a vendor that players sold to but never bought from grew without limit.
- A server operator reported 250k+ items piling up from players crafting and selling on a macro.
- Every one of those items was saved.
- Purging or deleting that vendor then sent one remove packet per item to every nearby client and disconnected them.

The behavior is inherited from RunUO.

- **`VendorBuybackPack`** replaces the plain backpack on `Layer.ShopBuy`.
  - It opts in to `SkipsChildSerialization`, so buyback items are never saved.
  - Its contents are private like any container's, so removing them reaches only the vendor (no client) and openers. Purges and deletes send nothing to bystanders.
- **Capacity.** The buyback holds at most `250 − buy-list entries` items, which is what the buy gump can show. The oldest items are evicted first. At capacity 0 the sold item is consumed and the seller is still paid.
- **Purge on the restock grid.**
  - `Restock()` empties the buyback.
  - A purge-only timer, armed on the first sale, covers vendors nobody buys from. It is due at the next restock boundary after now, so a vendor whose restock hasn't run for hours doesn't purge an item the moment it's sold.
  - The timer never restocks, so stock doubling and halving is unchanged.
  - The old per-item one-hour `LastMoved` check is gone.
- **Existing saves.** A legacy `ShopBuy` pack is replaced on the first tick after load. Thanks to #2676, deleting a pack of 250k+ items takes well under a second.

**Behavior changes for shard operators:**
- A buyback item lasts until the next restock boundary (at most `RestockDelay`), not one hour after its sale.
- A vendor that changes maps drops its buyback.
- A buy window that is open during a purge can show a row whose item is gone. Buying that row does nothing, and reopening shows the current list.

## Test plan

- [x] `VendorBuybackPackTests`: evicts oldest first; capacity 0 consumes the item; purge; a stale front entry can't spin eviction
- [x] `VendorBuybackTests`:
  - purge due time stays on the restock grid, including a stale restock and a restock time in the future;
  - partial stack sale: the split goes to buyback and the seller keeps the remainder;
  - zero capacity consumes the item and still pays;
  - restock purges and clears the timer, and the next sale re-arms it;
  - deleting the vendor cancels the timer;
  - a legacy 20k-item pack is replaced.
- [x] UOContent.Tests and Server.Tests green; schema generator clean
- [x] Manual in-game pass:
  - sell and buy back, including a partial stack;
  - over-capacity sale;
  - purge with no buyer;
  - `[restock`;
  - vendor facet change;
  - restart;
  - legacy save with a large `ShopBuy` pack;
  - mass selling with bystanders present;
  - deleting a vendor with a full buyback.
2026-10-09 22:56:39 -07:00
..
Abilities refactor: master views over BaseCreature's one master reference (#2674) 2026-09-24 22:45:24 -07:00
AI refactor: master views over BaseCreature's one master reference (#2674) 2026-09-24 22:45:24 -07:00
Animals refactor: master views over BaseCreature's one master reference (#2674) 2026-09-24 22:45:24 -07:00
Familiars refactor: master views over BaseCreature's one master reference (#2674) 2026-09-24 22:45:24 -07:00
Guards feat: Adjusts fame and karma system with era gates for OSI accuracy (#2389) 2026-04-25 11:19:57 -07:00
Healers feat: Adds Mobile.Murderer virtual property, consolidates kill-threshold checks (#2355) 2026-03-06 08:36:41 -08:00
Hireables refactor: fold hand-written serializable property setters into field hooks (#2587) 2026-08-22 18:20:39 -07:00
Monsters fix: fishing catches by expansion, SOS facets and the big fish mark (#2688) 2026-10-04 18:17:05 -07:00
Special perf: keep damage entries in an inline intrusive list (#2605) 2026-09-01 23:25:14 -07:00
Townfolk feat: adopt serialization generator v4 (field-side linkage, anchored timers) (#2586) 2026-08-22 17:54:02 -07:00
Vendors fix: bound and purge NPC vendor buyback stock (#2677) 2026-10-09 22:56:39 -07:00
BaseCreature.cs fix: a deleted character's followers, and familiars that never unregistered (#2675) 2026-09-24 23:01:40 -07:00
CreatureEvents.cs refactor: Changes BaseCreature to the SerializationGenerator (delta save requirement) (#2611) 2026-09-06 14:11:51 -07:00
NPCSpeeds.cs refactor: Changes BaseCreature to the SerializationGenerator (delta save requirement) (#2611) 2026-09-06 14:11:51 -07:00
PlayerMobile.cs fix: a deleted character's followers, and familiars that never unregistered (#2675) 2026-09-24 23:01:40 -07:00
VirtualMountItem.cs fix: Fixes mount stamina, adds Pub46+ Ethereal stamina (#1716) 2024-04-05 21:05:16 -07:00