[SerializeField] private Sprite[] bakerSprites = default; // reference to the list of possible baker sprites void Start() { // Setup trade reference lists (and only do so once per game launch) if (Trade.HundredTrades == null) { Trade.CreateHundredTradesList(); } if (Trade.AllLayouts == null) { Trade.CreateTradeLayoutsList(); } if (Trade.OneTrades == null) { Trade.CreateTradesLists(); } else { Trade.ShuffleTradesLists(); // if the trade lists have already been created in a previous round, just reshuffle them } // Choose a set from the 100 list to be the final target int rand = Random.Range(0, Trade.HundredTrades.Count); Trade mcGuffin = Trade.HundredTrades[rand]; goldenTrade.DisplayTrade(mcGuffin); // Choose another set from the 100 list to be the player's starting inventory. Deep copy to avoid // changing the list as the player's inventory changes rand = Random.Range(0, Trade.HundredTrades.Count); Dictionary <Muffin, int> startingInventory = new Dictionary <Muffin, int>(Trade.HundredTrades[rand].Buying); shopMenu.SetInitialPlayerInventory(startingInventory); // Distribute other trades to the normal shops by iterating through the shops list and trades lists concurrently int onesCounter = 0; int twosCounter = 0; int threesCounter = 0; for (int i = 0; i < shops.Length; i++) { shops[i].Layout = Trade.AllLayouts[i]; switch (Trade.AllLayouts[i]) { case Trade.ShopLayout.GOLD: // the golden shop is handled above break; case Trade.ShopLayout.ONE_THREE_ONE: shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.ThreeTrades[threesCounter]); threesCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; break; case Trade.ShopLayout.ONE_TWO_ONE: shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; break; case Trade.ShopLayout.TWO_TWO_TWO: shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; break; case Trade.ShopLayout.TWO_ONE_TWO: shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.TwoTrades[twosCounter]); twosCounter++; break; case Trade.ShopLayout.ONE_ONE_ONE_ONE: shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; shops[i].Trades.Add(Trade.OneTrades[onesCounter]); onesCounter++; break; } } // Randomly assign a baker to each shop System.Random rng = new System.Random(); int n = bakerSprites.Length; while (n > 1) { int k; do { k = rng.Next(n); } while (k == 0); // NOTE: we want to leave bakerSprites[0] in place n--; Sprite value = bakerSprites[k]; bakerSprites[k] = bakerSprites[n]; bakerSprites[n] = value; } for (int i = 0; i < shops.Length; i++) { shops[i].BakerSprite = bakerSprites[i]; } // Start clock Clock = 0; InvokeRepeating("ClockTick", 1, 1); }