YaLight commited on
Commit
addbfe9
·
1 Parent(s): 229f25b

Tune study and contest balance rules

Browse files
Files changed (2) hide show
  1. README.md +7 -0
  2. app.js +53 -11
README.md CHANGED
@@ -18,3 +18,10 @@ pinned: false
18
  - 隨機事件
19
  - 突發結局與終末結局
20
 
 
 
 
 
 
 
 
 
18
  - 隨機事件
19
  - 突發結局與終末結局
20
 
21
+ ## 改動紀錄
22
+
23
+ - 語文或邏輯增加到 81-90 區間時,每增加 1 點會讓另一項減少 2 點。
24
+ - 語文或邏輯增加到 91 以上時,每增加 1 點會讓另一項減少 3 點。
25
+ - 體力為 0 時,平日學習與假期讀書無法執行。
26
+ - 假期競賽標準改為第 1/2/3 年分別需要 55/70/85。
27
+ - 假期競賽成功時,壓力減少由 -10 改為 -5。
app.js CHANGED
@@ -5,6 +5,7 @@ const WEEKDAY_PHASES = ["早上", "下午", "晚上"];
5
  const HOLIDAY_PHASES = ["早上", "中午", "晚上"];
6
  const STORAGE_KEY = "high-school-simulator-state-v1";
7
  const SETUP_VERSION = 2;
 
8
 
9
  const STAT_LABELS = {
10
  learning: "學習",
@@ -257,19 +258,23 @@ function renderChoices() {
257
  label: action.label,
258
  hint: action.hint,
259
  tone: action.tone,
 
260
  onClick: () => takeAction(action.id),
261
  }),
262
  );
263
  });
264
  }
265
 
266
- function createChoiceButton({ label, hint, tone, onClick }) {
267
  const button = document.createElement("button");
268
  button.className = "choice-button";
269
  button.type = "button";
270
  button.dataset.tone = tone || "blue";
 
271
  button.innerHTML = `<strong>${label}</strong><span>${hint || ""}</span>`;
272
- button.addEventListener("click", onClick);
 
 
273
  return button;
274
  }
275
 
@@ -305,41 +310,54 @@ function getAvailableActions() {
305
  );
306
  }
307
 
308
- return base;
309
  }
310
 
311
  if (state.phase === 0) {
312
- return [
313
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
314
  { id: "studyLanguage", label: "學習(文科)", hint: "語文與學習", tone: "purple" },
315
  { id: "studyLogic", label: "學習(理科)", hint: "邏輯與學習", tone: "blue" },
316
  { id: "nap", label: "zzZ", hint: "可能被記警告", tone: "green" },
317
  { id: "skipClass", label: "逃課", hint: "裝病請假", tone: "red" },
318
  { id: "makeFriends", label: "交友", hint: "社交機會", tone: "green" },
319
- ];
320
  }
321
 
322
  if (state.phase === 1) {
323
- return [
324
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
325
  { id: "studyLanguage", label: "學習(文科)", hint: "語文與學習", tone: "purple" },
326
  { id: "studyLogic", label: "學習(理科)", hint: "邏輯與學習", tone: "blue" },
327
  { id: "nap", label: "zzZ", hint: "可能被記警告", tone: "green" },
328
  { id: "makeFriends", label: "交友", hint: "社交機會", tone: "green" },
329
- ];
330
  }
331
 
332
- return [
333
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
334
  { id: "studyLanguage", label: "讀書(文)", hint: "語文與學習", tone: "purple" },
335
  { id: "studyLogic", label: "讀書(理)", hint: "邏輯與學習", tone: "blue" },
336
  { id: "onlineFriends", label: "和朋友連機", hint: "社交與壓力波動", tone: "green" },
337
  { id: "sleep", label: "睡覺", hint: "體力與健康恢復", tone: "green" },
338
- ];
 
 
 
 
 
 
 
339
  }
340
 
