How does the candy merchant's lollipop stock work?

I noticed that buying a lot of lollipops from the candy merchant causes him to have a stock shortage, temporarily preventing him from selling lollipops.

Stock shortage : we will be restocked soon.
My questions:

  • How does the candy merchant's lollipop stock work? How many lollipops can I buy before he gets a stock shortage?
  • How long does it take for him to restock? Will he restock every x seconds, regardless of whether I bought all his lollipops or not? Or will he only start restocking once he gets a stock shortage?

Solution 1:

Each 15 minutes, the stock is updated by this formula:

this.setNbrInStock(this.nbrInStock + 15 + random.getRandomIntUpTo(10));

It adds 15 plus a random value between 0 and 10 of LPs to the stock. The maximum of LPs in stock is 140.

The update will occur, no matter whether you buy something or not, it just will be 140 LPs max.

if(this.nbrInStock > 140) this.nbrInStock = 140;

Funfact: It seems, that originally, it was planned, that the maximum are 100 LPs, as the comment says If > 100, decrease it.