labag 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,87 +3,93 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const pattern_1 = require("../pattern");
4
4
  const mode_1 = require("../mode");
5
5
  const randInt_1 = require("../utils/randInt");
6
- exports.default = new mode_1.Mode(false, "greenwei", {
7
- gss: 0,
8
- hhh: 0,
9
- hentai: 0,
10
- handson: 0,
11
- kachu: 0,
12
- rrr: 0,
13
- }, {
14
- gameStart: (_, mode) => {
15
- mode.active = false;
16
- mode.variable.times = 0;
17
- mode.variable.count = 0;
6
+ exports.default = new mode_1.Mode({
7
+ active: false,
8
+ name: "greenwei",
9
+ rates: {
10
+ gss: 0,
11
+ hhh: 0,
12
+ hentai: 0,
13
+ handson: 0,
14
+ kachu: 0,
15
+ rrr: 0,
18
16
  },
19
- roundStart: (_, mode) => {
20
- if (!mode.active)
21
- return;
22
- mode.variable.times -= 1;
23
- },
24
- rollSlots: (_, mode) => {
25
- mode.variable.randNum = (0, randInt_1.randInt)(1, 100);
26
- },
27
- calculateScore: (game, mode) => {
28
- if (mode.active) {
29
- game.marginScore = Math.round(game.marginScore * mode.variable.mutiplier);
30
- }
31
- },
32
- roundEnd: (game, mode) => {
33
- const { patterns } = game;
34
- const { variable } = mode;
35
- let gssCount = 0;
36
- let allGSS = true;
37
- for (const p of patterns) {
38
- if (p?.name === mode.variable.bindPattern.name) {
39
- gssCount++;
40
- }
41
- else {
42
- allGSS = false;
43
- }
44
- }
45
- variable.count += gssCount;
46
- if (mode.active) {
47
- if (allGSS) {
48
- variable.times += mode.variable.extendTimes;
49
- }
50
- if (variable.times <= 0) {
51
- mode.active = false;
17
+ eventListener: {
18
+ gameStart: (_, mode) => {
19
+ mode.active = false;
20
+ mode.variable.times = 0;
21
+ mode.variable.count = 0;
22
+ },
23
+ roundStart: (_, mode) => {
24
+ if (!mode.active)
25
+ return;
26
+ mode.variable.times -= 1;
27
+ },
28
+ rollSlots: (_, mode) => {
29
+ mode.variable.randNum = (0, randInt_1.randInt)(1, 100);
30
+ },
31
+ calculateScore: (game, mode) => {
32
+ if (mode.active) {
33
+ game.marginScore = Math.round(game.marginScore * mode.variable.mutiplier);
52
34
  }
53
- }
54
- if (!mode.active) {
55
- let activated = false;
56
- if (variable.randNum <= variable.rate && allGSS) {
57
- activated = true;
58
- variable.times += mode.variable.extendTimes;
35
+ },
36
+ roundEnd: (game, mode) => {
37
+ const { patterns } = game;
38
+ const { variable } = mode;
39
+ let gssCount = 0;
40
+ let allGSS = true;
41
+ for (const p of patterns) {
42
+ if (p?.name === mode.variable.bindPattern.name) {
43
+ gssCount++;
44
+ }
45
+ else {
46
+ allGSS = false;
47
+ }
59
48
  }
60
- else if (variable.count >= mode.variable.requiredBindPatternCount) {
61
- activated = true;
62
- variable.times += mode.variable.bonusTimes;
63
- variable.count -= mode.variable.requiredBindPatternCount;
49
+ variable.count += gssCount;
50
+ if (mode.active) {
51
+ if (allGSS) {
52
+ variable.times += mode.variable.extendTimes;
53
+ }
54
+ if (variable.times <= 0) {
55
+ mode.active = false;
56
+ }
64
57
  }
65
- if (activated) {
66
- mode.active = true;
67
- for (let i = 0; i < patterns.length; i++) {
68
- if (patterns[i]?.name === mode.variable.bindPattern.name) {
69
- patterns[i] = variable.pattern;
58
+ if (!mode.active) {
59
+ let activated = false;
60
+ if (variable.randNum <= variable.rate && allGSS) {
61
+ activated = true;
62
+ variable.times += mode.variable.extendTimes;
63
+ }
64
+ else if (variable.count >= mode.variable.requiredBindPatternCount) {
65
+ activated = true;
66
+ variable.times += mode.variable.bonusTimes;
67
+ variable.count -= mode.variable.requiredBindPatternCount;
68
+ }
69
+ if (activated) {
70
+ mode.active = true;
71
+ for (let i = 0; i < patterns.length; i++) {
72
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
73
+ patterns[i] = variable.pattern;
74
+ }
70
75
  }
71
76
  }
72
77
  }
73
- }
78
+ },
74
79
  },
75
- }, {
76
- times: 0,
77
- rate: 35,
78
- randNum: 0,
79
- count: 0,
80
- pattern: {
81
- name: "greenwei",
82
- scores: [800, 400, 180],
80
+ variable: {
81
+ times: 0,
82
+ rate: 35,
83
+ randNum: 0,
84
+ count: 0,
85
+ pattern: {
86
+ name: "greenwei",
87
+ scores: [800, 400, 180],
88
+ },
89
+ extendTimes: 2,
90
+ bindPattern: pattern_1.patterns[0],
91
+ bonusTimes: 2,
92
+ requiredBindPatternCount: 20,
93
+ mutiplier: 3,
83
94
  },
84
- extendTimes: 2,
85
- bindPattern: pattern_1.patterns[0],
86
- bonusTimes: 2,
87
- requiredBindPatternCount: 20,
88
- mutiplier: 3,
89
95
  });
@@ -1,4 +1,4 @@
1
- export declare const modes: {
1
+ export declare const _modes: {
2
2
  pikachu: import("..").Mode<{
3
3
  times: number;
4
4
  pattern: {
@@ -10,7 +10,7 @@ export declare const modes: {
10
10
  readonly scores: [12000, 8000, 1250];
11
11
  };
12
12
  bonusRounds: number;
13
- }>;
13
+ }, "pikachu">;
14
14
  superhhh: import("..").Mode<{
15
15
  times: number;
16
16
  rate: number;
@@ -26,7 +26,7 @@ export declare const modes: {
26
26
  scores: number[];
27
27
  };
28
28
  extendTimes: number;
29
- }>;
29
+ }, "superhhh">;
30
30
  greenwei: import("..").Mode<{
31
31
  times: number;
32
32
  rate: number;
@@ -44,11 +44,9 @@ export declare const modes: {
44
44
  bonusTimes: number;
45
45
  requiredBindPatternCount: number;
46
46
  mutiplier: number;
47
- }>;
48
- normal: import("..").Mode<Record<string, any>>;
47
+ }, "greenwei">;
49
48
  };
50
- export type ModeName = keyof typeof modes;
51
- export declare const modeList: (import("..").Mode<{
49
+ export declare const modes: (import("..").Mode<{
52
50
  times: number;
53
51
  rate: number;
54
52
  randNum: number;
@@ -65,7 +63,7 @@ export declare const modeList: (import("..").Mode<{
65
63
  bonusTimes: number;
66
64
  requiredBindPatternCount: number;
67
65
  mutiplier: number;
68
- }> | import("..").Mode<Record<string, any>> | import("..").Mode<{
66
+ }, "greenwei"> | import("..").Mode<{
69
67
  times: number;
70
68
  pattern: {
71
69
  name: string;
@@ -76,7 +74,7 @@ export declare const modeList: (import("..").Mode<{
76
74
  readonly scores: [12000, 8000, 1250];
77
75
  };
78
76
  bonusRounds: number;
79
- }> | import("..").Mode<{
77
+ }, "pikachu"> | import("..").Mode<{
80
78
  times: number;
81
79
  rate: number;
82
80
  score: number;
@@ -91,4 +89,4 @@ export declare const modeList: (import("..").Mode<{
91
89
  scores: number[];
92
90
  };
93
91
  extendTimes: number;
94
- }>)[];
92
+ }, "superhhh">)[];
@@ -3,15 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.modeList = exports.modes = void 0;
6
+ exports.modes = exports._modes = void 0;
7
7
  const greenwei_1 = __importDefault(require("./greenwei"));
8
- const normal_1 = __importDefault(require("./normal"));
9
8
  const pikachu_1 = __importDefault(require("./pikachu"));
10
9
  const superhhh_1 = __importDefault(require("./superhhh"));
11
- exports.modes = {
12
- pikachu: pikachu_1.default,
13
- superhhh: superhhh_1.default,
14
- greenwei: greenwei_1.default,
15
- normal: normal_1.default,
16
- };
17
- exports.modeList = Object.values(exports.modes);
10
+ exports._modes = { pikachu: pikachu_1.default, superhhh: superhhh_1.default, greenwei: greenwei_1.default };
11
+ exports.modes = Object.values(exports._modes);
@@ -10,5 +10,5 @@ declare const _default: Mode<{
10
10
  readonly scores: [12000, 8000, 1250];
11
11
  };
12
12
  bonusRounds: number;
13
- }>;
13
+ }, "pikachu">;
14
14
  export default _default;
@@ -2,42 +2,48 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const pattern_1 = require("../pattern");
4
4
  const mode_1 = require("../mode");
5
- exports.default = new mode_1.Mode(false, "pikachu", {
6
- gss: 0,
7
- hhh: 0,
8
- hentai: 0,
9
- handson: 0,
10
- kachu: 0,
11
- rrr: 0,
12
- }, {
13
- gameStart: (_, mode) => {
14
- mode.active = false;
15
- mode.variable.times = 0;
5
+ exports.default = new mode_1.Mode({
6
+ active: false,
7
+ name: "pikachu",
8
+ rates: {
9
+ gss: 0,
10
+ hhh: 0,
11
+ hentai: 0,
12
+ handson: 0,
13
+ kachu: 0,
14
+ rrr: 0,
16
15
  },
17
- roundEnd: (game, mode) => {
18
- const { patterns } = game;
19
- const hasBindPattern = patterns.some((p) => p && p.name === mode.variable.bindPattern.name);
20
- if (!game.isRunning() && hasBindPattern) {
21
- mode.active = true;
22
- game.played -= mode.variable.bonusRounds;
23
- mode.variable.times += 1;
24
- patterns.forEach((p, i) => {
25
- if (p?.name === mode.variable.bindPattern.name) {
26
- patterns[i] = mode.variable.pattern;
27
- }
28
- });
29
- return;
30
- }
31
- if (mode.active && hasBindPattern) {
32
- game.played -= Math.min(mode.variable.times, mode.variable.bonusRounds);
33
- }
16
+ eventListener: {
17
+ gameStart: (_, mode) => {
18
+ mode.active = false;
19
+ mode.variable.times = 0;
20
+ },
21
+ roundEnd: (game, mode) => {
22
+ const { patterns } = game;
23
+ const hasBindPattern = patterns.some((p) => p && p.name === mode.variable.bindPattern.name);
24
+ if (!game.isRunning && hasBindPattern) {
25
+ mode.active = true;
26
+ game.played -= mode.variable.bonusRounds;
27
+ mode.variable.times += 1;
28
+ patterns.forEach((p, i) => {
29
+ if (p?.name === mode.variable.bindPattern.name) {
30
+ patterns[i] = mode.variable.pattern;
31
+ }
32
+ });
33
+ return;
34
+ }
35
+ if (mode.active && hasBindPattern) {
36
+ game.played -= Math.min(mode.variable.times, mode.variable.bonusRounds);
37
+ }
38
+ },
34
39
  },
35
- }, {
36
- times: 0,
37
- pattern: {
38
- name: "pikachu",
39
- scores: [12000, 8000, 1250],
40
+ variable: {
41
+ times: 0,
42
+ pattern: {
43
+ name: "pikachu",
44
+ scores: [12000, 8000, 1250],
45
+ },
46
+ bindPattern: pattern_1.patterns[4],
47
+ bonusRounds: 3,
40
48
  },
41
- bindPattern: pattern_1.patterns[4],
42
- bonusRounds: 3,
43
49
  });
@@ -14,5 +14,5 @@ declare const _default: Mode<{
14
14
  scores: number[];
15
15
  };
16
16
  extendTimes: number;
17
- }>;
17
+ }, "superhhh">;
18
18
  export default _default;
@@ -3,78 +3,84 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const pattern_1 = require("../pattern");
4
4
  const mode_1 = require("../mode");
5
5
  const randInt_1 = require("../utils/randInt");
6
- exports.default = new mode_1.Mode(false, "superhhh", {
7
- gss: -19, // 36 -> 17
8
- hhh: -19, // 24 -> 5
9
- hentai: 1, // 17 -> 18
10
- handson: 7, // 12 -> 19
11
- kachu: 12, // 8 -> 20
12
- rrr: 18, // 3 -> 21
13
- }, {
14
- gameStart: (_, mode) => {
15
- mode.active = false;
16
- mode.variable.times = 0;
17
- mode.variable.score = 0;
6
+ exports.default = new mode_1.Mode({
7
+ active: false,
8
+ name: "superhhh",
9
+ rates: {
10
+ gss: -19, // 36 -> 17
11
+ hhh: -19, // 24 -> 5
12
+ hentai: 1, // 17 -> 18
13
+ handson: 7, // 12 -> 19
14
+ kachu: 12, // 8 -> 20
15
+ rrr: 18, // 3 -> 21
18
16
  },
19
- roundStart: (_, mode) => {
20
- if (!mode.active)
21
- return;
22
- mode.variable.score = 0;
23
- mode.variable.times -= 1;
24
- },
25
- rollSlots: (_, mode) => {
26
- mode.variable.randNum = (0, randInt_1.randInt)(1, 100);
27
- },
28
- calculateScore: (game, mode) => {
29
- if (mode.active)
30
- return;
31
- if (game.patterns.every((p) => p?.name === mode.variable.bindPattern.name) &&
32
- mode.variable.randNum <= mode.variable.rate) {
33
- mode.variable.score += Math.round(game.score / 2);
34
- game.marginScore += mode.variable.score;
35
- }
36
- },
37
- roundEnd: (game, mode) => {
38
- const { patterns } = game;
39
- const { variable } = mode;
40
- let hhhCount = 0;
41
- let allHHH = true;
42
- for (const p of patterns) {
43
- if (p?.name === mode.variable.bindPattern.name)
44
- hhhCount++;
45
- else
46
- allHHH = false;
47
- }
48
- if (mode.active) {
49
- if (allHHH) {
50
- variable.times += mode.variable.extendTimes;
17
+ eventListener: {
18
+ gameStart: (_, mode) => {
19
+ mode.active = false;
20
+ mode.variable.times = 0;
21
+ mode.variable.score = 0;
22
+ },
23
+ roundStart: (_, mode) => {
24
+ if (!mode.active)
25
+ return;
26
+ mode.variable.score = 0;
27
+ mode.variable.times -= 1;
28
+ },
29
+ rollSlots: (_, mode) => {
30
+ mode.variable.randNum = (0, randInt_1.randInt)(1, 100);
31
+ },
32
+ calculateScore: (game, mode) => {
33
+ if (mode.active)
34
+ return;
35
+ if (game.patterns.every((p) => p?.name === mode.variable.bindPattern.name) &&
36
+ mode.variable.randNum <= mode.variable.rate) {
37
+ mode.variable.score += Math.round(game.score / 2);
38
+ game.marginScore += mode.variable.score;
51
39
  }
52
- if (variable.times <= 0) {
53
- mode.active = false;
40
+ },
41
+ roundEnd: (game, mode) => {
42
+ const { patterns } = game;
43
+ const { variable } = mode;
44
+ let hhhCount = 0;
45
+ let allHHH = true;
46
+ for (const p of patterns) {
47
+ if (p?.name === mode.variable.bindPattern.name)
48
+ hhhCount++;
49
+ else
50
+ allHHH = false;
51
+ }
52
+ if (mode.active) {
53
+ if (allHHH) {
54
+ variable.times += mode.variable.extendTimes;
55
+ }
56
+ if (variable.times <= 0) {
57
+ mode.active = false;
58
+ }
54
59
  }
55
- }
56
- if (!mode.active) {
57
- if (variable.randNum <= variable.rate && hhhCount > 0) {
58
- mode.active = true;
59
- variable.times += variable.bonusTimes;
60
- for (let i = 0; i < patterns.length; i++) {
61
- if (patterns[i]?.name === mode.variable.bindPattern.name) {
62
- patterns[i] = variable.pattern;
60
+ if (!mode.active) {
61
+ if (variable.randNum <= variable.rate && hhhCount > 0) {
62
+ mode.active = true;
63
+ variable.times += variable.bonusTimes;
64
+ for (let i = 0; i < patterns.length; i++) {
65
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
66
+ patterns[i] = variable.pattern;
67
+ }
63
68
  }
64
69
  }
65
70
  }
66
- }
71
+ },
67
72
  },
68
- }, {
69
- times: 0,
70
- rate: 15,
71
- score: 0,
72
- randNum: 0,
73
- bindPattern: pattern_1.patterns[1],
74
- bonusTimes: 6,
75
- pattern: {
76
- name: "superhhh",
77
- scores: [1500, 800, 300],
73
+ variable: {
74
+ times: 0,
75
+ rate: 15,
76
+ score: 0,
77
+ randNum: 0,
78
+ bindPattern: pattern_1.patterns[1],
79
+ bonusTimes: 6,
80
+ pattern: {
81
+ name: "superhhh",
82
+ scores: [1500, 800, 300],
83
+ },
84
+ extendTimes: 2,
78
85
  },
79
- extendTimes: 2,
80
86
  });
@@ -25,12 +25,14 @@ class RecordChecker {
25
25
  this.game.init();
26
26
  this.game.times = record.times;
27
27
  for (const round of record.rounds) {
28
- if (!this.game.isRunning()) {
29
- throw new Error("遊戲次數已達上限,無法繼續遊玩。");
28
+ if (!this.game.isRunning) {
29
+ break;
30
30
  }
31
31
  // 1. 回合開始
32
- this.game["roundStart"]();
33
- // 2. 設定隨機數字與圖案 (模擬 rollSlots)
32
+ this.game.roundStart();
33
+ // 2. 觸發 rollSlots 事件,這會執行所有模式的隨機邏輯
34
+ this.game.rollSlots();
35
+ // 3. 覆蓋隨機數字與圖案 (確保使用紀錄中的數值)
34
36
  const { ranges } = this.game.getCurrentConfig();
35
37
  for (let i = 0; i < 3; i++) {
36
38
  const num = round.randNums?.[i.toString()] ?? 0;
@@ -38,22 +40,20 @@ class RecordChecker {
38
40
  const match = ranges.find((r) => num <= r.threshold);
39
41
  this.game.patterns[i] = match ? match.pattern : null;
40
42
  }
41
- // 觸發 rollSlots 事件,讓模式執行其邏輯 (例如 greenwei 產生隨機數)
42
- this.game["emit"]("rollSlots");
43
- // 3. 覆蓋模式的隨機變數 (確保使用紀錄中的數值)
43
+ // 4. 覆蓋模式的隨機變數 (確保使用紀錄中的數值)
44
44
  this.game.modes.forEach((mode) => {
45
45
  const recordedNum = round.randNums?.[mode.name];
46
46
  if (recordedNum !== undefined && mode.variable) {
47
47
  mode.variable.randNum = recordedNum;
48
48
  }
49
49
  });
50
- // 4. 計算分數
51
- this.game["calculateScore"]();
52
- // 5. 回合結束
53
- this.game["roundEnd"]();
50
+ // 5. 計算分數
51
+ this.game.calculateScore();
52
+ // 6. 回合結束
53
+ this.game.roundEnd();
54
54
  }
55
- if (!this.game.isRunning()) {
56
- this.game["gameOver"]();
55
+ if (!this.game.isRunning) {
56
+ this.game.gameOver();
57
57
  }
58
58
  return this.game.score;
59
59
  }
package/dist/test.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("./index");
4
+ const index_2 = require("./index");
4
5
  index_1.labag.addEventListener("gameStart", (game) => {
5
6
  console.log("Game Started!");
6
7
  console.log(`Total Rounds: ${game.times}\n`);
@@ -21,7 +22,8 @@ index_1.labag.addEventListener("roundEnd", (game) => {
21
22
  console.log(`Score: ${game.score}\n`);
22
23
  });
23
24
  index_1.labag.init();
24
- while (index_1.labag.isRunning()) {
25
+ index_2.recorder.init();
26
+ while (index_1.labag.isRunning) {
25
27
  index_1.labag.play();
26
28
  }
27
29
  console.log("Game Over");
@@ -30,3 +32,7 @@ console.log(`Active Modes at end: ${index_1.labag
30
32
  .getCurrentConfig()
31
33
  .modes.map((m) => m.name)
32
34
  .join(", ")}`);
35
+ console.log(`record: ${JSON.stringify(index_2.recorder.getRecord(), null, 2)}`);
36
+ console.log(index_1.checker.check(index_2.recorder.getRecord())
37
+ ? "Record is valid!"
38
+ : "Record is invalid!");
@@ -1,3 +1,4 @@
1
+ import { modes } from "src/modes";
1
2
  import { patterns } from "src/pattern";
2
3
  /**
3
4
  * 拉霸遊戲的事件類型。
@@ -16,3 +17,4 @@ export type Pattern = {
16
17
  * 圖案名稱的型別。
17
18
  */
18
19
  export type PatternName = (typeof patterns)[number]["name"];
20
+ export type ModeName = (typeof modes)[number]["name"] | "normal";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { LaBaG } from "./labag";
2
- import { modeList, ModeName } from "./modes";
2
+ import { modes } from "./modes";
3
3
  import { LaBaGEvent, Pattern, PatternName } from "./types";
4
4
  import { Mode } from "./mode";
5
5
  import { patterns } from "./pattern";
6
- import { Recorder, GameRecord } from './recorder';
6
+ import { Recorder, GameRecord } from "./recorder";
7
7
  import { RecordChecker } from "./recordChecker";
8
+ import { ModeName } from "./types/index";
8
9
 
9
10
  const labag = new LaBaG();
10
- modeList.forEach((mode) => {
11
+ modes.forEach((mode) => {
11
12
  labag.addMode(mode);
12
13
  });
13
14
  const recorder = new Recorder(labag);
@@ -16,7 +17,7 @@ export {
16
17
  labag,
17
18
  recorder,
18
19
  checker,
19
- modeList,
20
+ modes,
20
21
  patterns,
21
22
  LaBaG,
22
23
  Recorder,
@@ -25,6 +26,6 @@ export {
25
26
  type LaBaGEvent,
26
27
  type Pattern,
27
28
  type PatternName,
29
+ type GameRecord,
28
30
  type ModeName,
29
- type GameRecord
30
31
  };