341
  function takeAction(actionId) {
342
  if (state.ended) return;
 
 
 
 
 
 
343
 
344
  const actionMap = {
345
  sport: () => weekdaySport(),
@@ -482,7 +500,7 @@ function holidayNap() {
482
  }
483
 
484
  function contest(type) {
485
- const threshold = [50, 65, 80][state.year - 1];
486
  const statKey = type === "language" ? "language" : "logic";
487
  const title = type === "language" ? "語文比賽" : "邏輯競賽";
488
  const passed = state.stats[statKey] > threshold;
@@ -492,7 +510,7 @@ function contest(type) {
492
  if (passed) {
493
  applyOutcome(title, {
494
  text: `達到第 ${state.year} 年門檻 ${threshold},比賽表現出色。`,
495
- delta: { [statKey]: 6, learning: 6, stamina: -20, stress: -10, awards: 1 },
496
  });
497
  } else {
498
  applyOutcome(title, {
@@ -1243,6 +1261,18 @@ function applyDelta(delta) {
1243
  state.stats.awards = Math.max(0, Math.round(state.stats.awards));
1244
  state.stats.stamina = Math.round(clamp(state.stats.stamina, 0, state.stats.staminaMax));
1245
 
 
 
 
 
 
 
 
 
 
 
 
 
1246
  const actual = {};
1247
  Object.keys(state.stats).forEach((key) => {
1248
  const diff = state.stats[key] - before[key];
@@ -1251,6 +1281,18 @@ function applyDelta(delta) {
1251
  return actual;
1252
  }
1253
 
 
 
 
 
 
 
 
 
 
 
 
 
1254
  function formatDelta(delta) {
1255
  const entries = Object.entries(delta || {}).filter(([, value]) => value !== 0);
1256
  if (entries.length === 0) return "";
 
5
  const HOLIDAY_PHASES = ["早上", "中午", "晚上"];
6
  const STORAGE_KEY = "high-school-simulator-state-v1";
7
  const SETUP_VERSION = 2;
8
+ const STUDY_ACTION_IDS = new Set(["studyLanguage", "studyLogic", "holidayStudyLogic", "holidayStudyLanguage"]);
9
 
10
  const STAT_LABELS = {
11
  learning: "學習",
 
258
  label: action.label,
259
  hint: action.hint,
260
  tone: action.tone,
261
+ disabled: action.disabled,
262
  onClick: () => takeAction(action.id),
263
  }),
264
  );
265
  });
266
  }
267
 
268
+ function createChoiceButton({ label, hint, tone, disabled, onClick }) {
269
  const button = document.createElement("button");
270
  button.className = "choice-button";
271
  button.type = "button";
272
  button.dataset.tone = tone || "blue";
273
+ button.disabled = Boolean(disabled);
274
  button.innerHTML = `<strong>${label}</strong><span>${hint || ""}</span>`;
275
+ if (!disabled) {
276
+ button.addEventListener("click", onClick);
277
+ }
278
  return button;
279
  }
280
 
 
310
  );
311
  }
312
 
313
+ return withStudyAvailability(base);
314
  }
315
 
316
  if (state.phase === 0) {
317
+ return withStudyAvailability([
318
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
319
  { id: "studyLanguage", label: "學習(文科)", hint: "語文與學習", tone: "purple" },
320
  { id: "studyLogic", label: "學習(理科)", hint: "邏輯與學習", tone: "blue" },
321
  { id: "nap", label: "zzZ", hint: "可能被記警告", tone: "green" },
322
  { id: "skipClass", label: "逃課", hint: "裝病請假", tone: "red" },
323
  { id: "makeFriends", label: "交友", hint: "社交機會", tone: "green" },
324
+ ]);
325
  }
326
 
327
  if (state.phase === 1) {
328
+ return withStudyAvailability([
329
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
330
  { id: "studyLanguage", label: "學習(文科)", hint: "語文與學習", tone: "purple" },
331
  { id: "studyLogic", label: "學習(理科)", hint: "邏輯與學習", tone: "blue" },
332
  { id: "nap", label: "zzZ", hint: "可能被記警告", tone: "green" },
333
  { id: "makeFriends", label: "交友", hint: "社交機會", tone: "green" },
334
+ ]);
335
  }
336
 
337
+ return withStudyAvailability([
338
  { id: "sport", label: "運動", hint: "體力 -20,壓力下降", tone: "orange" },
339
  { id: "studyLanguage", label: "讀書(文)", hint: "語文與學習", tone: "purple" },
340
  { id: "studyLogic", label: "讀書(理)", hint: "邏輯與學習", tone: "blue" },
341
  { id: "onlineFriends", label: "和朋友連機", hint: "社交與壓力波動", tone: "green" },
342
  { id: "sleep", label: "睡覺", hint: "體力與健康恢復", tone: "green" },
343
+ ]);
344
+ }
345
+
346
+ function withStudyAvailability(actions) {
347
+ if (state.stats.stamina > 0) return actions;
348
+ return actions.map((action) =>
349
+ STUDY_ACTION_IDS.has(action.id) ? { ...action, hint: "體力為 0,無法學習", disabled: true } : action,
350
+ );
351
  }
352
 
353
  function takeAction(actionId) {
354
  if (state.ended) return;
355
+ if (STUDY_ACTION_IDS.has(actionId) && state.stats.stamina <= 0) {
356
+ addLog("體力為 0,無法學習。");
357
+ saveState();
358
+ render();
359
+ return;
360
+ }
361
 
362
  const actionMap = {
363
  sport: () => weekdaySport(),
 
500
  }
501
 
502
  function contest(type) {
503
+ const threshold = [55, 70, 85][state.year - 1];
504
  const statKey = type === "language" ? "language" : "logic";
505
  const title = type === "language" ? "語文比賽" : "邏輯競賽";
506
  const passed = state.stats[statKey] > threshold;
 
510
  if (passed) {
511
  applyOutcome(title, {
512
  text: `達到第 ${state.year} 年門檻 ${threshold},比賽表現出色。`,
513
+ delta: { [statKey]: 6, learning: 6, stamina: -20, stress: -5, awards: 1 },
514
  });
515
  } else {
516
  applyOutcome(title, {
 
1261
  state.stats.awards = Math.max(0, Math.round(state.stats.awards));
1262
  state.stats.stamina = Math.round(clamp(state.stats.stamina, 0, state.stats.staminaMax));
1263
 
1264
+ const languageDrain = calculateMasteryDrain(before.language, state.stats.language);
1265
+ const logicDrain = calculateMasteryDrain(before.logic, state.stats.logic);
1266
+ if (languageDrain > 0) {
1267
+ state.stats.logic -= languageDrain;
1268
+ }
1269
+ if (logicDrain > 0) {
1270
+ state.stats.language -= logicDrain;
1271
+ }
1272
+
1273
+ state.stats.language = Math.round(clamp(state.stats.language, 0, 100));
1274
+ state.stats.logic = Math.round(clamp(state.stats.logic, 0, 100));
1275
+
1276
  const actual = {};
1277
  Object.keys(state.stats).forEach((key) => {
1278
  const diff = state.stats[key] - before[key];
 
1281
  return actual;
1282
  }
1283
 
1284
+ function calculateMasteryDrain(beforeValue, afterValue) {
1285
+ if (afterValue <= beforeValue) return 0;
1286
+
1287
+ const over80Start = Math.max(beforeValue, 80);
1288
+ const over80End = Math.min(afterValue, 90);
1289
+ const over80Gain = Math.max(0, over80End - over80Start);
1290
+ const over90Start = Math.max(beforeValue, 90);
1291
+ const over90Gain = Math.max(0, afterValue - over90Start);
1292
+
1293
+ return over80Gain * 2 + over90Gain * 3;
1294
+ }
1295
+
1296
  function formatDelta(delta) {
1297
  const entries = Object.entries(delta || {}).filter(([, value]) => value !== 0);
1298
  if (entries.length === 0) return "";