document.addEventListener('DOMContentLoaded', () => { const dicePool = document.querySelector('dice-pool'); const diceGrid = document.querySelector('dice-grid'); const castBtn = document.getElementById('castBtn'); // Initialize dice pool with some dice dicePool.dice = ['A', 'B', 'C', 'D', 'E']; // Helper function to get random dice from pool function getRandomDice(dicePool, count) { // Make copy of current dice array const currentDice = [...(dicePool.dice || [])]; const shuffled = [...currentDice].sort(() => 0.5 - Math.random()); return shuffled.slice(0, Math.min(count, currentDice.length)); } // Ensure button exists before adding listener if (castBtn) { castBtn.addEventListener('click', () => { // Get random 5 dice from the pool const selectedDice = getRandomDice(dicePool, 5); // Place dice on the grid diceGrid.placeDice(selectedDice); }); } });