Lashtw commited on
Commit
eec1238
·
1 Parent(s): ace23a8

feat(lottery): add interactive 3-die Wonder Dice pop-out showdown with pair/triple match bonus

Browse files
css/lottery.css CHANGED
@@ -668,6 +668,197 @@ body.lottery-draw-body {
668
  animation: lotteryConfettiFall 2.2s ease-out forwards;
669
  }
670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  /* 深淺主題同步保護 */
672
  html[data-theme="dark"] .lottery-modal-card {
673
  color: #fef3c7;
@@ -708,4 +899,34 @@ html[data-theme="dark"] body.lottery-draw-body {
708
  .lottery-lantern {
709
  display: none;
710
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
  }
 
668
  animation: lotteryConfettiFall 2.2s ease-out forwards;
669
  }
670
 
671
+ /* ----------------------------------------------------------------------------
672
+ * 🎲 奇蹟骰跳出對決舞台(3 顆實體感點數金骰+對子/豹子光環特效)
673
+ * ---------------------------------------------------------------------------- */
674
+ @keyframes wonderDicePopIn {
675
+ 0% { transform: scale(0.72) translateY(28px); opacity: 0; }
676
+ 65% { transform: scale(1.04) translateY(-4px); opacity: 1; }
677
+ 100% { transform: scale(1) translateY(0); opacity: 1; }
678
+ }
679
+
680
+ @keyframes wonderDieRollBounce {
681
+ 0% { transform: translateY(0) rotate(0deg) scale(1); }
682
+ 25% { transform: translateY(-22px) rotate(-18deg) scale(1.09); }
683
+ 50% { transform: translateY(-6px) rotate(14deg) scale(0.96); }
684
+ 75% { transform: translateY(-18px) rotate(-10deg) scale(1.06); }
685
+ 100% { transform: translateY(0) rotate(0deg) scale(1); }
686
+ }
687
+
688
+ @keyframes wonderDieMatchPulse {
689
+ 0%, 100% { transform: translateY(-6px) scale(1.08); box-shadow: 0 10px 26px rgba(245, 158, 11, 0.72), 0 0 0 4px rgba(220, 38, 38, 0.55); }
690
+ 50% { transform: translateY(-10px) scale(1.13); box-shadow: 0 14px 32px rgba(245, 158, 11, 0.92), 0 0 0 6px rgba(245, 158, 11, 0.8); }
691
+ }
692
+
693
+ .wonder-dice-overlay {
694
+ position: fixed;
695
+ inset: 0;
696
+ z-index: 999;
697
+ background: rgba(44, 32, 27, 0.62);
698
+ backdrop-filter: blur(5px);
699
+ display: flex;
700
+ align-items: center;
701
+ justify-content: center;
702
+ padding: 16px;
703
+ }
704
+
705
+ .wonder-dice-card {
706
+ position: relative;
707
+ width: min(640px, 100%);
708
+ border-radius: 22px;
709
+ padding: 22px 24px;
710
+ background: linear-gradient(165deg, #ffffff 0%, #fcf4eb 100%);
711
+ border: 2.5px solid #d97706;
712
+ box-shadow: 0 24px 60px rgba(44, 32, 27, 0.42), inset 0 0 24px rgba(245, 158, 11, 0.14);
713
+ color: #2c201b;
714
+ overflow: hidden;
715
+ animation: wonderDicePopIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
716
+ }
717
+
718
+ .wonder-dice-header {
719
+ display: flex;
720
+ align-items: center;
721
+ justify-content: space-between;
722
+ gap: 10px;
723
+ margin-bottom: 12px;
724
+ }
725
+
726
+ .wonder-dice-target-row {
727
+ display: flex;
728
+ align-items: center;
729
+ flex-wrap: wrap;
730
+ gap: 10px;
731
+ margin-bottom: 10px;
732
+ }
733
+
734
+ .wonder-dice-rules {
735
+ padding: 10px 14px;
736
+ border-radius: 12px;
737
+ background: #fef3c7;
738
+ border: 1.5px solid rgba(217, 119, 6, 0.45);
739
+ color: #78350f;
740
+ font-size: 1rem;
741
+ font-weight: 700;
742
+ text-align: center;
743
+ margin-bottom: 16px;
744
+ }
745
+
746
+ .wonder-dice-stage {
747
+ display: flex;
748
+ align-items: center;
749
+ justify-content: center;
750
+ gap: 24px;
751
+ padding: 18px 10px 22px;
752
+ min-height: 150px;
753
+ border-radius: 18px;
754
+ background: radial-gradient(circle at 50% 45%, rgba(245, 158, 11, 0.22), rgba(243, 222, 203, 0.52) 78%);
755
+ border: 1.5px solid rgba(180, 110, 80, 0.28);
756
+ margin-bottom: 14px;
757
+ }
758
+
759
+ .wonder-die {
760
+ position: relative;
761
+ width: 104px;
762
+ height: 104px;
763
+ border-radius: 22px;
764
+ padding: 12px;
765
+ background: linear-gradient(145deg, #ffffff 0%, #fffbeb 55%, #fde68a 100%);
766
+ border: 2.5px solid #b45309;
767
+ box-shadow:
768
+ 0 10px 22px rgba(120, 70, 50, 0.28),
769
+ inset 0 3px 6px rgba(255, 255, 255, 0.95),
770
+ inset 0 -4px 8px rgba(180, 83, 9, 0.25);
771
+ display: grid;
772
+ grid-template-columns: repeat(3, 1fr);
773
+ grid-template-rows: repeat(3, 1fr);
774
+ place-items: center;
775
+ transition: transform 0.24s ease, opacity 0.24s ease, filter 0.24s ease, box-shadow 0.24s ease;
776
+ }
777
+
778
+ .wonder-die.rolling {
779
+ animation: wonderDieRollBounce 0.36s ease-in-out infinite;
780
+ border-color: #ef4444;
781
+ }
782
+
783
+ .wonder-die.locked {
784
+ transform: scale(1.02);
785
+ }
786
+
787
+ .wonder-die.matched {
788
+ background: linear-gradient(145deg, #fffbeb 0%, #fef08a 58%, #f59e0b 100%);
789
+ border-color: #b91c1c;
790
+ animation: wonderDieMatchPulse 1.1s ease-in-out infinite;
791
+ }
792
+
793
+ .wonder-die.matched::after {
794
+ content: '同點!';
795
+ position: absolute;
796
+ top: -12px;
797
+ right: -10px;
798
+ padding: 2px 8px;
799
+ border-radius: 999px;
800
+ background: #b91c1c;
801
+ color: #fef08a;
802
+ font-size: 0.78rem;
803
+ font-weight: 900;
804
+ border: 1.5px solid #fef08a;
805
+ box-shadow: 0 3px 8px rgba(0, 0, 0, 0.28);
806
+ }
807
+
808
+ .wonder-die.unmatched {
809
+ opacity: 0.58;
810
+ filter: saturate(0.65);
811
+ transform: scale(0.95);
812
+ }
813
+
814
+ .wonder-pip {
815
+ width: 17px;
816
+ height: 17px;
817
+ border-radius: 999px;
818
+ background: radial-gradient(circle at 30% 30%, #451a03, #1c1917);
819
+ box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.7);
820
+ }
821
+
822
+ .wonder-pip.red {
823
+ background: radial-gradient(circle at 30% 30%, #ef4444, #991b1b);
824
+ }
825
+
826
+ .wonder-pip.big-one {
827
+ width: 26px;
828
+ height: 26px;
829
+ }
830
+
831
+ .wonder-dice-result-banner {
832
+ padding: 12px 16px;
833
+ border-radius: 14px;
834
+ font-size: 1.18rem;
835
+ font-weight: 900;
836
+ text-align: center;
837
+ margin-bottom: 14px;
838
+ background: #fcf4eb;
839
+ border: 1.5px solid rgba(180, 110, 80, 0.3);
840
+ color: #2c201b;
841
+ }
842
+
843
+ .wonder-dice-result-banner.hit {
844
+ background: linear-gradient(135deg, #fef08a 0%, #fde68a 100%);
845
+ border-color: #b91c1c;
846
+ color: #991b1b;
847
+ box-shadow: 0 6px 18px rgba(217, 119, 6, 0.28);
848
+ }
849
+
850
+ .wonder-dice-result-banner.miss {
851
+ background: #f5ebe0;
852
+ border-color: #998074;
853
+ color: #685247;
854
+ }
855
+
856
+ .wonder-dice-actions {
857
+ display: flex;
858
+ gap: 10px;
859
+ flex-wrap: wrap;
860
+ }
861
+
862
  /* 深淺主題同步保護 */
863
  html[data-theme="dark"] .lottery-modal-card {
864
  color: #fef3c7;
 
899
  .lottery-lantern {
900
  display: none;
901
  }
902
+
903
+ .wonder-dice-card {
904
+ padding: 16px;
905
+ }
906
+
907
+ .wonder-dice-stage {
908
+ gap: 12px;
909
+ padding: 14px 6px 18px;
910
+ }
911
+
912
+ .wonder-die {
913
+ width: 82px;
914
+ height: 82px;
915
+ padding: 9px;
916
+ border-radius: 16px;
917
+ }
918
+
919
+ .wonder-pip {
920
+ width: 13px;
921
+ height: 13px;
922
+ }
923
+
924
+ .wonder-pip.big-one {
925
+ width: 21px;
926
+ height: 21px;
927
+ }
928
+
929
+ .wonder-dice-actions {
930
+ flex-direction: column;
931
+ }
932
  }
js/lottery-core.js CHANGED
@@ -770,3 +770,70 @@ export function stepNonOverlappingBalls(
770
 
771
  return balls;
772
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770
 
771
  return balls;
772
  }
773
+
774
+ /**
775
+ * 奇蹟骰三顆同點判別引擎:
776
+ * - 任兩顆點數相同(對子):加碼 +1 兵符
777
+ * - 三顆點數全同(豹子):爆擊加碼 +2 兵符
778
+ * - 三顆皆異:+0 兵符
779
+ * 全程受每人累積加碼上限 maxBonus(預設 3)保護。
780
+ */
781
+ export function evaluateWonderDiceRoll(dice = null, { currentBonus = 0, maxBonus = 3 } = {}) {
782
+ const rawList = Array.isArray(dice) && dice.length === 3
783
+ ? dice
784
+ : Array.from({ length: 3 }, () => Math.floor(Math.random() * 6) + 1);
785
+ const faces = rawList.map(v => {
786
+ const n = Math.round(Number(v) || 1);
787
+ return Math.min(6, Math.max(1, n));
788
+ });
789
+
790
+ const counts = {};
791
+ for (const f of faces) counts[f] = (counts[f] || 0) + 1;
792
+
793
+ let matchedValue = null;
794
+ let matchedCount = 0;
795
+ for (const [valStr, cnt] of Object.entries(counts)) {
796
+ if (cnt >= 2 && cnt > matchedCount) {
797
+ matchedCount = cnt;
798
+ matchedValue = Number(valStr);
799
+ }
800
+ }
801
+
802
+ let outcome = 'none';
803
+ let rawDelta = 0;
804
+ if (matchedCount === 3) {
805
+ outcome = 'triple';
806
+ rawDelta = 2;
807
+ } else if (matchedCount === 2) {
808
+ outcome = 'pair';
809
+ rawDelta = 1;
810
+ }
811
+
812
+ const matchedIndices = matchedValue === null
813
+ ? []
814
+ : faces.reduce((arr, f, idx) => (f === matchedValue ? [...arr, idx] : arr), []);
815
+
816
+ const cap = Math.max(0, Number(maxBonus) || 3);
817
+ const cur = Math.max(0, Number(currentBonus) || 0);
818
+ const nextBonus = Math.min(cap, cur + rawDelta);
819
+ const appliedDelta = Math.max(0, nextBonus - cur);
820
+ const capped = rawDelta > 0 && appliedDelta < rawDelta;
821
+
822
+ let label = '💨 未出現同點對子(+0 兵符)';
823
+ if (outcome === 'triple') label = '👑 三星豹子!奇蹟爆擊 +2 兵符';
824
+ else if (outcome === 'pair') label = '🎉 雙骰同點!加碼 +1 兵符';
825
+
826
+ return {
827
+ dice: faces,
828
+ outcome,
829
+ matchedCount,
830
+ matchedValue,
831
+ matchedIndices,
832
+ rawDelta,
833
+ appliedDelta,
834
+ nextBonus,
835
+ maxBonus: cap,
836
+ capped,
837
+ label,
838
+ };
839
+ }
js/lottery-draw.js CHANGED
@@ -15,6 +15,7 @@ import {
15
  calcLotteryMilestonesProgress,
16
  calcAdaptiveBallRadius,
17
  stepNonOverlappingBalls,
 
18
  createLotteryDrawState,
19
  drawWeightedWinner,
20
  applyTierDrawWithUpgrade,
@@ -470,10 +471,72 @@ function playMachineSound(kind) {
470
  osc.connect(g); g.connect(_drawAudio.destination);
471
  osc.start(now + idx * 0.09); osc.stop(now + idx * 0.09 + 0.38);
472
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
  }
474
  } catch (e) {}
475
  }
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  async function initLotteryDrawPage() {
478
  const db = await getDB();
479
  const params = new URLSearchParams(location.search);
@@ -754,16 +817,217 @@ async function initLotteryDrawPage() {
754
  saveTempSession();
755
  await triggerSingleDraw(t, false);
756
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
757
  $('#btnWonderDiceBonus')?.addEventListener('click', () => {
758
  const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
759
  if (!drawState || isAnimating || cycle?.status === 'settled') return;
760
- if (!lastWinnerUid) return alert('請先抽出至少一位現場得主再擲奇蹟骰!');
761
- const roll = Math.random() < 0.5 ? 1 : 2;
762
- const next = Math.min(3, (extraBonuses[lastWinnerUid] || 0) + roll);
763
- extraBonuses[lastWinnerUid] = next;
764
- saveTempSession();
765
- $('#lotteryChuteReveal').innerHTML += `<div style="margin-top:8px; color:#0284c7; font-size:1.08rem; font-weight:900;">🎲 奇蹟骰啟動!加碼總額累計 +${next} 兵符(上限 3)</div>`;
766
- renderAll();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767
  });
768
  $('#btnResetLocalDraw')?.addEventListener('click', () => {
769
  const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
 
15
  calcLotteryMilestonesProgress,
16
  calcAdaptiveBallRadius,
17
  stepNonOverlappingBalls,
18
+ evaluateWonderDiceRoll,
19
  createLotteryDrawState,
20
  drawWeightedWinner,
21
  applyTierDrawWithUpgrade,
 
471
  osc.connect(g); g.connect(_drawAudio.destination);
472
  osc.start(now + idx * 0.09); osc.stop(now + idx * 0.09 + 0.38);
473
  });
474
+ } else if (kind === 'diceRoll') {
475
+ for (let i = 0; i < 12; i++) {
476
+ const osc = _drawAudio.createOscillator();
477
+ const g = _drawAudio.createGain();
478
+ osc.type = 'square';
479
+ osc.frequency.setValueAtTime(340 + (i % 5) * 85, now + i * 0.09);
480
+ g.gain.setValueAtTime(0.0001, now + i * 0.09);
481
+ g.gain.exponentialRampToValueAtTime(0.07, now + i * 0.09 + 0.01);
482
+ g.gain.exponentialRampToValueAtTime(0.0001, now + i * 0.09 + 0.055);
483
+ osc.connect(g); g.connect(_drawAudio.destination);
484
+ osc.start(now + i * 0.09); osc.stop(now + i * 0.09 + 0.06);
485
+ }
486
+ } else if (kind === 'diceMiss') {
487
+ [330, 240].forEach((freq, idx) => {
488
+ const osc = _drawAudio.createOscillator();
489
+ const g = _drawAudio.createGain();
490
+ osc.type = 'sine';
491
+ osc.frequency.setValueAtTime(freq, now + idx * 0.14);
492
+ g.gain.setValueAtTime(0.11, now + idx * 0.14);
493
+ g.gain.exponentialRampToValueAtTime(0.0001, now + idx * 0.14 + 0.22);
494
+ osc.connect(g); g.connect(_drawAudio.destination);
495
+ osc.start(now + idx * 0.14); osc.stop(now + idx * 0.14 + 0.24);
496
+ });
497
  }
498
  } catch (e) {}
499
  }
500
 
501
+ const DIE_PIP_SLOTS = {
502
+ 1: [5],
503
+ 2: [1, 9],
504
+ 3: [1, 5, 9],
505
+ 4: [1, 3, 7, 9],
506
+ 5: [1, 3, 5, 7, 9],
507
+ 6: [1, 3, 4, 6, 7, 9],
508
+ };
509
+
510
+ function renderWonderDieFaceHtml(face) {
511
+ const f = Math.min(6, Math.max(1, Math.round(Number(face) || 1)));
512
+ const activeSlots = DIE_PIP_SLOTS[f] || [5];
513
+ let html = '';
514
+ for (let slot = 1; slot <= 9; slot++) {
515
+ if (activeSlots.includes(slot)) {
516
+ const isRed = f === 1 || f === 4;
517
+ const cls = `wonder-pip${isRed ? ' red' : ''}${f === 1 ? ' big-one' : ''}`;
518
+ html += `<span class="${cls}"></span>`;
519
+ } else {
520
+ html += '<span></span>';
521
+ }
522
+ }
523
+ return html;
524
+ }
525
+
526
+ function spawnWonderDiceConfetti(cardEl) {
527
+ if (!cardEl) return;
528
+ const colors = ['#f59e0b', '#ef4444', '#fef08a', '#fb923c', '#10b981'];
529
+ for (let i = 0; i < 20; i++) {
530
+ const piece = document.createElement('span');
531
+ piece.className = 'lottery-confetti';
532
+ piece.style.left = `${8 + Math.random() * 84}%`;
533
+ piece.style.background = colors[i % colors.length];
534
+ piece.style.animationDelay = `${(Math.random() * 0.28).toFixed(2)}s`;
535
+ cardEl.appendChild(piece);
536
+ setTimeout(() => piece.remove(), 2400);
537
+ }
538
+ }
539
+
540
  async function initLotteryDrawPage() {
541
  const db = await getDB();
542
  const params = new URLSearchParams(location.search);
 
817
  saveTempSession();
818
  await triggerSingleDraw(t, false);
819
  });
820
+ // 🎲 奇蹟骰跳出對決舞台控制器(3 顆實體感點數骰,對子 +1、豹子 +2)
821
+ let isDiceRolling = false;
822
+ let diceIntervalId = null;
823
+ const diceTimeouts = [];
824
+
825
+ const clearDiceTimers = () => {
826
+ if (diceIntervalId) {
827
+ clearInterval(diceIntervalId);
828
+ diceIntervalId = null;
829
+ }
830
+ while (diceTimeouts.length > 0) {
831
+ clearTimeout(diceTimeouts.pop());
832
+ }
833
+ };
834
+
835
+ const getDrawnWinnerEntries = () => {
836
+ const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
837
+ const rankMap = { head: 4, t1: 3, t2: 2, t3: 1 };
838
+ const tierLabelMap = Object.fromEntries((drawState?.prizeTiers || []).map(t => [t.tierKey, t.label]));
839
+ return Object.entries(drawState?.uidToTier || {})
840
+ .map(([uid, tierKey]) => {
841
+ const entry = cycle?.entries?.[uid] || {};
842
+ return {
843
+ uid,
844
+ tierKey,
845
+ tierLabel: tierLabelMap[tierKey] || tierKey,
846
+ rank: rankMap[tierKey] || 0,
847
+ seat: String(entry.seat || '?'),
848
+ name: entry.name || uid,
849
+ };
850
+ })
851
+ .sort((a, b) => b.rank - a.rank);
852
+ };
853
+
854
+ const syncWonderDiceTargets = (preferredUid = null) => {
855
+ const sel = $('#selWonderDiceTarget');
856
+ const capEl = $('#lblWonderDiceCap');
857
+ if (!sel) return null;
858
+ const list = getDrawnWinnerEntries();
859
+ sel.innerHTML = list.map(w => {
860
+ const b = extraBonuses[w.uid] || 0;
861
+ return `<option value="${esc(w.uid)}">${esc(w.tierLabel)}・${esc(w.seat)}號 ${esc(w.name)}${b > 0 ? ` (+${b})` : ''}</option>`;
862
+ }).join('');
863
+ const chosen = (preferredUid && list.some(w => w.uid === preferredUid))
864
+ ? preferredUid
865
+ : (lastWinnerUid && list.some(w => w.uid === lastWinnerUid))
866
+ ? lastWinnerUid
867
+ : list[0]?.uid || '';
868
+ if (chosen) sel.value = chosen;
869
+ if (capEl && chosen) {
870
+ const cur = extraBonuses[chosen] || 0;
871
+ capEl.textContent = `已加碼 +${cur} / 3 兵符`;
872
+ }
873
+ return chosen;
874
+ };
875
+
876
+ const closeWonderDiceModal = () => {
877
+ clearDiceTimers();
878
+ isDiceRolling = false;
879
+ const overlay = $('#wonderDiceOverlay');
880
+ if (overlay) overlay.classList.add('hidden');
881
+ };
882
+
883
+ const runWonderDiceRoll = () => {
884
+ const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
885
+ if (!drawState || isAnimating || isDiceRolling || cycle?.status === 'settled') return;
886
+ const sel = $('#selWonderDiceTarget');
887
+ const targetUid = sel?.value || lastWinnerUid;
888
+ const winnerMeta = getDrawnWinnerEntries().find(w => w.uid === targetUid);
889
+ if (!targetUid || !winnerMeta) return;
890
+
891
+ clearDiceTimers();
892
+ isDiceRolling = true;
893
+ const rollAgainBtn = $('#btnRollWonderDiceAgain');
894
+ const finishBtn = $('#btnFinishWonderDice');
895
+ const bannerEl = $('#wonderDiceResult');
896
+ if (rollAgainBtn) rollAgainBtn.disabled = true;
897
+ if (sel) sel.disabled = true;
898
+ if (finishBtn) finishBtn.disabled = true;
899
+
900
+ const dieEls = [$('#wonderDie0'), $('#wonderDie1'), $('#wonderDie2')];
901
+ const locked = [false, false, false];
902
+ dieEls.forEach((el, idx) => {
903
+ if (!el) return;
904
+ el.classList.remove('locked', 'matched', 'unmatched');
905
+ el.classList.add('rolling');
906
+ el.innerHTML = renderWonderDieFaceHtml(((idx + 2) % 6) + 1);
907
+ });
908
+
909
+ if (bannerEl) {
910
+ bannerEl.className = 'wonder-dice-result-banner';
911
+ bannerEl.textContent = `🎲 正在為【${winnerMeta.seat}號 ${winnerMeta.name}】擲出三顆奇蹟金骰…`;
912
+ }
913
+
914
+ const curBonus = extraBonuses[targetUid] || 0;
915
+ const res = evaluateWonderDiceRoll(null, { currentBonus: curBonus, maxBonus: 3 });
916
+
917
+ playMachineSound('diceRoll');
918
+ diceIntervalId = setInterval(() => {
919
+ for (let i = 0; i < 3; i++) {
920
+ if (!locked[i] && dieEls[i]) {
921
+ const tempFace = Math.floor(Math.random() * 6) + 1;
922
+ dieEls[i].innerHTML = renderWonderDieFaceHtml(tempFace);
923
+ }
924
+ }
925
+ }, 65);
926
+
927
+ const lockDie = (idx) => {
928
+ locked[idx] = true;
929
+ const el = dieEls[idx];
930
+ if (!el) return;
931
+ el.classList.remove('rolling');
932
+ el.classList.add('locked');
933
+ el.innerHTML = renderWonderDieFaceHtml(res.dice[idx]);
934
+ playMachineSound('tick');
935
+ };
936
+
937
+ diceTimeouts.push(setTimeout(() => lockDie(0), 520));
938
+ diceTimeouts.push(setTimeout(() => {
939
+ lockDie(1);
940
+ if (bannerEl && res.dice[0] === res.dice[1]) {
941
+ bannerEl.textContent = `👀 前兩顆同為【${res.dice[0]} 點】!已穩拿 +1 兵符,第三顆拚三星豹子!`;
942
+ }
943
+ }, 960));
944
+
945
+ diceTimeouts.push(setTimeout(() => {
946
+ if (diceIntervalId) {
947
+ clearInterval(diceIntervalId);
948
+ diceIntervalId = null;
949
+ }
950
+ lockDie(2);
951
+
952
+ const matchedSet = new Set(res.matchedIndices);
953
+ dieEls.forEach((el, idx) => {
954
+ if (!el) return;
955
+ if (matchedSet.has(idx)) el.classList.add('matched');
956
+ else el.classList.add('unmatched');
957
+ });
958
+
959
+ if (res.appliedDelta > 0) {
960
+ extraBonuses[targetUid] = res.nextBonus;
961
+ saveTempSession();
962
+ renderAll();
963
+ syncWonderDiceTargets(targetUid);
964
+ playMachineSound('fanfare');
965
+ spawnWonderDiceConfetti($('#wonderDiceCard'));
966
+ if (bannerEl) {
967
+ bannerEl.className = 'wonder-dice-result-banner hit';
968
+ bannerEl.innerHTML = `${esc(res.label)}<div style="font-size:1rem; margin-top:4px; color:#78350f;">🎁 ${esc(winnerMeta.seat)}號 ${esc(winnerMeta.name)} 奇蹟骰加碼累計 +${res.nextBonus} / 3 兵符</div>`;
969
+ }
970
+ const chute = $('#lotteryChuteReveal');
971
+ if (chute) {
972
+ chute.innerHTML = `<div style="font-size:1.18rem; color:#991b1b; font-weight:900; text-align:center;">🎲 奇蹟骰開出 [${res.dice.join('・')}] ➔ ${esc(res.label)}(${esc(winnerMeta.seat)}號 ${esc(winnerMeta.name)} 累計 +${res.nextBonus} 兵符)</div>`;
973
+ }
974
+ } else if (res.capped) {
975
+ playMachineSound('diceMiss');
976
+ if (bannerEl) {
977
+ bannerEl.className = 'wonder-dice-result-banner miss';
978
+ bannerEl.textContent = `🎲 開出 [${res.dice.join('・')}]!雖擲出同點,但 ${winnerMeta.seat}號已達個人 +3 兵符上限!`;
979
+ }
980
+ } else {
981
+ playMachineSound('diceMiss');
982
+ if (bannerEl) {
983
+ bannerEl.className = 'wonder-dice-result-banner miss';
984
+ bannerEl.textContent = `💨 開出 [${res.dice.join('・')}]・三顆都不同點(+0 兵符),按下方按鈕再試一次!`;
985
+ }
986
+ }
987
+
988
+ isDiceRolling = false;
989
+ if (rollAgainBtn) rollAgainBtn.disabled = (extraBonuses[targetUid] || 0) >= 3;
990
+ if (sel) sel.disabled = false;
991
+ if (finishBtn) finishBtn.disabled = false;
992
+ }, 1460));
993
+ };
994
+
995
  $('#btnWonderDiceBonus')?.addEventListener('click', () => {
996
  const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
997
  if (!drawState || isAnimating || cycle?.status === 'settled') return;
998
+ const winners = getDrawnWinnerEntries();
999
+ if (winners.length === 0) {
1000
+ return alert('請先抽出至少一位現場得主再擲奇蹟骰!');
1001
+ }
1002
+ const overlay = $('#wonderDiceOverlay');
1003
+ if (!overlay) return;
1004
+ const chosenUid = syncWonderDiceTargets(lastWinnerUid);
1005
+ overlay.classList.remove('hidden');
1006
+ if ((extraBonuses[chosenUid] || 0) >= 3) {
1007
+ const bannerEl = $('#wonderDiceResult');
1008
+ if (bannerEl) {
1009
+ bannerEl.className = 'wonder-dice-result-banner miss';
1010
+ bannerEl.textContent = '✅ 目前選取同學已達奇蹟骰上限 (+3 兵符),可切換其他得主挑戰!';
1011
+ }
1012
+ if ($('#btnRollWonderDiceAgain')) $('#btnRollWonderDiceAgain').disabled = true;
1013
+ } else {
1014
+ runWonderDiceRoll();
1015
+ }
1016
+ });
1017
+
1018
+ $('#selWonderDiceTarget')?.addEventListener('change', (e) => {
1019
+ if (isDiceRolling) return;
1020
+ const uid = e.target.value;
1021
+ const cur = extraBonuses[uid] || 0;
1022
+ if ($('#lblWonderDiceCap')) $('#lblWonderDiceCap').textContent = `已加碼 +${cur} / 3 兵符`;
1023
+ if ($('#btnRollWonderDiceAgain')) $('#btnRollWonderDiceAgain').disabled = cur >= 3;
1024
+ });
1025
+
1026
+ $('#btnRollWonderDiceAgain')?.addEventListener('click', () => runWonderDiceRoll());
1027
+ $('#btnCloseWonderDice')?.addEventListener('click', () => closeWonderDiceModal());
1028
+ $('#btnFinishWonderDice')?.addEventListener('click', () => closeWonderDiceModal());
1029
+ $('#wonderDiceOverlay')?.addEventListener('click', (e) => {
1030
+ if (e.target === $('#wonderDiceOverlay') && !isDiceRolling) closeWonderDiceModal();
1031
  });
1032
  $('#btnResetLocalDraw')?.addEventListener('click', () => {
1033
  const cycle = currentCycleId ? currentClass?.lotteryCycles?.[currentCycleId] : null;
lottery-draw.html CHANGED
@@ -65,7 +65,7 @@
65
 
66
  <div style="margin-top:10px; display:flex; gap:10px; flex-wrap:wrap;">
67
  <button id="btnExtraTeacherDraw" class="draw-btn" type="button" style="flex:1;">➕ 班導加抽 +1 名</button>
68
- <button id="btnWonderDiceBonus" class="draw-btn" type="button" style="flex:1;">🎲 奇蹟骰加碼 (+1~2 兵符)</button>
69
  <button id="btnResetLocalDraw" class="draw-btn" type="button" title="僅重設尚未結算發信的現場模擬抽籤">🧹 重抽暫存</button>
70
  </div>
71
  </section>
@@ -86,6 +86,41 @@
86
  </section>
87
  </main>
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  <script type="module" src="js/lottery-draw.js?v=20261116_v1"></script>
90
  </body>
91
  </html>
 
65
 
66
  <div style="margin-top:10px; display:flex; gap:10px; flex-wrap:wrap;">
67
  <button id="btnExtraTeacherDraw" class="draw-btn" type="button" style="flex:1;">➕ 班導加抽 +1 名</button>
68
+ <button id="btnWonderDiceBonus" class="draw-btn" type="button" style="flex:1;">🎲 奇蹟骰對決(同點 +1|豹子 +2)</button>
69
  <button id="btnResetLocalDraw" class="draw-btn" type="button" title="僅重設尚未結算發信的現場模擬抽籤">🧹 重抽暫存</button>
70
  </div>
71
  </section>
 
86
  </section>
87
  </main>
88
 
89
+ <!-- 🎲 奇蹟骰跳出對決舞台 -->
90
+ <div id="wonderDiceOverlay" class="wonder-dice-overlay hidden" role="dialog" aria-modal="true" aria-labelledby="wonderDiceTitle">
91
+ <div id="wonderDiceCard" class="wonder-dice-card">
92
+ <div class="wonder-dice-header">
93
+ <h2 id="wonderDiceTitle" style="margin:0; font-size:1.45rem; color:#991b1b;">🎲 奇蹟骰・加碼對決台</h2>
94
+ <button id="btnCloseWonderDice" class="draw-btn" type="button" aria-label="關閉奇蹟骰視窗">✕</button>
95
+ </div>
96
+
97
+ <div class="wonder-dice-target-row">
98
+ <label for="selWonderDiceTarget" style="font-weight:800; color:#2c201b; font-size:1.05rem;">🎯 加碼對象:</label>
99
+ <select id="selWonderDiceTarget" class="draw-select" style="flex:1; min-width:180px;"></select>
100
+ <span id="lblWonderDiceCap" class="lottery-pill-tag">+0 / 3 兵符</span>
101
+ </div>
102
+
103
+ <div class="wonder-dice-rules">
104
+ ✨ 三骰同步擲出:<b>任兩顆同點 ➔ 加碼 +1 兵符</b>|<b>三顆全同(豹子)➔ 加碼 +2 兵符</b>(單人上限 3 兵符)
105
+ </div>
106
+
107
+ <div id="wonderDiceStage" class="wonder-dice-stage">
108
+ <div id="wonderDie0" class="wonder-die" data-face="6"></div>
109
+ <div id="wonderDie1" class="wonder-die" data-face="6"></div>
110
+ <div id="wonderDie2" class="wonder-die" data-face="1"></div>
111
+ </div>
112
+
113
+ <div id="wonderDiceResult" class="wonder-dice-result-banner">
114
+ 準備擲出三顆禦用金骰…
115
+ </div>
116
+
117
+ <div class="wonder-dice-actions">
118
+ <button id="btnRollWonderDiceAgain" class="draw-btn gold" type="button" style="flex:1; font-size:1.12rem;">🎲 再次擲出奇蹟骰!</button>
119
+ <button id="btnFinishWonderDice" class="draw-btn" type="button" style="font-size:1.05rem;">✅ 確認返回開獎台</button>
120
+ </div>
121
+ </div>
122
+ </div>
123
+
124
  <script type="module" src="js/lottery-draw.js?v=20261116_v1"></script>
125
  </body>
126
  </html>
tools/verify-integrity.mjs CHANGED
@@ -77,6 +77,7 @@ import {
77
  applyTierDrawWithUpgrade,
78
  buildLotterySettlement,
79
  stepNonOverlappingBalls,
 
80
  } from '../js/lottery-core.js';
81
  import { renderRichQuizText, todayStr } from '../js/util.js';
82
  import { rollChestRewards, evaluateChestRhythm, CHEST_RHYTHM_CFG } from '../js/tianji.js';
@@ -1611,12 +1612,32 @@ ok('學生端透明樂透箱舞台、activeRound F5 鎖定與 CSS RWD 檢驗 100
1611
  'btnExtraTeacherDraw',
1612
  'btnWonderDiceBonus',
1613
  'btnRedrawVacancy',
 
 
 
1614
  ]) {
1615
  assert.ok(drawHtml.includes(id), `lottery-draw.html 缺少必要控制/開獎機元素 #${id}`);
1616
  }
1617
  const drawJsCode = fs.readFileSync(path.join(ROOT, 'js', 'lottery-draw.js'), 'utf8');
1618
  assert.ok(!/\b(?:onSnapshot|onWorldBoss)\s*\(/.test(drawJsCode), '開獎台嚴禁使用常駐監聽呼叫');
1619
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1620
  assert.equal(
1621
  pickDefaultLotteryCycleId({
1622
  weeklySpotlight: { eventId: 'lottery', cycleId: 'lotto_pilot_20261119' },
 
77
  applyTierDrawWithUpgrade,
78
  buildLotterySettlement,
79
  stepNonOverlappingBalls,
80
+ evaluateWonderDiceRoll,
81
  } from '../js/lottery-core.js';
82
  import { renderRichQuizText, todayStr } from '../js/util.js';
83
  import { rollChestRewards, evaluateChestRhythm, CHEST_RHYTHM_CFG } from '../js/tianji.js';
 
1612
  'btnExtraTeacherDraw',
1613
  'btnWonderDiceBonus',
1614
  'btnRedrawVacancy',
1615
+ 'wonderDiceOverlay',
1616
+ 'selWonderDiceTarget',
1617
+ 'btnRollWonderDiceAgain',
1618
  ]) {
1619
  assert.ok(drawHtml.includes(id), `lottery-draw.html 缺少必要控制/開獎機元素 #${id}`);
1620
  }
1621
  const drawJsCode = fs.readFileSync(path.join(ROOT, 'js', 'lottery-draw.js'), 'utf8');
1622
  assert.ok(!/\b(?:onSnapshot|onWorldBoss)\s*\(/.test(drawJsCode), '開獎台嚴禁使用常駐監聽呼叫');
1623
 
1624
+ // 奇蹟骰三顆同點判別引擎檢驗(任 2 顆同點 +1、3 顆豹子 +2、全異 +0、上限 3 守衛)
1625
+ const wdPair = evaluateWonderDiceRoll([3, 3, 5], { currentBonus: 0, maxBonus: 3 });
1626
+ assert.equal(wdPair.outcome, 'pair');
1627
+ assert.equal(wdPair.appliedDelta, 1);
1628
+ assert.deepEqual(wdPair.matchedIndices, [0, 1]);
1629
+ const wdTriple = evaluateWonderDiceRoll([6, 6, 6], { currentBonus: 1, maxBonus: 3 });
1630
+ assert.equal(wdTriple.outcome, 'triple');
1631
+ assert.equal(wdTriple.appliedDelta, 2);
1632
+ assert.equal(wdTriple.nextBonus, 3);
1633
+ const wdMiss = evaluateWonderDiceRoll([1, 4, 6], { currentBonus: 0, maxBonus: 3 });
1634
+ assert.equal(wdMiss.outcome, 'none');
1635
+ assert.equal(wdMiss.appliedDelta, 0);
1636
+ const wdCap = evaluateWonderDiceRoll([2, 2, 5], { currentBonus: 3, maxBonus: 3 });
1637
+ assert.equal(wdCap.appliedDelta, 0);
1638
+ assert.equal(wdCap.nextBonus, 3);
1639
+ assert.equal(wdCap.capped, true);
1640
+
1641
  assert.equal(
1642
  pickDefaultLotteryCycleId({
1643
  weeklySpotlight: { eventId: 'lottery', cycleId: 'lotto_pilot_20261119' },