feat(lottery-a1): add EVENT_CATALOG, event-schedule, pilot preset & claim-before-hide guard
Browse files- js/config.js +94 -1
- js/engine.js +57 -19
- js/event-schedule.js +305 -0
- tools/verify-integrity.mjs +434 -20
js/config.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
// 所有數值都集中在這裡,調整平衡只要改這個檔案。
|
| 4 |
// =============================================================
|
| 5 |
|
| 6 |
-
export const APP_BUILD_VERSION = '
|
| 7 |
|
| 8 |
// ---------- 主題(攻城掠地世界觀) ----------
|
| 9 |
export const THEME = {
|
|
@@ -472,6 +472,51 @@ export const EVENTS_CONFIG = [
|
|
| 472 |
}
|
| 473 |
];
|
| 474 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 475 |
// =============================================================
|
| 476 |
// 西域商隊與駱駝商人(英文 960 單字跨領域活動)
|
| 477 |
// =============================================================
|
|
@@ -743,6 +788,54 @@ export const TITLE_DEFS = {
|
|
| 743 |
shadow: '0 0 6px rgba(71, 85, 105, 0.4)',
|
| 744 |
glowClass: '',
|
| 745 |
rarity: '先鋒・隨軍'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
}
|
| 747 |
};
|
| 748 |
|
|
|
|
| 3 |
// 所有數值都集中在這裡,調整平衡只要改這個檔案。
|
| 4 |
// =============================================================
|
| 5 |
|
| 6 |
+
export const APP_BUILD_VERSION = '20261114_v2';
|
| 7 |
|
| 8 |
// ---------- 主題(攻城掠地世界觀) ----------
|
| 9 |
export const THEME = {
|
|
|
|
| 472 |
}
|
| 473 |
];
|
| 474 |
|
| 475 |
+
/** 可插拔活動底座註冊目錄(週期固定事件 + 奇數週/快閃主打活動插件) */
|
| 476 |
+
export const EVENT_CATALOG = {
|
| 477 |
+
camel: {
|
| 478 |
+
id: 'camel',
|
| 479 |
+
name: '駱駝商人',
|
| 480 |
+
icon: '🐫',
|
| 481 |
+
category: 'odd_baseline',
|
| 482 |
+
isRecurringBiweekly: true,
|
| 483 |
+
isSpotlightPlugin: false,
|
| 484 |
+
supportsCycles: false,
|
| 485 |
+
supportsSubThemes: false,
|
| 486 |
+
},
|
| 487 |
+
caravan: {
|
| 488 |
+
id: 'caravan',
|
| 489 |
+
name: '西域商隊',
|
| 490 |
+
icon: '🐫',
|
| 491 |
+
category: 'even_baseline',
|
| 492 |
+
isRecurringBiweekly: true,
|
| 493 |
+
isSpotlightPlugin: false,
|
| 494 |
+
supportsCycles: false,
|
| 495 |
+
supportsSubThemes: false,
|
| 496 |
+
},
|
| 497 |
+
lottery: {
|
| 498 |
+
id: 'lottery',
|
| 499 |
+
name: '錯題樂透',
|
| 500 |
+
icon: '🎰',
|
| 501 |
+
category: 'spotlight_plugin',
|
| 502 |
+
isRecurringBiweekly: false,
|
| 503 |
+
isSpotlightPlugin: true,
|
| 504 |
+
supportsCycles: true,
|
| 505 |
+
supportsSubThemes: true,
|
| 506 |
+
defaultPrizeMode: 'standard',
|
| 507 |
+
},
|
| 508 |
+
boss: {
|
| 509 |
+
id: 'boss',
|
| 510 |
+
name: '世界 Boss',
|
| 511 |
+
icon: '👹',
|
| 512 |
+
category: 'spotlight_plugin',
|
| 513 |
+
isRecurringBiweekly: false,
|
| 514 |
+
isSpotlightPlugin: true,
|
| 515 |
+
supportsCycles: true,
|
| 516 |
+
supportsSubThemes: true,
|
| 517 |
+
},
|
| 518 |
+
};
|
| 519 |
+
|
| 520 |
// =============================================================
|
| 521 |
// 西域商隊與駱駝商人(英文 960 單字跨領域活動)
|
| 522 |
// =============================================================
|
|
|
|
| 788 |
shadow: '0 0 6px rgba(71, 85, 105, 0.4)',
|
| 789 |
glowClass: '',
|
| 790 |
rarity: '先鋒・隨軍'
|
| 791 |
+
},
|
| 792 |
+
'九州錦鯉': {
|
| 793 |
+
name: '九州錦鯉',
|
| 794 |
+
icon: '🐠',
|
| 795 |
+
source: '錯題樂透・頭獎傳說',
|
| 796 |
+
desc: '自萬千錯題之中脫穎而出,氣運貫通九州的樂透頭獎錦鯉!',
|
| 797 |
+
bg: 'linear-gradient(135deg, #f59e0b 0%, #b45309 60%, #78350f 100%)',
|
| 798 |
+
border: '1px solid #fde68a',
|
| 799 |
+
color: '#fffbeb',
|
| 800 |
+
shadow: '0 0 14px rgba(245, 158, 11, 0.75)',
|
| 801 |
+
glowClass: 'title-glow-gold',
|
| 802 |
+
rarity: '傳說・錦鯉'
|
| 803 |
+
},
|
| 804 |
+
'天選歐皇': {
|
| 805 |
+
name: '天選歐皇',
|
| 806 |
+
icon: '👑',
|
| 807 |
+
source: '錯題樂透・頭獎加冕',
|
| 808 |
+
desc: '黃金彩球閃耀天際,週五公開抽獎萬眾矚目的天選之人!',
|
| 809 |
+
bg: 'linear-gradient(135deg, #d97706 0%, #991b1b 100%)',
|
| 810 |
+
border: '1px solid #fcd34d',
|
| 811 |
+
color: '#ffffff',
|
| 812 |
+
shadow: '0 0 12px rgba(251, 191, 36, 0.65)',
|
| 813 |
+
glowClass: 'title-glow-gold',
|
| 814 |
+
rarity: '史詩・歐皇'
|
| 815 |
+
},
|
| 816 |
+
'鴻運先鋒': {
|
| 817 |
+
name: '鴻運先鋒',
|
| 818 |
+
icon: '🎊',
|
| 819 |
+
source: '錯題樂透・一獎榮耀',
|
| 820 |
+
desc: '厚積薄發,兼顧錯題實力與好運眷顧的一獎贏家!',
|
| 821 |
+
bg: 'linear-gradient(135deg, #0ea5e9 0%, #1d4ed8 100%)',
|
| 822 |
+
border: '1px solid #7dd3fc',
|
| 823 |
+
color: '#ffffff',
|
| 824 |
+
shadow: '0 0 10px rgba(14, 165, 233, 0.55)',
|
| 825 |
+
glowClass: 'title-glow-blue',
|
| 826 |
+
rarity: '稀有・鴻運'
|
| 827 |
+
},
|
| 828 |
+
'錯題終結者': {
|
| 829 |
+
name: '錯題終結者',
|
| 830 |
+
icon: '⚡',
|
| 831 |
+
source: '錯題樂透・最勤學苦勞獎',
|
| 832 |
+
desc: '週內投球最勤勉、親手掃清海量錯題的實力典範!',
|
| 833 |
+
bg: 'linear-gradient(135deg, #10b981 0%, #047857 100%)',
|
| 834 |
+
border: '1px solid #6ee7b7',
|
| 835 |
+
color: '#ffffff',
|
| 836 |
+
shadow: '0 0 10px rgba(16, 185, 129, 0.55)',
|
| 837 |
+
glowClass: 'title-glow-emerald',
|
| 838 |
+
rarity: '殊榮・勤學'
|
| 839 |
}
|
| 840 |
};
|
| 841 |
|
js/engine.js
CHANGED
|
@@ -7,9 +7,10 @@ import {
|
|
| 7 |
OPEN_OFFSET_DAYS, DEFAULT_OPEN_HOUR, SYSTEMS, WEEKLY_SCHEDULE, SLOTH_PENALTY_MULT,
|
| 8 |
EVENTS_CONFIG, WORLD_BOSS_ROSTER, WORLD_BOSS_END_DATE, MERCHANT,
|
| 9 |
ERA2_TALLY_COST, ERA2_BASE_PROD, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES,
|
| 10 |
-
} from './config.js?v=
|
| 11 |
-
import { todayStr, addDays } from './util.js?v=
|
| 12 |
-
import { normalizeWorldBossState, getScheduledOpenTs, formatCountdown, formatOpenAt } from './world-boss-schedule.js?v=
|
|
|
|
| 13 |
export { normalizeWorldBossState, formatCountdown, formatOpenAt };
|
| 14 |
export { todayStr, REVIEW_MAX_QUESTIONS, WORLD_BOSS_ROSTER, ERA2_TALLY_COST, ERA2_BASE_PROD, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES };
|
| 15 |
|
|
@@ -1105,14 +1106,43 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1105 |
const isClosedMode = wb.phaseMode === 'closed' || wb.phaseMode === 'taotie_closed' || wb.hidden === true;
|
| 1106 |
// 若為第一期饕餮,若手動關閉或非開放模式且日期已過截止日,則視為已圓滿收起(地圖不呈現圖標)
|
| 1107 |
const isTaotieConcluded = (bossCfg.id === 'taotie') && (isClosedMode || (wb.phaseMode !== 'open' && today > (WORLD_BOSS_END_DATE || '2026-11-01')));
|
| 1108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1109 |
const isDirectOpen = wb.phaseMode === 'open';
|
| 1110 |
const isUnlockedDate = (isScheduledMode ? !isCountdown : (isDirectOpen || isEventOpen('boss', classInfo, today))) && !isPreviewMode && !isClosedMode && !isExpired;
|
| 1111 |
const isReqPassed = (progress?.[reqUnit]?.best || 0) >= PASS_SCORE;
|
| 1112 |
const unlocked = isUnlockedDate && !isExpired && isReqPassed;
|
| 1113 |
|
| 1114 |
-
// 討伐令計算(每日 3 次 + 額外購買/贈送討伐令)
|
| 1115 |
-
const extraOrders = (
|
| 1116 |
? Math.max(0, Number(game?.extraBossOrders) || 0)
|
| 1117 |
: 0;
|
| 1118 |
const maxOrders = 3 + extraOrders;
|
|
@@ -1123,13 +1153,8 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1123 |
const dRec = wb.damages[effUid];
|
| 1124 |
if (dRec.dailyUsed && typeof dRec.dailyUsed[today] === 'number') {
|
| 1125 |
wbDailyUsed = Math.max(0, Number(dRec.dailyUsed[today]) || 0);
|
| 1126 |
-
} else if (dRec.lastDate === today) {
|
| 1127 |
-
wbDailyUsed = Math.max(0, Number(dRec.todayCount
|
| 1128 |
-
} else if (typeof dRec.lastAt === 'number' && todayStr(new Date(dRec.lastAt)) === today) {
|
| 1129 |
-
const openDateStr = Number.isFinite(openAt) ? todayStr(new Date(openAt)) : '';
|
| 1130 |
-
if (openDateStr === today) {
|
| 1131 |
-
wbDailyUsed = Math.max(0, Number(dRec.attacksCount) || 0);
|
| 1132 |
-
}
|
| 1133 |
}
|
| 1134 |
}
|
| 1135 |
let hwmUsed = 0;
|
|
@@ -1145,12 +1170,16 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1145 |
} catch (e) {}
|
| 1146 |
}
|
| 1147 |
|
| 1148 |
-
// 🛡️ 權威戰報降噪校準:若班級伺服器戰報
|
| 1149 |
-
//
|
| 1150 |
let used = Math.max(gameUsed, wbDailyUsed, hwmUsed);
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1154 |
used = authDailyUsed;
|
| 1155 |
if (typeof localStorage !== 'undefined') {
|
| 1156 |
try {
|
|
@@ -1158,6 +1187,13 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1158 |
} catch (e) {}
|
| 1159 |
}
|
| 1160 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1161 |
}
|
| 1162 |
const ordersLeft = Math.max(0, maxOrders - used);
|
| 1163 |
|
|
@@ -1228,6 +1264,7 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1228 |
isTaotieConcluded,
|
| 1229 |
isUnlockedDate,
|
| 1230 |
isExpired,
|
|
|
|
| 1231 |
ordersLeft,
|
| 1232 |
maxOrders,
|
| 1233 |
usedOrders: used,
|
|
@@ -1240,7 +1277,8 @@ export function calcWorldBossStatus(classInfo, progress, game, today = todayStr(
|
|
| 1240 |
pctFloat,
|
| 1241 |
killer: wb.killer || null,
|
| 1242 |
damages: wb.damages || {},
|
| 1243 |
-
chargeThresholds: wb.chargeThresholds || null
|
|
|
|
| 1244 |
};
|
| 1245 |
}
|
| 1246 |
|
|
|
|
| 7 |
OPEN_OFFSET_DAYS, DEFAULT_OPEN_HOUR, SYSTEMS, WEEKLY_SCHEDULE, SLOTH_PENALTY_MULT,
|
| 8 |
EVENTS_CONFIG, WORLD_BOSS_ROSTER, WORLD_BOSS_END_DATE, MERCHANT,
|
| 9 |
ERA2_TALLY_COST, ERA2_BASE_PROD, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES,
|
| 10 |
+
} from './config.js?v=20261114_v2';
|
| 11 |
+
import { todayStr, addDays } from './util.js?v=20261114_v2';
|
| 12 |
+
import { normalizeWorldBossState, getScheduledOpenTs, formatCountdown, formatOpenAt } from './world-boss-schedule.js?v=20261114_v2';
|
| 13 |
+
import { resolveWeeklySpotlight } from './event-schedule.js?v=20261114_v2';
|
| 14 |
export { normalizeWorldBossState, formatCountdown, formatOpenAt };
|
| 15 |
export { todayStr, REVIEW_MAX_QUESTIONS, WORLD_BOSS_ROSTER, ERA2_TALLY_COST, ERA2_BASE_PROD, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES };
|
| 16 |
|
|
|
|
| 1106 |
const isClosedMode = wb.phaseMode === 'closed' || wb.phaseMode === 'taotie_closed' || wb.hidden === true;
|
| 1107 |
// 若為第一期饕餮,若手動關閉或非開放模式且日期已過截止日,則視為已圓滿收起(地圖不呈現圖標)
|
| 1108 |
const isTaotieConcluded = (bossCfg.id === 'taotie') && (isClosedMode || (wb.phaseMode !== 'open' && today > (WORLD_BOSS_END_DATE || '2026-11-01')));
|
| 1109 |
+
|
| 1110 |
+
// 2026-11-16 起:舊版未設定 weeklySpotlight 且無 cycleId 之窮奇,僅在教師尚未確認結清且仍有未領獎學生時保留「僅限領獎」入口
|
| 1111 |
+
const spotlightInfo = classInfo?.weeklySpotlight ? resolveWeeklySpotlight(classInfo, nowTs) : null;
|
| 1112 |
+
const isYinYangPre = !!bossCfg.isYinYang || bossCfg.id === 'qiongqi';
|
| 1113 |
+
const preDefeated = !!wb.defeated || (isYinYangPre
|
| 1114 |
+
? (typeof wb.yangHp === 'number' && typeof wb.yinHp === 'number' && wb.yangHp <= 0 && wb.yinHp <= 0)
|
| 1115 |
+
: (typeof wb.curHp === 'number' && wb.curHp <= 0));
|
| 1116 |
+
let isLegacyExpired = false;
|
| 1117 |
+
let claimOnlyAfterEnd = false;
|
| 1118 |
+
if (!wb.cycleId) {
|
| 1119 |
+
if (spotlightInfo && spotlightInfo.eventId !== 'boss') {
|
| 1120 |
+
const myClaimed = hasClaimedBossReward(game, bossCfg.id);
|
| 1121 |
+
const alreadySettledOrCleared = Boolean(classInfo?.legacyBossClearedAt || classInfo?.bossSettlements?.[bossCfg.id]);
|
| 1122 |
+
if (alreadySettledOrCleared || myClaimed || !preDefeated) {
|
| 1123 |
+
isLegacyExpired = true;
|
| 1124 |
+
} else {
|
| 1125 |
+
claimOnlyAfterEnd = true;
|
| 1126 |
+
}
|
| 1127 |
+
} else if (!spotlightInfo && String(today) >= '2026-11-16') {
|
| 1128 |
+
const myClaimed = hasClaimedBossReward(game, bossCfg.id);
|
| 1129 |
+
const alreadySettledOrCleared = Boolean(classInfo?.legacyBossClearedAt || classInfo?.bossSettlements?.[bossCfg.id] || isClosedMode);
|
| 1130 |
+
if (alreadySettledOrCleared || myClaimed || !preDefeated) {
|
| 1131 |
+
isLegacyExpired = true;
|
| 1132 |
+
} else {
|
| 1133 |
+
claimOnlyAfterEnd = true;
|
| 1134 |
+
}
|
| 1135 |
+
}
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
const isExpired = isClosedMode || isTaotieConcluded || isLegacyExpired || (bossCfg.id === 'taotie' ? !!(WORLD_BOSS_END_DATE && today > WORLD_BOSS_END_DATE) : false);
|
| 1139 |
const isDirectOpen = wb.phaseMode === 'open';
|
| 1140 |
const isUnlockedDate = (isScheduledMode ? !isCountdown : (isDirectOpen || isEventOpen('boss', classInfo, today))) && !isPreviewMode && !isClosedMode && !isExpired;
|
| 1141 |
const isReqPassed = (progress?.[reqUnit]?.best || 0) >= PASS_SCORE;
|
| 1142 |
const unlocked = isUnlockedDate && !isExpired && isReqPassed;
|
| 1143 |
|
| 1144 |
+
// 討伐令計算(每日 3 次 + 額外購買/贈送討伐令,嚴格限定當日 extraBossOrdersDate === today)
|
| 1145 |
+
const extraOrders = (game?.extraBossOrdersDate === today)
|
| 1146 |
? Math.max(0, Number(game?.extraBossOrders) || 0)
|
| 1147 |
: 0;
|
| 1148 |
const maxOrders = 3 + extraOrders;
|
|
|
|
| 1153 |
const dRec = wb.damages[effUid];
|
| 1154 |
if (dRec.dailyUsed && typeof dRec.dailyUsed[today] === 'number') {
|
| 1155 |
wbDailyUsed = Math.max(0, Number(dRec.dailyUsed[today]) || 0);
|
| 1156 |
+
} else if (dRec.lastDate === today && typeof dRec.todayCount === 'number') {
|
| 1157 |
+
wbDailyUsed = Math.max(0, Number(dRec.todayCount) || 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1158 |
}
|
| 1159 |
}
|
| 1160 |
let hwmUsed = 0;
|
|
|
|
| 1170 |
} catch (e) {}
|
| 1171 |
}
|
| 1172 |
|
| 1173 |
+
// 🛡️ 權威戰報降噪校準:若班級伺服器戰報已載入(damages 存在,即使今日尚無出征紀錄亦視為 0 次),
|
| 1174 |
+
// 且本地 hwmUsed 或 gameUsed 異常大於 maxOrders,以伺服器權威次數為準校準修正,並洗滌本地髒高水位快取!
|
| 1175 |
let used = Math.max(gameUsed, wbDailyUsed, hwmUsed);
|
| 1176 |
+
const hasAuthDamagesMap = Boolean(effUid && wb && typeof wb.damages === 'object');
|
| 1177 |
+
const hasAuthDailyEntry = Boolean(effUid && wb?.damages?.[effUid]?.dailyUsed?.[today] !== undefined);
|
| 1178 |
+
if (used > maxOrders && (hasAuthDailyEntry || hasAuthDamagesMap)) {
|
| 1179 |
+
const authDailyUsed = hasAuthDailyEntry
|
| 1180 |
+
? Math.max(0, Number(wb.damages[effUid].dailyUsed[today]) || 0)
|
| 1181 |
+
: wbDailyUsed;
|
| 1182 |
+
if (authDailyUsed <= maxOrders) {
|
| 1183 |
used = authDailyUsed;
|
| 1184 |
if (typeof localStorage !== 'undefined') {
|
| 1185 |
try {
|
|
|
|
| 1187 |
} catch (e) {}
|
| 1188 |
}
|
| 1189 |
}
|
| 1190 |
+
} else if (hwmUsed > maxOrders && Math.max(gameUsed, wbDailyUsed) <= maxOrders) {
|
| 1191 |
+
used = Math.max(gameUsed, wbDailyUsed);
|
| 1192 |
+
if (effUid && typeof localStorage !== 'undefined') {
|
| 1193 |
+
try {
|
| 1194 |
+
localStorage.setItem('idle_boss_hwm_' + effUid, JSON.stringify({ date: today, used }));
|
| 1195 |
+
} catch (e) {}
|
| 1196 |
+
}
|
| 1197 |
}
|
| 1198 |
const ordersLeft = Math.max(0, maxOrders - used);
|
| 1199 |
|
|
|
|
| 1264 |
isTaotieConcluded,
|
| 1265 |
isUnlockedDate,
|
| 1266 |
isExpired,
|
| 1267 |
+
claimOnlyAfterEnd,
|
| 1268 |
ordersLeft,
|
| 1269 |
maxOrders,
|
| 1270 |
usedOrders: used,
|
|
|
|
| 1277 |
pctFloat,
|
| 1278 |
killer: wb.killer || null,
|
| 1279 |
damages: wb.damages || {},
|
| 1280 |
+
chargeThresholds: wb.chargeThresholds || null,
|
| 1281 |
+
questionMode: wb.questionMode || 'auto'
|
| 1282 |
};
|
| 1283 |
}
|
| 1284 |
|
js/event-schedule.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// js/event-schedule.js
|
| 3 |
+
// 可插拔週期活動排程解析與快閃/奇數週預設產生器(純函數,無副作用)
|
| 4 |
+
// - 嚴格以東八區 (Asia/Taipei, UTC+8) 判定日期與週次
|
| 5 |
+
// - 零循環依賴:僅依賴 config.js、util.js、world-boss-schedule.js
|
| 6 |
+
// ============================================================================
|
| 7 |
+
import { EVENT_CATALOG, PASS_SCORE, WORLD_BOSS_ROSTER } from './config.js?v=20261114_v2';
|
| 8 |
+
import { todayStr } from './util.js?v=20261114_v2';
|
| 9 |
+
import { toTs } from './world-boss-schedule.js?v=20261114_v2';
|
| 10 |
+
|
| 11 |
+
const TAIPEI_OFFSET_MS = 8 * 3600 * 1000;
|
| 12 |
+
const CARAVAN_ANCHOR_MS = Date.parse('2026-11-02T00:00:00+08:00');
|
| 13 |
+
const DAY_MS = 86400 * 1000;
|
| 14 |
+
|
| 15 |
+
/** 取得東八區 UTC 對齊物件(透過 getUTC* 讀取台北年月日時分秒與星期) */
|
| 16 |
+
function toTaipeiUtcView(now = new Date()) {
|
| 17 |
+
const ts = typeof now === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(now)
|
| 18 |
+
? Date.parse(`${now}T12:00:00+08:00`)
|
| 19 |
+
: toTs(now);
|
| 20 |
+
const safeTs = Number.isFinite(ts) ? ts : Date.now();
|
| 21 |
+
return { ts: safeTs, d: new Date(safeTs + TAIPEI_OFFSET_MS) };
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/** 計算東八區 YYYY-MM-DD 與週次資訊 */
|
| 25 |
+
export function getTaipeiWeekKey(now = new Date()) {
|
| 26 |
+
const { d } = toTaipeiUtcView(now);
|
| 27 |
+
// 依 ISO-8601 算法對東八區日期取年週(如 2026-11-23 → '2026w48')
|
| 28 |
+
const utcMid = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
|
| 29 |
+
const dayNum = utcMid.getUTCDay() || 7;
|
| 30 |
+
utcMid.setUTCDate(utcMid.getUTCDate() + 4 - dayNum);
|
| 31 |
+
const yearStart = new Date(Date.UTC(utcMid.getUTCFullYear(), 0, 1));
|
| 32 |
+
const weekNo = Math.ceil((((utcMid - yearStart) / DAY_MS) + 1) / 7);
|
| 33 |
+
return `${utcMid.getUTCFullYear()}w${String(weekNo).padStart(2, '0')}`;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/** 取得台北基準當週是否為偶數「西域商隊週」 */
|
| 37 |
+
export function isTaipeiCaravanWeek(now = new Date()) {
|
| 38 |
+
const { d } = toTaipeiUtcView(now);
|
| 39 |
+
const dayStartTs = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()) - TAIPEI_OFFSET_MS;
|
| 40 |
+
const diffDays = Math.floor((dayStartTs - CARAVAN_ANCHOR_MS) / DAY_MS);
|
| 41 |
+
if (diffDays < 0) return false;
|
| 42 |
+
const weekIdx = Math.floor(diffDays / 7);
|
| 43 |
+
return weekIdx % 2 === 0;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/** 取得東八區當週週一 07:00 至週日 23:59:59.999 毫秒區間 */
|
| 47 |
+
export function getTaipeiWeekBounds(now = new Date()) {
|
| 48 |
+
const { d } = toTaipeiUtcView(now);
|
| 49 |
+
const weekday = (d.getUTCDay() + 6) % 7; // Mon=0 .. Sun=6
|
| 50 |
+
const monMidnightTs = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() - weekday) - TAIPEI_OFFSET_MS;
|
| 51 |
+
const sunEndTs = monMidnightTs + 7 * DAY_MS - 1;
|
| 52 |
+
return {
|
| 53 |
+
openAt: monMidnightTs + 7 * 3600 * 1000,
|
| 54 |
+
endAt: sunEndTs,
|
| 55 |
+
};
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/** 將時間區間格式化為簡潔台北日期字串 */
|
| 59 |
+
export function formatCycleRangeLabel(openAt, endAt) {
|
| 60 |
+
const fmt = (ms) => {
|
| 61 |
+
const t = toTs(ms);
|
| 62 |
+
if (!Number.isFinite(t)) return '';
|
| 63 |
+
const d = new Date(t + TAIPEI_OFFSET_MS);
|
| 64 |
+
const wk = ['日', '一', '二', '三', '四', '五', '六'][d.getUTCDay()];
|
| 65 |
+
const hh = String(d.getUTCHours()).padStart(2, '0');
|
| 66 |
+
const mm = String(d.getUTCMinutes()).padStart(2, '0');
|
| 67 |
+
return `${d.getUTCMonth() + 1}/${d.getUTCDate()}(${wk}) ${hh}:${mm}`;
|
| 68 |
+
};
|
| 69 |
+
const s = fmt(openAt);
|
| 70 |
+
const e = fmt(endAt);
|
| 71 |
+
return s && e ? `${s} ~ ${e}` : (s || e || '未排程');
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* 解析班級當下有效之「錯題主打活動(weeklySpotlight)」
|
| 76 |
+
* - 奇數週未選定或為 'none' → active: false(安全休兵)
|
| 77 |
+
* - 偶數商隊週 → 預設不開放主打,除非明確標記 allowDuringCaravan: true(如週四快閃測試)
|
| 78 |
+
* - 超過 endAt 或教師手動 closedAt → 自動收起隱藏(active: false)
|
| 79 |
+
*/
|
| 80 |
+
export function resolveWeeklySpotlight(classInfo = {}, now = new Date()) {
|
| 81 |
+
const { ts: nowTs } = toTaipeiUtcView(now);
|
| 82 |
+
const isCaravanWeek = isTaipeiCaravanWeek(nowTs);
|
| 83 |
+
const sp = classInfo?.weeklySpotlight;
|
| 84 |
+
|
| 85 |
+
if (!sp || typeof sp !== 'object' || !sp.eventId || sp.eventId === 'none') {
|
| 86 |
+
return {
|
| 87 |
+
active: false,
|
| 88 |
+
reason: 'none',
|
| 89 |
+
eventId: 'none',
|
| 90 |
+
cycleId: null,
|
| 91 |
+
subId: null,
|
| 92 |
+
questionMode: 'mixed',
|
| 93 |
+
isCaravanWeek,
|
| 94 |
+
allowDuringCaravan: false,
|
| 95 |
+
openAt: null,
|
| 96 |
+
endAt: null,
|
| 97 |
+
isBeforeOpen: false,
|
| 98 |
+
isExpired: false,
|
| 99 |
+
isClosed: false,
|
| 100 |
+
countdownMs: 0,
|
| 101 |
+
};
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
const eventId = String(sp.eventId);
|
| 105 |
+
const cycleId = sp.cycleId || null;
|
| 106 |
+
const allowDuringCaravan = sp.allowDuringCaravan === true;
|
| 107 |
+
const openAt = Number.isFinite(toTs(sp.openAt)) ? toTs(sp.openAt) : null;
|
| 108 |
+
const endAt = Number.isFinite(toTs(sp.endAt)) ? toTs(sp.endAt) : null;
|
| 109 |
+
const closedAt = Number.isFinite(toTs(sp.closedAt)) ? toTs(sp.closedAt) : null;
|
| 110 |
+
|
| 111 |
+
const cycleDoc = eventId === 'lottery' && cycleId
|
| 112 |
+
? classInfo?.lotteryCycles?.[cycleId]
|
| 113 |
+
: (eventId === 'boss' && cycleId ? classInfo?.bossCycles?.[cycleId] : null);
|
| 114 |
+
const cycleStatus = cycleDoc?.status || 'open';
|
| 115 |
+
const prizeMode = cycleDoc?.prizeMode || sp.prizeMode || 'standard';
|
| 116 |
+
const milestones = Array.isArray(cycleDoc?.milestones) ? cycleDoc.milestones : null;
|
| 117 |
+
const questionMode = cycleDoc?.questionMode || sp.questionMode || 'mixed';
|
| 118 |
+
const effectiveOpenAt = Number.isFinite(toTs(cycleDoc?.openAt)) ? toTs(cycleDoc.openAt) : openAt;
|
| 119 |
+
const effectiveEndAt = Number.isFinite(toTs(cycleDoc?.endAt)) ? toTs(cycleDoc.endAt) : endAt;
|
| 120 |
+
|
| 121 |
+
const base = {
|
| 122 |
+
eventId,
|
| 123 |
+
cycleId,
|
| 124 |
+
subId: sp.subId || null,
|
| 125 |
+
questionMode,
|
| 126 |
+
prizeMode,
|
| 127 |
+
milestones,
|
| 128 |
+
cycleStatus,
|
| 129 |
+
catalogEntry: EVENT_CATALOG[eventId] || null,
|
| 130 |
+
isCaravanWeek,
|
| 131 |
+
allowDuringCaravan,
|
| 132 |
+
openAt: effectiveOpenAt,
|
| 133 |
+
endAt: effectiveEndAt,
|
| 134 |
+
countdownMs: 0,
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
if (isCaravanWeek && !allowDuringCaravan) {
|
| 138 |
+
return { ...base, active: false, reason: 'caravan_week', isBeforeOpen: false, isExpired: false, isClosed: false };
|
| 139 |
+
}
|
| 140 |
+
if (cycleStatus === 'voided' || cycleStatus === 'closed' || (closedAt !== null && nowTs >= closedAt)) {
|
| 141 |
+
return { ...base, active: false, reason: cycleStatus === 'voided' ? 'voided' : 'closed', isBeforeOpen: false, isExpired: false, isClosed: true };
|
| 142 |
+
}
|
| 143 |
+
if (effectiveOpenAt !== null && nowTs < effectiveOpenAt) {
|
| 144 |
+
return {
|
| 145 |
+
...base,
|
| 146 |
+
active: false,
|
| 147 |
+
reason: 'before_open',
|
| 148 |
+
isBeforeOpen: true,
|
| 149 |
+
isExpired: false,
|
| 150 |
+
isClosed: false,
|
| 151 |
+
countdownMs: Math.max(0, effectiveOpenAt - nowTs),
|
| 152 |
+
};
|
| 153 |
+
}
|
| 154 |
+
if (effectiveEndAt !== null && nowTs > effectiveEndAt) {
|
| 155 |
+
return { ...base, active: false, reason: 'expired', isBeforeOpen: false, isExpired: true, isClosed: false };
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
return {
|
| 159 |
+
...base,
|
| 160 |
+
active: true,
|
| 161 |
+
reason: 'open',
|
| 162 |
+
isBeforeOpen: false,
|
| 163 |
+
isExpired: false,
|
| 164 |
+
isClosed: false,
|
| 165 |
+
};
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/** 產生「本週四 2026-11-19 快閃錯題樂透預設」(週五自動對學生收起以便開獎) */
|
| 169 |
+
export function buildPilotLotterySpotlightPreset({
|
| 170 |
+
cycleId = 'lotto_pilot_20261119',
|
| 171 |
+
openAt = '2026-11-19T07:00:00+08:00',
|
| 172 |
+
endAt = '2026-11-19T23:59:59+08:00',
|
| 173 |
+
milestones = [45, 90, 140],
|
| 174 |
+
questionMode = 'mixed',
|
| 175 |
+
prizeMode = 'pilot',
|
| 176 |
+
maxDailyRounds = 2,
|
| 177 |
+
} = {}) {
|
| 178 |
+
const openTs = toTs(openAt);
|
| 179 |
+
const endTs = toTs(endAt);
|
| 180 |
+
const now = Date.now();
|
| 181 |
+
return {
|
| 182 |
+
weeklySpotlight: {
|
| 183 |
+
weekKey: '2026w47_pilot',
|
| 184 |
+
eventId: 'lottery',
|
| 185 |
+
cycleId,
|
| 186 |
+
subId: null,
|
| 187 |
+
allowDuringCaravan: true,
|
| 188 |
+
prizeMode,
|
| 189 |
+
questionMode,
|
| 190 |
+
openAt: openTs,
|
| 191 |
+
endAt: endTs,
|
| 192 |
+
closedAt: null,
|
| 193 |
+
updatedAt: now,
|
| 194 |
+
},
|
| 195 |
+
lotteryCycle: {
|
| 196 |
+
cycleId,
|
| 197 |
+
title: '週四快閃錯題樂透(試營運)',
|
| 198 |
+
status: 'open',
|
| 199 |
+
prizeMode,
|
| 200 |
+
themeId: 'pilot_flash',
|
| 201 |
+
questionMode,
|
| 202 |
+
maxDailyRounds,
|
| 203 |
+
milestones: [...milestones],
|
| 204 |
+
openAt: openTs,
|
| 205 |
+
endAt: endTs,
|
| 206 |
+
entries: {},
|
| 207 |
+
drawResult: null,
|
| 208 |
+
updatedAt: now,
|
| 209 |
+
},
|
| 210 |
+
};
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/** 產生指定奇數週之主打活動設定(預設涵蓋該週一 07:00 ~ 週日 23:59:59) */
|
| 214 |
+
export function buildOddWeekSpotlightPreset({
|
| 215 |
+
eventId = 'lottery',
|
| 216 |
+
now = new Date(),
|
| 217 |
+
subId = null,
|
| 218 |
+
questionMode = 'mixed',
|
| 219 |
+
milestones = [150, 280, 420],
|
| 220 |
+
prizeMode = 'standard',
|
| 221 |
+
allowDuringCaravan = false,
|
| 222 |
+
} = {}) {
|
| 223 |
+
const weekKey = getTaipeiWeekKey(now);
|
| 224 |
+
const { openAt, endAt } = getTaipeiWeekBounds(now);
|
| 225 |
+
const prefix = eventId === 'boss' ? 'boss' : 'lotto';
|
| 226 |
+
const cycleId = `${prefix}_${weekKey}`;
|
| 227 |
+
const updatedAt = Date.now();
|
| 228 |
+
const weeklySpotlight = {
|
| 229 |
+
weekKey,
|
| 230 |
+
eventId,
|
| 231 |
+
cycleId: eventId === 'none' ? null : cycleId,
|
| 232 |
+
subId: eventId === 'boss' ? (subId || 'qiongqi') : null,
|
| 233 |
+
allowDuringCaravan: Boolean(allowDuringCaravan),
|
| 234 |
+
prizeMode,
|
| 235 |
+
questionMode,
|
| 236 |
+
openAt,
|
| 237 |
+
endAt,
|
| 238 |
+
closedAt: null,
|
| 239 |
+
updatedAt,
|
| 240 |
+
};
|
| 241 |
+
const cycle = eventId === 'lottery'
|
| 242 |
+
? {
|
| 243 |
+
cycleId,
|
| 244 |
+
title: `錯題樂透(${weekKey})`,
|
| 245 |
+
status: 'open',
|
| 246 |
+
prizeMode,
|
| 247 |
+
themeId: 'classic_gold',
|
| 248 |
+
questionMode,
|
| 249 |
+
maxDailyRounds: 2,
|
| 250 |
+
milestones: [...milestones],
|
| 251 |
+
openAt,
|
| 252 |
+
endAt,
|
| 253 |
+
entries: {},
|
| 254 |
+
drawResult: null,
|
| 255 |
+
updatedAt,
|
| 256 |
+
}
|
| 257 |
+
: null;
|
| 258 |
+
return { weekKey, cycleId, weeklySpotlight, cycle };
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/** 清查班級中尚未領取舊版世界 Boss(taotie/qiongqi)獎勵之有效學生(排除教師與 20 號測試號) */
|
| 262 |
+
export function findUnclaimedLegacyBossStudents(classInfo = {}, students = []) {
|
| 263 |
+
const wb = classInfo?.worldBoss;
|
| 264 |
+
if (!wb || !Array.isArray(students) || classInfo?.legacyBossClearedAt) return [];
|
| 265 |
+
const bossId = wb.bossId || 'taotie';
|
| 266 |
+
const bossCfg = WORLD_BOSS_ROSTER[bossId] || WORLD_BOSS_ROSTER.taotie;
|
| 267 |
+
const reqUnit = bossCfg.unlockUnit || 'u3';
|
| 268 |
+
const isDefeated = Boolean(
|
| 269 |
+
wb.defeated ||
|
| 270 |
+
(bossCfg.isYinYang
|
| 271 |
+
? (Number(wb.yangHp ?? 1) <= 0 && Number(wb.yinHp ?? 1) <= 0)
|
| 272 |
+
: Number(wb.curHp ?? 1) <= 0)
|
| 273 |
+
);
|
| 274 |
+
const damages = wb.damages || {};
|
| 275 |
+
const settledInfo = classInfo?.bossSettlements?.[bossId];
|
| 276 |
+
|
| 277 |
+
const unclaimed = [];
|
| 278 |
+
for (const st of students) {
|
| 279 |
+
if (!st || !st.uid) continue;
|
| 280 |
+
if (st.role === 'teacher' || String(st.seat) === '20') continue;
|
| 281 |
+
const g = st.game || {};
|
| 282 |
+
const claimedLegacy = Boolean(
|
| 283 |
+
g?.boss?.claimed?.[bossId] ||
|
| 284 |
+
(bossId === 'taotie' && g?.boss?.rewardClaimed)
|
| 285 |
+
);
|
| 286 |
+
if (claimedLegacy || settledInfo) continue;
|
| 287 |
+
|
| 288 |
+
const dealtDmg = Number(damages[st.uid]?.dmg) || 0;
|
| 289 |
+
const unlocked = (st.progress?.[reqUnit]?.best || 0) >= PASS_SCORE;
|
| 290 |
+
if (dealtDmg > 0 || (isDefeated && unlocked)) {
|
| 291 |
+
unclaimed.push({
|
| 292 |
+
uid: st.uid,
|
| 293 |
+
seat: st.seat ?? '',
|
| 294 |
+
name: st.name || '無名將領',
|
| 295 |
+
dealtDmg,
|
| 296 |
+
});
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
return unclaimed.sort((a, b) => (Number(a.seat) || 999) - (Number(b.seat) || 999));
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
export function getActiveEventTodayStr(now = new Date()) {
|
| 303 |
+
const { ts } = toTaipeiUtcView(now);
|
| 304 |
+
return todayStr(new Date(ts));
|
| 305 |
+
}
|
tools/verify-integrity.mjs
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
| 41 |
getEventStatusInfo,
|
| 42 |
getCaravanRotation,
|
| 43 |
clickValue,
|
| 44 |
-
totalProd,
|
| 45 |
} from '../js/engine.js';
|
| 46 |
import {
|
| 47 |
getMerchantDayInfo,
|
|
@@ -52,9 +52,17 @@ import {
|
|
| 52 |
buyMerchantItem,
|
| 53 |
getCamelPreviewRange,
|
| 54 |
} from '../js/merchant.js';
|
| 55 |
-
import { BUILDINGS, MERCHANT, SCHEDULE, WEEKLY_SCHEDULE, APP_BUILD_VERSION, ERA2_TALLY_COST, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES } from '../js/config.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
import { renderRichQuizText, todayStr } from '../js/util.js';
|
| 57 |
import { rollChestRewards, evaluateChestRhythm, CHEST_RHYTHM_CFG } from '../js/tianji.js';
|
|
|
|
|
|
|
| 58 |
|
| 59 |
const ROOT = process.cwd();
|
| 60 |
let passedChecks = 0;
|
|
@@ -122,17 +130,17 @@ for (const file of jsFiles) {
|
|
| 122 |
|
| 123 |
// 在模擬瀏覽器 DOM 環境下真實 import() 載入核心模組(攔截如 ReferenceError: exitToMap is not defined 等頂層執行期錯誤)
|
| 124 |
globalThis.window = globalThis;
|
| 125 |
-
globalThis.location = { search: '?demo=1', href: 'http://localhost/?demo=1', pathname: '/', reload: () => {} };
|
| 126 |
-
globalThis.history = { replaceState: () => {} };
|
| 127 |
-
globalThis.localStorage = { getItem: () => null, setItem: () => {}, removeItem: () => {} };
|
| 128 |
-
globalThis.sessionStorage = { getItem: () => null, setItem: () => {}, removeItem: () => {} };
|
| 129 |
globalThis.performance = globalThis.performance || { now: () => Date.now() };
|
| 130 |
globalThis.requestAnimationFrame = () => 1;
|
| 131 |
-
globalThis.cancelAnimationFrame = () => {};
|
| 132 |
-
globalThis.addEventListener = () => {};
|
| 133 |
-
globalThis.removeEventListener = () => {};
|
| 134 |
globalThis.confirm = () => false;
|
| 135 |
-
globalThis.alert = () => {};
|
| 136 |
globalThis.fetch = async (url) => ({
|
| 137 |
ok: true,
|
| 138 |
json: async () => (String(url).includes('index.json') ? [] : { questions: [], words: [] }),
|
|
@@ -144,14 +152,14 @@ const makeDummyEl = () => ({
|
|
| 144 |
innerHTML: '',
|
| 145 |
value: '',
|
| 146 |
disabled: false,
|
| 147 |
-
classList: { add: () => {}, remove: () => {}, toggle: () => false, contains: () => false },
|
| 148 |
-
addEventListener: () => {},
|
| 149 |
-
removeEventListener: () => {},
|
| 150 |
querySelector: () => makeDummyEl(),
|
| 151 |
querySelectorAll: () => [],
|
| 152 |
-
appendChild: () => {},
|
| 153 |
-
remove: () => {},
|
| 154 |
-
setAttribute: () => {},
|
| 155 |
closest: () => null,
|
| 156 |
});
|
| 157 |
globalThis.document = {
|
|
@@ -163,8 +171,8 @@ globalThis.document = {
|
|
| 163 |
querySelector: () => makeDummyEl(),
|
| 164 |
querySelectorAll: () => [],
|
| 165 |
createElement: () => makeDummyEl(),
|
| 166 |
-
addEventListener: () => {},
|
| 167 |
-
removeEventListener: () => {},
|
| 168 |
};
|
| 169 |
|
| 170 |
for (const file of jsFiles) {
|
|
@@ -675,19 +683,55 @@ assert.equal(b2InfoBefore.canUpgrade, false, 'B1 昇華前 B9 必須被前置鎖
|
|
| 675 |
assert.match(b2InfoBefore.lockReason, /需先將前置名都【景陽瓷都】升級至第二紀元/, '鎖定原因提示正確');
|
| 676 |
|
| 677 |
// 昇華 B1
|
|
|
|
| 678 |
const prevB1Prod = buildingProd(BUILDINGS[0], gEra2.buildings.b1, derive({}, {}, gEra2));
|
| 679 |
const b1Res = evolveTownToEra2('b1', gEra2, {});
|
| 680 |
assert.equal(b1Res.ok, true, 'B1 昇華應成功');
|
| 681 |
assert.equal(gEra2.buildings.b1.era2, true, 'B1 era2 應標記為 true');
|
| 682 |
assert.equal(gEra2.blueprints, 75, '應扣除 25 兵符');
|
| 683 |
const newB1Prod = buildingProd(BUILDINGS[0], gEra2.buildings.b1, derive({}, {}, gEra2));
|
| 684 |
-
assert.equal(
|
|
|
|
|
|
|
|
|
|
| 685 |
|
| 686 |
// B1 昇華完成後,B2 達到 ★5 且前置滿足 -> 應可昇華
|
| 687 |
const b2InfoAfter = getEra2UpgradeInfo('b9', gEra2, {});
|
| 688 |
assert.equal(b2InfoAfter.canUpgrade, true, 'B1 昇華後 B9 應解除鎖定');
|
| 689 |
|
| 690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
|
| 692 |
// ----------------------------------------------------------------------------
|
| 693 |
// 11. 全軍共拓每週軍餉上限鎖定與同袍代捐防超捐檢驗 (Weekly Donation Cap Guard)
|
|
@@ -837,4 +881,374 @@ assert.equal(rollChestRewards('silver', 100, { timingSuccess: true, rng: () => 0
|
|
| 837 |
assert.ok(CHEST_RHYTHM_CFG.goldBonusTwoTallyProb > CHEST_RHYTHM_CFG.goldBaseTwoTallyProb, '黃金箱節奏成功機率必須高於基礎值');
|
| 838 |
ok('天機閣寶箱震動開啟動畫類別、節奏桿判定與兵符微幅提升機制檢驗通過');
|
| 839 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
console.log(`\n🎉 全部 ${passedChecks} 大項工程防呆檢驗 100% 通過!可安全部署上線。`);
|
|
|
|
| 41 |
getEventStatusInfo,
|
| 42 |
getCaravanRotation,
|
| 43 |
clickValue,
|
| 44 |
+
totalProd, healYield,
|
| 45 |
} from '../js/engine.js';
|
| 46 |
import {
|
| 47 |
getMerchantDayInfo,
|
|
|
|
| 52 |
buyMerchantItem,
|
| 53 |
getCamelPreviewRange,
|
| 54 |
} from '../js/merchant.js';
|
| 55 |
+
import { BUILDINGS, MERCHANT, SCHEDULE, WEEKLY_SCHEDULE, APP_BUILD_VERSION, ERA2_TALLY_COST, ERA2_BASE_PROD, ERA2_SEQUENCE, ERA2_CONDITIONS, ERA2_TOWN_NAMES, EVENT_CATALOG, TITLE_DEFS } from '../js/config.js';
|
| 56 |
+
import {
|
| 57 |
+
resolveWeeklySpotlight,
|
| 58 |
+
buildPilotLotterySpotlightPreset,
|
| 59 |
+
buildOddWeekSpotlightPreset,
|
| 60 |
+
findUnclaimedLegacyBossStudents,
|
| 61 |
+
} from '../js/event-schedule.js';
|
| 62 |
import { renderRichQuizText, todayStr } from '../js/util.js';
|
| 63 |
import { rollChestRewards, evaluateChestRhythm, CHEST_RHYTHM_CFG } from '../js/tianji.js';
|
| 64 |
+
import { LocalBackend, settleBossDamageRecord, applyBossHighWaterMarkToGame } from '../js/db.js';
|
| 65 |
+
import { computeStudentAudit, cumStarCost } from '../.agents/skills/student-resource-audit/scripts/audit-student.js';
|
| 66 |
|
| 67 |
const ROOT = process.cwd();
|
| 68 |
let passedChecks = 0;
|
|
|
|
| 130 |
|
| 131 |
// 在模擬瀏覽器 DOM 環境下真實 import() 載入核心模組(攔截如 ReferenceError: exitToMap is not defined 等頂層執行期錯誤)
|
| 132 |
globalThis.window = globalThis;
|
| 133 |
+
globalThis.location = { search: '?demo=1', href: 'http://localhost/?demo=1', pathname: '/', reload: () => { } };
|
| 134 |
+
globalThis.history = { replaceState: () => { } };
|
| 135 |
+
globalThis.localStorage = { getItem: () => null, setItem: () => { }, removeItem: () => { } };
|
| 136 |
+
globalThis.sessionStorage = { getItem: () => null, setItem: () => { }, removeItem: () => { } };
|
| 137 |
globalThis.performance = globalThis.performance || { now: () => Date.now() };
|
| 138 |
globalThis.requestAnimationFrame = () => 1;
|
| 139 |
+
globalThis.cancelAnimationFrame = () => { };
|
| 140 |
+
globalThis.addEventListener = () => { };
|
| 141 |
+
globalThis.removeEventListener = () => { };
|
| 142 |
globalThis.confirm = () => false;
|
| 143 |
+
globalThis.alert = () => { };
|
| 144 |
globalThis.fetch = async (url) => ({
|
| 145 |
ok: true,
|
| 146 |
json: async () => (String(url).includes('index.json') ? [] : { questions: [], words: [] }),
|
|
|
|
| 152 |
innerHTML: '',
|
| 153 |
value: '',
|
| 154 |
disabled: false,
|
| 155 |
+
classList: { add: () => { }, remove: () => { }, toggle: () => false, contains: () => false },
|
| 156 |
+
addEventListener: () => { },
|
| 157 |
+
removeEventListener: () => { },
|
| 158 |
querySelector: () => makeDummyEl(),
|
| 159 |
querySelectorAll: () => [],
|
| 160 |
+
appendChild: () => { },
|
| 161 |
+
remove: () => { },
|
| 162 |
+
setAttribute: () => { },
|
| 163 |
closest: () => null,
|
| 164 |
});
|
| 165 |
globalThis.document = {
|
|
|
|
| 171 |
querySelector: () => makeDummyEl(),
|
| 172 |
querySelectorAll: () => [],
|
| 173 |
createElement: () => makeDummyEl(),
|
| 174 |
+
addEventListener: () => { },
|
| 175 |
+
removeEventListener: () => { },
|
| 176 |
};
|
| 177 |
|
| 178 |
for (const file of jsFiles) {
|
|
|
|
| 683 |
assert.match(b2InfoBefore.lockReason, /需先將前置名都【景陽瓷都】升級至第二紀元/, '鎖定原因提示正確');
|
| 684 |
|
| 685 |
// 昇華 B1
|
| 686 |
+
gEra2.buildings.b1.lv = 10;
|
| 687 |
const prevB1Prod = buildingProd(BUILDINGS[0], gEra2.buildings.b1, derive({}, {}, gEra2));
|
| 688 |
const b1Res = evolveTownToEra2('b1', gEra2, {});
|
| 689 |
assert.equal(b1Res.ok, true, 'B1 昇華應成功');
|
| 690 |
assert.equal(gEra2.buildings.b1.era2, true, 'B1 era2 應標記為 true');
|
| 691 |
assert.equal(gEra2.blueprints, 75, '應扣除 25 兵符');
|
| 692 |
const newB1Prod = buildingProd(BUILDINGS[0], gEra2.buildings.b1, derive({}, {}, gEra2));
|
| 693 |
+
assert.equal(gEra2.buildings.b1.star, 0, 'B1 飛升後星級應重鑄歸零 (0★)');
|
| 694 |
+
assert.equal(gEra2.peakBuildings.b1.maxStar, 0, 'B1 peakBuildings.maxStar 應同步歸零');
|
| 695 |
+
assert.ok(prevB1Prod > 0 && newB1Prod > prevB1Prod, 'B1 飛升後秒產必須嚴格大於飛升前 ★5 秒產');
|
| 696 |
+
assert.equal(newB1Prod, prevB1Prod * (ERA2_BASE_PROD.b1 / (BUILDINGS[0].baseProd * 32)), '第二紀元產量應完成時代基底重鑄(由 ★5 躍升至 ERA2_BASE_PROD.b1 且星級歸 0)');
|
| 697 |
|
| 698 |
// B1 昇華完成後,B2 達到 ★5 且前置滿足 -> 應可昇華
|
| 699 |
const b2InfoAfter = getEra2UpgradeInfo('b9', gEra2, {});
|
| 700 |
assert.equal(b2InfoAfter.canUpgrade, true, 'B1 昇華後 B9 應解除鎖定');
|
| 701 |
|
| 702 |
+
// 10.4 全 10 座城鎮依序飛升均必須滿 ★5(含 ★6 超星)且飛升後全數變回 0 星、擴軍 +1 預估正成長
|
| 703 |
+
const dEra2Test = derive({}, {}, gEra2);
|
| 704 |
+
gEra2.blueprints = 500;
|
| 705 |
+
for (let idx = 1; idx < ERA2_SEQUENCE.length; idx++) {
|
| 706 |
+
const bId = ERA2_SEQUENCE[idx];
|
| 707 |
+
const bDef = BUILDINGS.find(x => x.id === bId);
|
| 708 |
+
gEra2.buildings[bId].lv = 20;
|
| 709 |
+
gEra2.buildings[bId].star = (bId === 'b8') ? 6 : 5;
|
| 710 |
+
const res = evolveTownToEra2(bId, gEra2, {});
|
| 711 |
+
assert.equal(res.ok, true, `${bId} 應可於前置昇華且滿 5 星後順利飛升`);
|
| 712 |
+
assert.equal(gEra2.buildings[bId].era2, true, `${bId} era2 應標記為 true`);
|
| 713 |
+
assert.equal(gEra2.buildings[bId].star, 0, `${bId} 飛升後星級必須重鑄歸 0`);
|
| 714 |
+
assert.equal(gEra2.peakBuildings[bId].era2, true, `${bId} peakBuildings.era2 應標記為 true`);
|
| 715 |
+
assert.equal(gEra2.peakBuildings[bId].maxStar, 0, `${bId} peakBuildings.maxStar 必須同步歸 0`);
|
| 716 |
+
|
| 717 |
+
const curP = buildingProd(bDef, gEra2.buildings[bId], dEra2Test);
|
| 718 |
+
const nextP = buildingProd(bDef, { ...gEra2.buildings[bId], lv: gEra2.buildings[bId].lv + 1 }, dEra2Test);
|
| 719 |
+
assert.ok(nextP - curP > 0, `${bId} 飛升後擴軍 +1 預估產量增量必須為正值`);
|
| 720 |
+
}
|
| 721 |
+
const normAllEra2 = normalizeGame(gEra2);
|
| 722 |
+
healYield(normAllEra2);
|
| 723 |
+
for (const bId of ERA2_SEQUENCE) {
|
| 724 |
+
assert.equal(normAllEra2.buildings[bId].era2, true, `重讀與自癒後 ${bId} 仍應為第二紀元`);
|
| 725 |
+
assert.equal(normAllEra2.buildings[bId].star, 0, `重讀與自癒不可將已歸 0 星的 ${bId} 拉回 5 星`);
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
// 10.5 沙盤面板:移除「第二紀元傳世名都/已質變」橫幅,且擴軍預估保留完整建築狀態 (era2)
|
| 729 |
+
const mapJsSrc = fs.readFileSync(path.join(ROOT, 'js', 'map.js'), 'utf8');
|
| 730 |
+
assert.ok(!mapJsSrc.includes('第二紀元傳世名都'), 'js/map.js 不可再顯示「第二紀元傳世名都」橫幅訊息');
|
| 731 |
+
assert.ok(!mapJsSrc.includes('已質變'), 'js/map.js 不可再顯示「已質變」標籤');
|
| 732 |
+
assert.ok(mapJsSrc.includes('buildingProd(b, { ...st, lv: st.lv + amt }, dState)'), 'js/map.js 擴軍預估必須展開 st(保留 era2 屬性)');
|
| 733 |
+
|
| 734 |
+
ok('第二紀元四大誓約、兵符調升、全10城5星飛升歸0、產能質變與沙盤擴軍預估檢驗通過');
|
| 735 |
|
| 736 |
// ----------------------------------------------------------------------------
|
| 737 |
// 11. 全軍共拓每週軍餉上限鎖定與同袍代捐防超捐檢驗 (Weekly Donation Cap Guard)
|
|
|
|
| 881 |
assert.ok(CHEST_RHYTHM_CFG.goldBonusTwoTallyProb > CHEST_RHYTHM_CFG.goldBaseTwoTallyProb, '黃金箱節奏成功機率必須高於基礎值');
|
| 882 |
ok('天機閣寶箱震動開啟動畫類別、節奏桿判定與兵符微幅提升機制檢驗通過');
|
| 883 |
|
| 884 |
+
// ----------------------------------------------------------------------------
|
| 885 |
+
// 15. 世界 Boss P0 止血回歸檢驗(討伐令上限、HWM 自癒、傷害封頂、已擊敗不扣次數與防閃爍)
|
| 886 |
+
// ----------------------------------------------------------------------------
|
| 887 |
+
{
|
| 888 |
+
const today = todayStr();
|
| 889 |
+
|
| 890 |
+
// 15.1 缺少 extraBossOrdersDate 時絕不放寬至 >3 次
|
| 891 |
+
const stNoExtraDate = calcWorldBossStatus(
|
| 892 |
+
{ worldBoss: { bossId: 'qiongqi', phaseMode: 'open', damages: {} } },
|
| 893 |
+
{ u6: { best: 100 } },
|
| 894 |
+
{ extraBossOrders: 2 },
|
| 895 |
+
today
|
| 896 |
+
);
|
| 897 |
+
assert.equal(stNoExtraDate.maxOrders, 3, '缺乏 extraBossOrdersDate 時不可發放額外討伐令');
|
| 898 |
+
|
| 899 |
+
// 15.2 歷史累計 attacksCount=9 絕不誤充今日已用次數
|
| 900 |
+
const stAttacksCountIsolated = calcWorldBossStatus(
|
| 901 |
+
{
|
| 902 |
+
worldBoss: {
|
| 903 |
+
bossId: 'qiongqi',
|
| 904 |
+
phaseMode: 'open',
|
| 905 |
+
damages: {
|
| 906 |
+
uIsolate: { dmg: 45, attacksCount: 9, lastDate: today, lastAt: Date.now() }
|
| 907 |
+
}
|
| 908 |
+
}
|
| 909 |
+
},
|
| 910 |
+
{ u6: { best: 100 } },
|
| 911 |
+
{ boss: { date: today, used: 0 } },
|
| 912 |
+
today,
|
| 913 |
+
null,
|
| 914 |
+
'uIsolate'
|
| 915 |
+
);
|
| 916 |
+
assert.equal(stAttacksCountIsolated.used, 0, '缺少 dailyUsed[today]/todayCount 時不可由累計 attacksCount 推算今日次數');
|
| 917 |
+
assert.equal(stAttacksCountIsolated.ordersLeft, 3, '跨日/換期累計 attacksCount=9 時今日仍應保有 3 次討伐令');
|
| 918 |
+
|
| 919 |
+
// 15.3 0 次出征遭髒 HWM 污染時(4 > 3)自動自癒清零+動態上限 HWM 校準
|
| 920 |
+
const prevLS = globalThis.localStorage;
|
| 921 |
+
const memStore = new Map();
|
| 922 |
+
globalThis.localStorage = {
|
| 923 |
+
getItem: (k) => (memStore.has(k) ? memStore.get(k) : null),
|
| 924 |
+
setItem: (k, v) => { memStore.set(k, String(v)); },
|
| 925 |
+
removeItem: (k) => { memStore.delete(k); }
|
| 926 |
+
};
|
| 927 |
+
try {
|
| 928 |
+
globalThis.localStorage.setItem('idle_boss_hwm_uPolluted', JSON.stringify({ date: today, used: 4 }));
|
| 929 |
+
const stHealed = calcWorldBossStatus(
|
| 930 |
+
{ worldBoss: { bossId: 'qiongqi', phaseMode: 'open', damages: {} } },
|
| 931 |
+
{ u6: { best: 100 } },
|
| 932 |
+
{},
|
| 933 |
+
today,
|
| 934 |
+
null,
|
| 935 |
+
'uPolluted'
|
| 936 |
+
);
|
| 937 |
+
assert.equal(stHealed.used, 0, '今日伺服器出征 0 次時,被污染的 HWM=4 應自癒歸零');
|
| 938 |
+
assert.equal(stHealed.ordersLeft, 3, 'HWM 自癒後 ordersLeft 應恢復 3');
|
| 939 |
+
const healedCached = JSON.parse(globalThis.localStorage.getItem('idle_boss_hwm_uPolluted'));
|
| 940 |
+
assert.equal(healedCached.used, 0, 'localStorage 髒 HWM 快取必須同步清洗回 0');
|
| 941 |
+
|
| 942 |
+
globalThis.localStorage.setItem('idle_boss_hwm_uExtra', JSON.stringify({ date: today, used: 6 }));
|
| 943 |
+
const extraGame = { extraBossOrders: 2, extraBossOrdersDate: today, boss: { date: today, used: 2 } };
|
| 944 |
+
applyBossHighWaterMarkToGame('uExtra', extraGame);
|
| 945 |
+
const healedExtraCached = JSON.parse(globalThis.localStorage.getItem('idle_boss_hwm_uExtra'));
|
| 946 |
+
assert.equal(healedExtraCached.used, 2, '超越動態上限(5)之髒 HWM=6 應自癒回今日實績 2');
|
| 947 |
+
|
| 948 |
+
// 15.4 settleBossDamageRecord:單場傷害封頂、每日上限、alreadyDefeated 不扣次數
|
| 949 |
+
const stuMock = { uid: 's1', seat: '1', name: '一號', classCode: '999', bankId: 'wiring', game: { boss: { date: today, used: 0 } } };
|
| 950 |
+
const wbQ = { bossId: 'qiongqi', phaseMode: 'open', yangMaxHp: 1200, yinMaxHp: 800, yangHp: 1200, yinHp: 800, maxHp: 2000, curHp: 2000, damages: { s1: { name: '一號', seat: '1', dmg: 10, attacksCount: 12, lastDate: '2026-11-01' } } };
|
| 951 |
+
const capRes = settleBossDamageRecord(wbQ, stuMock, 999, { yangDmg: 400, yinDmg: 400 }, { game: { boss: {} } }, today);
|
| 952 |
+
assert.equal(capRes.result.effectiveDmg, 50, '窮奇單場傷害應封頂為 50 HP');
|
| 953 |
+
assert.equal(capRes.result.dailyUsedToday, 1, '儘管歷史 attacksCount=12,今日首次出征仍計為第 1 次');
|
| 954 |
+
|
| 955 |
+
const wbDefeated = { bossId: 'qiongqi', phaseMode: 'open', yangMaxHp: 1200, yinMaxHp: 800, yangHp: 0, yinHp: 0, maxHp: 2000, curHp: 0, defeated: true, damages: { s1: { dmg: 10, attacksCount: 1, dailyUsed: { [today]: 1 } } } };
|
| 956 |
+
const defRes = settleBossDamageRecord(wbDefeated, stuMock, 15, { yangDmg: 10, yinDmg: 5 }, { game: { boss: { date: today, used: 1 } } }, today);
|
| 957 |
+
assert.equal(defRes.alreadyDefeated, true, '已被擊敗時應標記 alreadyDefeated');
|
| 958 |
+
assert.equal(defRes.orderConsumed, false, '已被擊敗時絕不消耗今日討伐令');
|
| 959 |
+
assert.equal(defRes.result.effectiveDmg, 0, '已被擊敗時不計入無效溢傷');
|
| 960 |
+
|
| 961 |
+
const wbTaotie = { bossId: 'taotie', phaseMode: 'open', maxHp: 500, curHp: 500, damages: {} };
|
| 962 |
+
const taoCap = settleBossDamageRecord(wbTaotie, stuMock, 999, null, { game: { boss: {} } }, today);
|
| 963 |
+
assert.equal(taoCap.result.effectiveDmg, 25, '饕餮單場傷害應封頂為 25 HP');
|
| 964 |
+
|
| 965 |
+
// 15.5 LocalBackend.recordBossDamage 與 Firestore 同構日限與學生存檔同步
|
| 966 |
+
const lb = new LocalBackend();
|
| 967 |
+
const seed = {
|
| 968 |
+
users: {},
|
| 969 |
+
classes: {
|
| 970 |
+
'999': {
|
| 971 |
+
code: '999',
|
| 972 |
+
name: '測試班',
|
| 973 |
+
worldBoss: { bossId: 'qiongqi', phaseMode: 'open', yangMaxHp: 1200, yinMaxHp: 800, yangHp: 1200, yinHp: 800, maxHp: 2000, curHp: 2000, damages: {} }
|
| 974 |
+
}
|
| 975 |
+
},
|
| 976 |
+
students: {
|
| 977 |
+
stu1: { uid: 'stu1', seat: '1', name: '一號', classCode: '999', bankId: 'wiring', game: { boss: { date: today, used: 0 } } }
|
| 978 |
+
},
|
| 979 |
+
attempts: [],
|
| 980 |
+
giftLog: []
|
| 981 |
+
};
|
| 982 |
+
globalThis.localStorage.setItem('idle_demo_db_v1', JSON.stringify(seed));
|
| 983 |
+
const localStu = seed.students.stu1;
|
| 984 |
+
await lb.recordBossDamage('999', localStu, 10, { yangDmg: 6, yinDmg: 4 });
|
| 985 |
+
await lb.recordBossDamage('999', localStu, 10, { yangDmg: 6, yinDmg: 4 });
|
| 986 |
+
const r3 = await lb.recordBossDamage('999', localStu, 10, { yangDmg: 6, yinDmg: 4 });
|
| 987 |
+
assert.equal(r3.dailyUsedToday, 3, 'LocalBackend 第 3 戰後應為 3 次');
|
| 988 |
+
const savedAfter3 = lb.load();
|
| 989 |
+
assert.equal(savedAfter3.students.stu1.game.boss.used, 3, 'LocalBackend 必須同步更新學生 game.boss.used');
|
| 990 |
+
await assert.rejects(
|
| 991 |
+
() => lb.recordBossDamage('999', localStu, 10, { yangDmg: 6, yinDmg: 4 }),
|
| 992 |
+
/今日出征討伐次數已達上限/,
|
| 993 |
+
'LocalBackend 第 4 戰必須比照 Firestore 阻擋'
|
| 994 |
+
);
|
| 995 |
+
} finally {
|
| 996 |
+
globalThis.localStorage = prevLS;
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
// 15.6 防閃爍與管理連結靜態檢查
|
| 1000 |
+
const bossHtmlSrc = fs.readFileSync(path.join(ROOT, 'boss.html'), 'utf8');
|
| 1001 |
+
const bossCssSrc = fs.readFileSync(path.join(ROOT, 'css', 'boss.css'), 'utf8');
|
| 1002 |
+
const teacherHtmlSrc = fs.readFileSync(path.join(ROOT, 'teacher.html'), 'utf8');
|
| 1003 |
+
assert.ok(bossHtmlSrc.includes('<body class="boss-hydrating">'), 'boss.html 初始必須帶有 boss-hydrating 類別避免閃現饕餮');
|
| 1004 |
+
assert.ok(!bossHtmlSrc.includes('assets/boss_taotie.png'), 'boss.html 不可靜態寫死上古饕餮圖片');
|
| 1005 |
+
assert.ok(!bossHtmlSrc.includes('上古・饕餮'), 'boss.html 不可靜態寫死上古饕餮名稱');
|
| 1006 |
+
assert.ok(bossCssSrc.includes('body.boss-hydrating'), 'css/boss.css ���須定義 body.boss-hydrating 載入遮罩');
|
| 1007 |
+
assert.ok(teacherHtmlSrc.includes('id="btnAdminOpenBossPage"'), 'teacher.html 必須具備動態戰場連結按鈕 btnAdminOpenBossPage');
|
| 1008 |
+
assert.ok(teacherHtmlSrc.includes('value="qiongqi_closed"'), 'teacher.html 必須具備 qiongqi_closed 關閉收起選項');
|
| 1009 |
+
|
| 1010 |
+
// 15.7 窮奇手動關閉收起狀態檢驗(必須於大地圖隱藏且不被自動重開)
|
| 1011 |
+
const stQiongqiClosed = calcWorldBossStatus(
|
| 1012 |
+
{
|
| 1013 |
+
worldBoss: {
|
| 1014 |
+
bossId: 'qiongqi',
|
| 1015 |
+
phaseMode: 'closed',
|
| 1016 |
+
hidden: true,
|
| 1017 |
+
phaseSetAt: new Date('2026-11-14T21:00:00+08:00').getTime(),
|
| 1018 |
+
defeated: true,
|
| 1019 |
+
curHp: 0
|
| 1020 |
+
},
|
| 1021 |
+
eventSettings: { boss: { mode: 'closed' } }
|
| 1022 |
+
},
|
| 1023 |
+
{ u6: { best: 100 } },
|
| 1024 |
+
{},
|
| 1025 |
+
'2026-11-14',
|
| 1026 |
+
new Date('2026-11-14T21:05:00+08:00').getTime()
|
| 1027 |
+
);
|
| 1028 |
+
assert.equal(stQiongqiClosed.bossId, 'qiongqi', '關閉後 bossId 仍應保留 qiongqi 戰績脈絡');
|
| 1029 |
+
assert.equal(stQiongqiClosed.isClosedMode, true, '窮奇關閉後 isClosedMode 應為 true');
|
| 1030 |
+
assert.equal(stQiongqiClosed.isExpired, true, '窮奇關閉後 isExpired 應為 true(大地圖收起)');
|
| 1031 |
+
assert.equal(stQiongqiClosed.unlocked, false, '窮奇關閉後 unlocked 應為 false');
|
| 1032 |
+
}
|
| 1033 |
+
ok('世界 Boss P0 止血回歸檢驗(次數防漏/HWM 自癒/傷限/防閃爍/LocalBackend 同步)100% 通過');
|
| 1034 |
+
|
| 1035 |
+
// ----------------------------------------------------------------------------
|
| 1036 |
+
// 16. 學生兵符對帳輔助腳本 (.agents/skills/student-resource-audit/scripts/audit-student.js) 檢驗
|
| 1037 |
+
// ----------------------------------------------------------------------------
|
| 1038 |
+
{
|
| 1039 |
+
const auditScriptPath = path.join(ROOT, '.agents', 'skills', 'student-resource-audit', 'scripts', 'audit-student.js');
|
| 1040 |
+
execFileSync(process.execPath, ['--check', auditScriptPath], { stdio: 'pipe' });
|
| 1041 |
+
|
| 1042 |
+
// 16.1 升星累計費用驗證(含前 5 星 [1,3,6,11,19] 與 ★6+ 等比遞增)
|
| 1043 |
+
assert.equal(cumStarCost(0), 0, '0 星累計應為 0');
|
| 1044 |
+
assert.equal(cumStarCost(1), 1, '1 星累計應為 1');
|
| 1045 |
+
assert.equal(cumStarCost(3), 6, '3 星累計應為 6');
|
| 1046 |
+
assert.equal(cumStarCost(4), 11, '4 星累計應為 11(不可用舊制三角數 10)');
|
| 1047 |
+
assert.equal(cumStarCost(5), 19, '5 星累計應為 19(不可用舊制三角數 15)');
|
| 1048 |
+
assert.equal(cumStarCost(6), 32, '6 星累計應為 19 + ceil(8*1.6) = 32');
|
| 1049 |
+
|
| 1050 |
+
// 16.2 建城開拓(84) + 二紀元飛升重置(19+25+postStars) + ★6+ + 後台回收
|
| 1051 |
+
const allTenBuildings = {};
|
| 1052 |
+
for (const b of BUILDINGS) {
|
| 1053 |
+
allTenBuildings[b.id] = { lv: 1, star: 0 };
|
| 1054 |
+
}
|
| 1055 |
+
allTenBuildings.b1 = { lv: 10, era2: true, star: 2 }; // 1(conq) + 19(era1★5) + 25(ascend) + 3(era2★2)
|
| 1056 |
+
allTenBuildings.b2 = { lv: 5, era2: false, star: 6 }; // 2(conq) + 32(★6)
|
| 1057 |
+
|
| 1058 |
+
// 16.3 時間軸:改版前(10/22)不受4卷池限;改版後(11/10)若今日 openRanges 只含 u6..u9,不應污染歷史 11/03 合法池內 u3 複習
|
| 1059 |
+
const mockNowMs = new Date('2026-11-14T12:00:00+08:00').getTime();
|
| 1060 |
+
const mockClassInfo = {
|
| 1061 |
+
code: '902new',
|
| 1062 |
+
openRanges: ['u6', 'u7', 'u8', 'u9'], // 今日動態開放範圍
|
| 1063 |
+
worldBoss: {
|
| 1064 |
+
bossId: 'qiongqi',
|
| 1065 |
+
killer: { uid: 'stu-audit-1' },
|
| 1066 |
+
damages: { 'stu-audit-1': { dmg: 120 } },
|
| 1067 |
+
},
|
| 1068 |
+
};
|
| 1069 |
+
const mockStudent = {
|
| 1070 |
+
uid: 'stu-audit-1',
|
| 1071 |
+
classCode: '902new',
|
| 1072 |
+
seat: 99,
|
| 1073 |
+
name: '對帳測試生',
|
| 1074 |
+
progress: {
|
| 1075 |
+
u1: { passed: true, best: 100, claimed: 5 },
|
| 1076 |
+
u5: { passed: true, best: 100, claimed: 5 },
|
| 1077 |
+
u9: { passed: true, best: 100, claimed: 8 }, // 建都 b10 後 u9+ 8 符
|
| 1078 |
+
c1: { passed: true, best: 95, claimed: 6 }, // Tier 2 95 分 = 6 符
|
| 1079 |
+
},
|
| 1080 |
+
game: {
|
| 1081 |
+
blueprints: 10,
|
| 1082 |
+
tianjiDate: '2026-11-14',
|
| 1083 |
+
buildings: allTenBuildings,
|
| 1084 |
+
titles: ['破魔先鋒'],
|
| 1085 |
+
boss: {
|
| 1086 |
+
claimed: { taotie: true, qiongqi: true },
|
| 1087 |
+
rewardClaimed: true,
|
| 1088 |
+
},
|
| 1089 |
+
merchant: {
|
| 1090 |
+
buys: {
|
| 1091 |
+
shardBox: { total: 2 }, // 2 * 1 = 2
|
| 1092 |
+
goldTally: { total: 1 }, // 1 * 2 = 2
|
| 1093 |
+
tallyChest: { total: 1 }, // 1 * 5 = 5 -> total 9
|
| 1094 |
+
},
|
| 1095 |
+
},
|
| 1096 |
+
},
|
| 1097 |
+
};
|
| 1098 |
+
const mockAttempts = [
|
| 1099 |
+
// 10/22 首次通過 u1 (不給複習) + 同日重考 (改版前給 +1)
|
| 1100 |
+
{ uid: 'stu-audit-1', rid: 'u1', score: 100, at: new Date('2026-10-22T09:00:00+08:00').getTime() },
|
| 1101 |
+
{ uid: 'stu-audit-1', rid: 'u1', score: 90, at: new Date('2026-10-22T15:00:00+08:00').getTime() },
|
| 1102 |
+
// 11/03:當時排程開放 u1..u5,最新 4 卷為 [u2,u3,u4,u5];u5 首通無複習,u1 不在池內,隔天 11/04 u5 複習在池內 (+1)
|
| 1103 |
+
{ uid: 'stu-audit-1', rid: 'u5', score: 100, at: new Date('2026-11-03T10:00:00+08:00').getTime() },
|
| 1104 |
+
{ uid: 'stu-audit-1', rid: 'u1', score: 100, at: new Date('2026-11-03T11:00:00+08:00').getTime() },
|
| 1105 |
+
{ uid: 'stu-audit-1', rid: 'u5', score: 90, at: new Date('2026-11-04T10:00:00+08:00').getTime() },
|
| 1106 |
+
// u9 & c1 首通
|
| 1107 |
+
{ uid: 'stu-audit-1', rid: 'u9', score: 100, at: new Date('2026-11-12T09:00:00+08:00').getTime() },
|
| 1108 |
+
{ uid: 'stu-audit-1', rid: 'c1', score: 95, at: new Date('2026-11-13T09:00:00+08:00').getTime() },
|
| 1109 |
+
];
|
| 1110 |
+
const mockGifts = [
|
| 1111 |
+
// bp === 0 饕餮純戰報信不可遮蔽競技場自領;一般信件 +3(未領 +4 不計)
|
| 1112 |
+
{ title: '饕餮戰報', bp: 0, claimed: true, bossSettle: 'taotie', at: 1793540000000 },
|
| 1113 |
+
{ title: '老師獎勵', bp: 3, claimed: true, at: 1793600000000 },
|
| 1114 |
+
{ title: '未開信件', bp: 4, claimed: false, at: 1793700000000 },
|
| 1115 |
+
];
|
| 1116 |
+
const mockReclaimLogs = [
|
| 1117 |
+
{ type: 'reclaim', isReclaim: true, results: [{ uid: 'stu-audit-1', before: { bp: 15 }, after: { bp: 11 } }] }, // -4
|
| 1118 |
+
];
|
| 1119 |
+
|
| 1120 |
+
const auditRes = computeStudentAudit({
|
| 1121 |
+
studentDoc: mockStudent,
|
| 1122 |
+
classInfo: mockClassInfo,
|
| 1123 |
+
attempts: mockAttempts,
|
| 1124 |
+
gifts: mockGifts,
|
| 1125 |
+
reclaimLogs: mockReclaimLogs,
|
| 1126 |
+
nowMs: mockNowMs,
|
| 1127 |
+
});
|
| 1128 |
+
|
| 1129 |
+
// 支出檢查:conquer=84, star=(19+3)+32=54, era2=25, reclaim=4 -> 167
|
| 1130 |
+
assert.equal(auditRes.expenses.conquerBp, 84, '開拓 10 城應合計 84 兵符');
|
| 1131 |
+
assert.equal(auditRes.expenses.starBp, 54, '二紀元 b1(19+3) 與 ★6 b2(32) 應合計 54 升星兵符');
|
| 1132 |
+
assert.equal(auditRes.expenses.era2AscendBp, ERA2_TALLY_COST, '二紀元飛升費應等於 ERA2_TALLY_COST (25)');
|
| 1133 |
+
assert.equal(auditRes.expenses.reclaimedBp, 4, '後台回收紀錄應扣減 4 兵符');
|
| 1134 |
+
assert.equal(auditRes.expenses.totalSpentBp, 167, '總支出應為 84+54+25+4 = 167');
|
| 1135 |
+
|
| 1136 |
+
// 收入檢查:fp=5+5+8+6=24;revPool=2(10/22 u1, 11/04 u5), revAll=3(含 11/03 池外 u1);gift=3(pend=4);
|
| 1137 |
+
// bossArena: 饕餮(MVP=6) + 窮奇(killer=9) = 15;merchant = 9 -> pool總收入 = 24+2+3+15+9 = 53
|
| 1138 |
+
assert.equal(auditRes.incomes.firstPassBp, 24, '首通進度應精準包含 Tier 2 與 u9+ 8 符加碼');
|
| 1139 |
+
assert.equal(auditRes.incomes.reviewBpPool, 2, '嚴格複習池應排除 11/03 池外 u1 並正確保留歷史 11/04 u5(不受今日 openRanges 污染)');
|
| 1140 |
+
assert.equal(auditRes.incomes.reviewBpAllPassed, 3, '全部重考複習上限應為 3');
|
| 1141 |
+
assert.equal(auditRes.incomes.giftBpClaimed, 3, '信箱已領應僅計入 bp>0 且 claimed=true');
|
| 1142 |
+
assert.equal(auditRes.incomes.giftBpPending, 4, '待領信箱應獨立統計為 4');
|
| 1143 |
+
assert.equal(auditRes.incomes.bossArenaBp, 15, 'bp=0 饕餮戰報不應遮蔽自領 6 符,且應加計窮奇尾刀 9 符');
|
| 1144 |
+
assert.equal(auditRes.incomes.merchantBp, 9, '西域商隊購買兵符應合計 9 符');
|
| 1145 |
+
assert.equal(auditRes.incomes.totalIncomeMinPool, 53, '嚴格下限總收入應為 53');
|
| 1146 |
+
|
| 1147 |
+
// 若確實透過 bp=4 饕餮結算信領獎,則不可重複計入競技場饕餮 6 符
|
| 1148 |
+
const auditWithPaidTaotieMail = computeStudentAudit({
|
| 1149 |
+
studentDoc: mockStudent,
|
| 1150 |
+
classInfo: mockClassInfo,
|
| 1151 |
+
attempts: mockAttempts,
|
| 1152 |
+
gifts: [{ title: '饕餮結算', bp: 4, claimed: true, bossSettle: 'taotie' }],
|
| 1153 |
+
reclaimLogs: [],
|
| 1154 |
+
nowMs: mockNowMs,
|
| 1155 |
+
});
|
| 1156 |
+
assert.equal(auditWithPaidTaotieMail.incomes.bossArenaBp, 9, '已領 bp>0 饕餮結算信時不可重複計入競技場饕餮獎勵');
|
| 1157 |
+
|
| 1158 |
+
// 若 diffFromPool >= 0 但 diffFromAllRev < -10(學生頻繁刷池外舊卷),不可誤報異常;同時驗證缺少對應嘗試紀錄時可抓出 PROGRESS_MISMATCH
|
| 1159 |
+
const outOfPoolRetakes = [];
|
| 1160 |
+
for (let d = 5; d <= 16; d++) {
|
| 1161 |
+
outOfPoolRetakes.push({ uid: 'stu-audit-1', rid: 'u1', score: 100, at: new Date(`2026-11-${String(d).padStart(2, '0')}T10:00:00+08:00`).getTime() });
|
| 1162 |
+
}
|
| 1163 |
+
const retakerAttempts = [
|
| 1164 |
+
{ uid: 'stu-audit-1', rid: 'u1', score: 100, at: new Date('2026-10-22T09:00:00+08:00').getTime() },
|
| 1165 |
+
{ uid: 'stu-audit-1', rid: 'u5', score: 100, at: new Date('2026-11-03T10:00:00+08:00').getTime() },
|
| 1166 |
+
...outOfPoolRetakes,
|
| 1167 |
+
];
|
| 1168 |
+
const auditHealthyRetaker = computeStudentAudit({
|
| 1169 |
+
studentDoc: {
|
| 1170 |
+
...mockStudent,
|
| 1171 |
+
progress: { u1: { passed: true, best: 100, claimed: 5 }, u5: { passed: true, best: 100, claimed: 5 } },
|
| 1172 |
+
game: { ...mockStudent.game, buildings: { b1: { lv: 1, star: 0 } }, blueprints: 9, merchant: {}, titles: [], boss: {} },
|
| 1173 |
+
},
|
| 1174 |
+
classInfo: mockClassInfo,
|
| 1175 |
+
attempts: retakerAttempts,
|
| 1176 |
+
gifts: [],
|
| 1177 |
+
reclaimLogs: [],
|
| 1178 |
+
nowMs: mockNowMs,
|
| 1179 |
+
});
|
| 1180 |
+
assert.equal(auditHealthyRetaker.discrepancyMax, 0, '嚴格下限差應精準為 0');
|
| 1181 |
+
assert.equal(auditHealthyRetaker.discrepancyMin, -12, '上限差應精準為 -12(受 12 筆池外重考影響)');
|
| 1182 |
+
assert.equal(auditHealthyRetaker.status, 'NORMAL', '嚴格下限未虧空時,刷池外舊卷不可誤判為異常警告');
|
| 1183 |
+
|
| 1184 |
+
const auditMismatch = computeStudentAudit({
|
| 1185 |
+
studentDoc: {
|
| 1186 |
+
...mockStudent,
|
| 1187 |
+
game: { ...mockStudent.game, buildings: { b1: { lv: 1, star: 0 } }, blueprints: 23, merchant: {}, titles: [], boss: {} },
|
| 1188 |
+
},
|
| 1189 |
+
classInfo: mockClassInfo,
|
| 1190 |
+
attempts: retakerAttempts,
|
| 1191 |
+
gifts: [],
|
| 1192 |
+
reclaimLogs: [],
|
| 1193 |
+
nowMs: mockNowMs,
|
| 1194 |
+
});
|
| 1195 |
+
assert.equal(auditMismatch.status, 'PROGRESS_MISMATCH', 'progress.claimed 與 attempts 不符時應標記 PROGRESS_MISMATCH');
|
| 1196 |
+
assert.equal(auditMismatch.diagnostics.progressMismatch.length, 2, '應精準回報缺少嘗��紀錄的 u9 與 c1');
|
| 1197 |
+
}
|
| 1198 |
+
ok('學生兵符對帳輔助腳本(建城/升星★6+/二紀元重置/4卷池防污染/Boss戰報防遮蔽/商隊/回收)100% 通過');
|
| 1199 |
+
|
| 1200 |
+
// ----------------------------------------------------------------------------
|
| 1201 |
+
// 17. 可插拔活動排程、週四快閃並列與舊窮奇全員領完才隱藏檢驗 (Task A1)
|
| 1202 |
+
// ----------------------------------------------------------------------------
|
| 1203 |
+
{
|
| 1204 |
+
assert.ok(EVENT_CATALOG && EVENT_CATALOG.lottery && EVENT_CATALOG.boss && EVENT_CATALOG.caravan && EVENT_CATALOG.camel, 'EVENT_CATALOG 必須註冊 4 大活動');
|
| 1205 |
+
assert.ok(TITLE_DEFS['九州錦鯉'] && TITLE_DEFS['錯題終結者'], 'TITLE_DEFS 必須包含樂透稱號');
|
| 1206 |
+
|
| 1207 |
+
// 17.1 偶數商隊週預設無主打;啟用週四快閃 allowDuringCaravan=true 後可與商隊並行,週五自動收起
|
| 1208 |
+
const pilot = buildPilotLotterySpotlightPreset();
|
| 1209 |
+
const clsPilot = {
|
| 1210 |
+
weeklySpotlight: pilot.weeklySpotlight,
|
| 1211 |
+
lotteryCycles: { [pilot.lotteryCycle.cycleId]: pilot.lotteryCycle },
|
| 1212 |
+
};
|
| 1213 |
+
assert.equal(isEventOpen('caravan', clsPilot, '2026-11-19'), true, '快閃期間西域商隊應維持正常開放');
|
| 1214 |
+
const spThu = resolveWeeklySpotlight(clsPilot, new Date('2026-11-19T14:00:00+08:00'));
|
| 1215 |
+
assert.equal(spThu.active, true, '2026-11-19 14:00 快閃樂透應為開啟');
|
| 1216 |
+
assert.equal(spThu.eventId, 'lottery');
|
| 1217 |
+
assert.equal(spThu.cycleId, 'lotto_pilot_20261119');
|
| 1218 |
+
const spFriDefault = resolveWeeklySpotlight(clsPilot, new Date('2026-11-20T09:00:00+08:00'));
|
| 1219 |
+
assert.equal(spFriDefault.active, false, '預設僅週四開放,週五應自動收起待開獎');
|
| 1220 |
+
assert.equal(spFriDefault.isExpired, true);
|
| 1221 |
+
|
| 1222 |
+
// 17.2 奇數週未選定安全為 none;教師選定後於下週週日 23:59 後自動隱藏
|
| 1223 |
+
assert.equal(resolveWeeklySpotlight({}, new Date('2026-11-23T10:00:00+08:00')).active, false, '奇數週未選定主打時必須安全休兵');
|
| 1224 |
+
const oddPreset = buildOddWeekSpotlightPreset({ eventId: 'lottery', now: new Date('2026-11-23T08:00:00+08:00') });
|
| 1225 |
+
const clsOdd = { weeklySpotlight: oddPreset.weeklySpotlight, lotteryCycles: { [oddPreset.cycleId]: oddPreset.cycle } };
|
| 1226 |
+
assert.equal(resolveWeeklySpotlight(clsOdd, new Date('2026-11-23T10:00:00+08:00')).active, true, '奇數週選定樂透後應正常開放');
|
| 1227 |
+
assert.equal(resolveWeeklySpotlight(clsOdd, new Date('2026-11-30T00:01:00+08:00')).active, false, '超過該週日 23:59 後應自動隱藏');
|
| 1228 |
+
|
| 1229 |
+
// 17.3 舊窮奇「全員領完才隱藏」與未領獎保留入口
|
| 1230 |
+
const clsLegacyQ = {
|
| 1231 |
+
eventSettings: { boss: { mode: 'open' } },
|
| 1232 |
+
worldBoss: { bossId: 'qiongqi', phaseMode: 'open', defeated: true, curHp: 0, maxHp: 2000, damages: { s1: { dmg: 50 }, s2: { dmg: 30 } } },
|
| 1233 |
+
};
|
| 1234 |
+
const gUnclaimed = newGame();
|
| 1235 |
+
const gClaimed = newGame();
|
| 1236 |
+
markBossRewardClaimed(gClaimed, 'qiongqi');
|
| 1237 |
+
const stUnclaimed = calcWorldBossStatus(clsLegacyQ, { u6: { best: 90 } }, gUnclaimed, '2026-11-16');
|
| 1238 |
+
assert.equal(stUnclaimed.isExpired, false, '2026-11-16 起未領取舊窮奇獎勵者仍應保留領獎入口');
|
| 1239 |
+
assert.equal(stUnclaimed.claimOnlyAfterEnd, true, '保留入口應標記為僅供補領獎勵(claimOnlyAfterEnd)');
|
| 1240 |
+
const stClaimed = calcWorldBossStatus(clsLegacyQ, { u6: { best: 90 } }, gClaimed, '2026-11-16');
|
| 1241 |
+
assert.equal(stClaimed.isExpired, true, '已領過舊窮奇獎勵者應自動隱藏');
|
| 1242 |
+
const stCleared = calcWorldBossStatus({ ...clsLegacyQ, legacyBossClearedAt: 1795000000000 }, { u6: { best: 90 } }, gUnclaimed, '2026-11-16');
|
| 1243 |
+
assert.equal(stCleared.isExpired, true, '班級教師確認全員結清後應全面隱藏');
|
| 1244 |
+
|
| 1245 |
+
const unclaimedStudents = findUnclaimedLegacyBossStudents(clsLegacyQ, [
|
| 1246 |
+
{ uid: 's1', seat: '1', name: '甲生', role: 'student', game: gClaimed, progress: { u6: { best: 90 } } },
|
| 1247 |
+
{ uid: 's2', seat: '2', name: '乙生', role: 'student', game: gUnclaimed, progress: { u6: { best: 90 } } },
|
| 1248 |
+
{ uid: 't1', seat: '20', name: '測試帳號', role: 'student', game: gUnclaimed, progress: { u6: { best: 90 } } },
|
| 1249 |
+
]);
|
| 1250 |
+
assert.deepEqual(unclaimedStudents.map(s => s.uid), ['s2'], '應精準列出尚未領取舊窮奇獎勵之有效學生(排除已領與 20 號測試號)');
|
| 1251 |
+
}
|
| 1252 |
+
ok('可插拔活動排程、週四快閃並列與舊窮奇領完才隱藏檢驗 100% 通過');
|
| 1253 |
+
|
| 1254 |
console.log(`\n🎉 全部 ${passedChecks} 大項工程防呆檢驗 100% 通過!可安全部署上線。`);
|