#!/usr/bin/env node // ===================================================================== // [DEPRECATED / ARCHIVED HISTORICAL CLI — 僅供 2026-10-21 封測重整歷史存查] // ⚠️ 警告:本腳本為一次性封測早期工具,內含舊版寫死數值(舊 baseProds、 // 1.5^star 倍率等),與現行遊戲公式 (js/config.js / js/engine.js) 不相容, // 嚴禁對正式營運班級重複執行。請勿修改其歷史演算法,僅保留作封存紀錄。 // ===================================================================== // 攻城掠地・封測先鋒功勳結算 & 全自動進度重整腳本 (Alpha Reset & Reward CLI) // // 功能: // 1. 自動檢索並計算資料庫中全班每位學生的「每秒糧草產量(🌾/秒)」 // 2. 依階梯規準換算對應的「📜 偷看卷」與「✂️ 刪去卷」數量 // 3. 將個人糧草重設為 15、兵符為 0、城池清空(恢復開局狀態) // 4. 將換算卷軸存入學生背包(game.items) // 5. 寫入 alphaPioneer 功勳紀錄,並將 alphaNoticeSeen 設為 false // 讓學生於明日打開遊戲時自動彈出專屬冊封令(單次顯示,之後不再出現) // // 用法: // node tools/alpha-reset.js --help // node tools/alpha-reset.js --dry-run (預覽試算,不寫入資料庫) // node tools/alpha-reset.js --class=skill115 (執行指定班級重整與發獎) // ===================================================================== import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 讀取 firebase-config.js 提取專案設定 const configPath = path.resolve(__dirname, '../js/firebase-config.js'); let firebaseConfig = { apiKey: "AIzaSyDN79LlYPgxp98N4pjAIdi5HBk31HWbs0A", projectId: "finalreview-fe52b" }; try { const cfgRaw = fs.readFileSync(configPath, 'utf-8'); const apiKeyMatch = cfgRaw.match(/apiKey:\s*["']([^"']+)["']/); const projectIdMatch = cfgRaw.match(/projectId:\s*["']([^"']+)["']/); if (apiKeyMatch) firebaseConfig.apiKey = apiKeyMatch[1]; if (projectIdMatch) firebaseConfig.projectId = projectIdMatch[1]; } catch(e) { // 使用預設 fallback } // 獎勵換算階梯表 function calcAlphaReward(prodPerSec, student) { const g = student?.game; const hasPlayed = !!(g && ( prodPerSec > 0 || (g.clicks || 0) > 0 || (g.totalEarned || 0) > 0 || (g.buildings && Object.values(g.buildings).some(b => (b?.lv || 0) > 0)) )); if (prodPerSec >= 300) { return { rankTitle: '智勇大將軍', peek: 3, eliminate: 3, hasPlayed: true, desc: '秒產 ≥ 300 🌾(每分 ≥ 1.8萬)' }; } else if (prodPerSec >= 50) { return { rankTitle: '破陣前鋒', peek: 2, eliminate: 2, hasPlayed: true, desc: '秒產 ≥ 50 🌾(每分 ≥ 3,000)' }; } else if (prodPerSec >= 10) { return { rankTitle: '驍勇校尉', peek: 1, eliminate: 2, hasPlayed: true, desc: '秒產 ≥ 10 🌾(每分 ≥ 600)' }; } else if (hasPlayed) { return { rankTitle: '隨軍將士', peek: 1, eliminate: 1, hasPlayed: true, desc: '封測拓荒隨軍保底獎' }; } else { return { rankTitle: '新募新兵', peek: 0, eliminate: 0, hasPlayed: false, desc: '未參與今日封測' }; } } // 產能估算模型(與 engine.js buildingProd 相同) function estimateProd(game) { if (!game || !game.buildings) return 0; // 建築基本秒產定義 const baseProds = { b1: 1, b2: 4, b3: 15, b4: 55, b5: 200, b6: 750, b7: 2800, b8: 10500, b9: 40000, b10: 160000 }; let total = 0; for (const [id, b] of Object.entries(game.buildings)) { const lv = Number(b?.lv) || 0; if (lv > 0 && baseProds[id]) { let p = baseProds[id] * lv; // 里程碑倍率 (每 25 級 x2) const milestones = [25, 50, 100, 150, 200, 250]; const mCount = milestones.filter(m => lv >= m).length; p *= Math.pow(2, mCount); // 星級倍率 (每星 x1.5) const star = Number(b?.star) || 0; p *= Math.pow(1.5, star); total += p; } } return total; } // 解析命令列參數 const args = process.argv.slice(2); const isDryRun = args.includes('--dry-run'); const targetClassArg = args.find(a => a.startsWith('--class=')); const targetClass = targetClassArg ? targetClassArg.split('=')[1] : null; console.log('\n==========================================================================='); console.log(' 🎖️ 攻城掠地・封測先鋒功勳結算 & 全自動進度重整系統 (CLI)'); console.log(' Firebase Project: ' + firebaseConfig.projectId); console.log(' 模式: ' + (isDryRun ? '🔍 預覽試算(--dry-run,不更動資料庫)' : '🚀 正式重整模式')); console.log('===========================================================================\n'); console.log(`📋 換算獎勵階梯規準:`); console.log(` 1. 【智勇大將軍】(秒產 ≥ 300 🌾,每分 ≥ 1.8萬) ➜ 📜 偷看卷 ×3、✂️ 刪去卷 ×3`); console.log(` 2. 【破陣前鋒】 (秒產 ≥ 50 🌾,每分 ≥ 3,000) ➜ 📜 偷看卷 ×2、✂️ 刪去卷 ×2`); console.log(` 3. 【驍勇校尉】 (秒產 ≥ 10 🌾,每分 ≥ 600) ➜ 📜 偷看卷 ×1、✂️ 刪去卷 ×2`); console.log(` 4. 【隨軍將士】 (參與封測拓荒保底獎) ➜ 📜 偷看卷 ×1、✂️ 刪去卷 ×1\n`); console.log('💡 提示:本專案亦已在【教師後台(teacher.html)】中實裝「🎖️ 封測功勳結算&重整進度」按鈕,'); console.log(' 教師可直接在瀏覽器後台以高質感視覺化介面一鍵全自動預覽與結算!'); console.log(' 若需透過命令列批次作業,請參考上方階梯或在後台執行。\n');