labag 1.0.6 → 1.0.8

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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { LaBaG } from "./types/LaBaG";
1
+ import { LaBaG, OneDataType, AllDataType } from "./types/LaBaG";
2
2
  import { Mode, ModeNames } from "./types/Mode";
3
3
  import { PlayLaBaG } from "./types/PlayLaBaG";
4
4
  import { JsonLaBaG } from "./types/JsonLaBaG";
5
5
  import { P, PData } from "./types/P";
6
6
  declare const PDatas: Record<string, PData>;
7
7
  declare const Modes: Record<Exclude<ModeNames, "Normal">, Mode>;
8
- export { LaBaG, PlayLaBaG, JsonLaBaG, Modes, ModeNames, P, PData, PDatas };
8
+ export { OneDataType, AllDataType, LaBaG, PlayLaBaG, JsonLaBaG, Modes, ModeNames, P, PData, PDatas, };
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ const Modes = {
59
59
  Score: 0,
60
60
  RandNum: 0,
61
61
  Random() {
62
- this.RandNum = (0, RandInt_1.RandInt)();
62
+ this.RandNum = (0, RandInt_1.RandInt)(1, 100);
63
63
  },
64
64
  Judge(Game) {
65
65
  if (!Game.GameRunning() ||
@@ -105,7 +105,7 @@ const Modes = {
105
105
  Score: 0, // 咖波累積數
106
106
  RandNum: 0,
107
107
  Random() {
108
- this.RandNum = (0, RandInt_1.RandInt)();
108
+ this.RandNum = (0, RandInt_1.RandInt)(1, 100);
109
109
  },
110
110
  Judge(Game) {
111
111
  if (!Game.GameRunning() ||
@@ -0,0 +1,26 @@
1
+ import { AllDataType, LaBaG, OneDataType } from "./LaBaG";
2
+ import { ModeNames } from "./Mode";
3
+ import { P } from "./P";
4
+ export declare class BaseLaBaG implements LaBaG {
5
+ AllData: AllDataType;
6
+ OneData: OneDataType;
7
+ DataIndex: number;
8
+ Times: number;
9
+ Played: number;
10
+ Score: number;
11
+ MarginScore: number;
12
+ Ps: [P | null, P | null, P | null];
13
+ RateRanges: Record<ModeNames, number[]>;
14
+ ScoreTimes: Record<ModeNames, number>;
15
+ ScoreTime: number;
16
+ ModeToScreen: boolean;
17
+ constructor();
18
+ GameRunning(): boolean;
19
+ NowMode(): ModeNames;
20
+ Reset(): void;
21
+ Random(): void;
22
+ CalculateScore(): void;
23
+ Result(): void;
24
+ JudgeMode(): void;
25
+ Logic(): void;
26
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseLaBaG = void 0;
4
+ const __1 = require("..");
5
+ const P_1 = require("./P");
6
+ const RandInt_1 = require("src/utils/RandInt");
7
+ class BaseLaBaG {
8
+ AllData = {};
9
+ OneData = {};
10
+ DataIndex = 0;
11
+ Times = 30;
12
+ Played = 0;
13
+ Score = 0;
14
+ MarginScore = 0;
15
+ Ps = [null, null, null];
16
+ RateRanges = [
17
+ "Normal",
18
+ "SuperHHH",
19
+ "GreenWei",
20
+ "PiKaChu",
21
+ ].reduce((Ranges, mode) => {
22
+ const res = [];
23
+ let accRate = 0;
24
+ for (const p of P_1.P.Map.values()) {
25
+ accRate += p.rates[mode];
26
+ res.push(accRate);
27
+ }
28
+ Ranges[mode] = res;
29
+ return Ranges;
30
+ }, {});
31
+ ScoreTimes = {
32
+ Normal: 1,
33
+ SuperHHH: 1,
34
+ GreenWei: 3,
35
+ PiKaChu: 1,
36
+ };
37
+ ScoreTime = 1;
38
+ ModeToScreen = false;
39
+ constructor() { }
40
+ GameRunning() {
41
+ //遊戲進行
42
+ return this.Times > this.Played;
43
+ }
44
+ NowMode() {
45
+ // 查找當前模式
46
+ const mode = Object.entries(__1.Modes).find(([_, mode]) => mode.InMode ?? false);
47
+ return mode ? mode[0] : "Normal";
48
+ }
49
+ Reset() {
50
+ // 重置
51
+ this.AllData = {};
52
+ this.DataIndex = 0;
53
+ this.Played = 0;
54
+ this.Score = 0;
55
+ this.MarginScore = 0;
56
+ this.ScoreTime = 1;
57
+ this.Ps = [null, null, null];
58
+ Object.values(__1.Modes).forEach((mode) => {
59
+ if (mode.InMode !== undefined)
60
+ mode.InMode = false;
61
+ if (mode.Score !== undefined)
62
+ mode.Score = 0;
63
+ if (mode.RandNum !== undefined)
64
+ mode.RandNum = 0;
65
+ if (mode.Times !== undefined)
66
+ mode.Times = 0;
67
+ });
68
+ }
69
+ Random() {
70
+ const RandNums = Array.from({ length: 3 }, () => (0, RandInt_1.RandInt)(1, 100));
71
+ RandNums.forEach((RandNum, index) => {
72
+ this.OneData[`RandNums[${index}]`] = RandNum;
73
+ });
74
+ Object.values(__1.Modes).forEach((mode) => {
75
+ mode.Random?.();
76
+ });
77
+ this.OneData["SuperHHH"] = __1.Modes.SuperHHH.RandNum;
78
+ this.OneData["GreenWei"] = __1.Modes.GreenWei.RandNum;
79
+ const RateRange = this.RateRanges[this.NowMode()];
80
+ const PCodes = Array.from(P_1.P.Map.keys());
81
+ RandNums.forEach((RandNum, i) => {
82
+ const code = PCodes.find((_, j) => RandNum <= RateRange[j]);
83
+ if (code) {
84
+ this.Ps[i] = P_1.P.Map.get(code) ?? null;
85
+ }
86
+ });
87
+ // 累積咖波累積數
88
+ this.Ps.forEach((p) => {
89
+ if (__1.Modes.GreenWei.Score !== undefined) {
90
+ if (p?.code === "A" && __1.Modes.GreenWei.Score < 20) {
91
+ __1.Modes.GreenWei.Score += 1;
92
+ }
93
+ }
94
+ });
95
+ }
96
+ CalculateScore() {
97
+ //計算分數
98
+ const UniqueCount = new Set(this.Ps.map((p) => p?.code)).size;
99
+ switch (UniqueCount) {
100
+ case 1: // 三個一樣
101
+ this.MarginScore += this.Ps[0]?.scores?.[0];
102
+ break;
103
+ case 2: // 兩個一樣
104
+ if (this.Ps[0]?.code === this.Ps[1]?.code) {
105
+ this.MarginScore += this.Ps[0]?.scores?.[1];
106
+ this.MarginScore += this.Ps[2]?.scores?.[2];
107
+ this.MarginScore = Math.round(this.MarginScore / 1.4);
108
+ }
109
+ else if (this.Ps[1]?.code === this.Ps[2]?.code) {
110
+ this.MarginScore += this.Ps[1]?.scores?.[1];
111
+ this.MarginScore += this.Ps[0]?.scores?.[2];
112
+ this.MarginScore = Math.round(this.MarginScore / 1.4);
113
+ }
114
+ else if (this.Ps[2]?.code === this.Ps[0]?.code) {
115
+ this.MarginScore += this.Ps[2]?.scores?.[1];
116
+ this.MarginScore += this.Ps[1]?.scores?.[2];
117
+ this.MarginScore = Math.round(this.MarginScore / 1.4);
118
+ }
119
+ break;
120
+ case 3: // 三個不一樣
121
+ this.MarginScore += this.Ps[0]?.scores?.[2];
122
+ this.MarginScore += this.Ps[1]?.scores?.[2];
123
+ this.MarginScore += this.Ps[2]?.scores?.[2];
124
+ this.MarginScore = Math.round(this.MarginScore / 3);
125
+ break;
126
+ }
127
+ // 根據當前模式更新加分倍數
128
+ this.ScoreTime = this.ScoreTimes[this.NowMode()];
129
+ this.MarginScore *= this.ScoreTime;
130
+ }
131
+ Result() {
132
+ // 結果
133
+ this.Played += 1;
134
+ this.DataIndex += 1;
135
+ this.Score += this.MarginScore;
136
+ this.AllData[`${this.DataIndex}`] = this.OneData;
137
+ }
138
+ JudgeMode() {
139
+ if (!this.GameRunning()) {
140
+ __1.Modes.PiKaChu.Judge?.(this);
141
+ return;
142
+ }
143
+ const mode = this.NowMode();
144
+ switch (mode) {
145
+ case "Normal":
146
+ case "PiKaChu":
147
+ __1.Modes.SuperHHH.Judge?.(this);
148
+ if (!__1.Modes.SuperHHH.InMode) {
149
+ __1.Modes.GreenWei.Judge?.(this);
150
+ }
151
+ break;
152
+ case "SuperHHH":
153
+ __1.Modes.SuperHHH.Judge?.(this);
154
+ break;
155
+ case "GreenWei":
156
+ __1.Modes.GreenWei.Judge?.(this);
157
+ break;
158
+ }
159
+ }
160
+ Logic() {
161
+ // 邏輯流程
162
+ this.Reset();
163
+ while (this.GameRunning()) {
164
+ this.ModeToScreen = false;
165
+ this.OneData = {};
166
+ this.MarginScore = 0;
167
+ this.Random();
168
+ this.CalculateScore();
169
+ this.Result();
170
+ this.JudgeMode();
171
+ }
172
+ }
173
+ }
174
+ exports.BaseLaBaG = BaseLaBaG;
@@ -1,4 +1,4 @@
1
- import { BaseLaBaG } from "./LaBaG";
1
+ import { BaseLaBaG } from "./BaseLaBaG";
2
2
  export declare class JsonLaBaG extends BaseLaBaG {
3
3
  jsonData: BaseLaBaG["AllData"];
4
4
  dataIndex: number;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonLaBaG = void 0;
4
4
  const P_1 = require("./P");
5
- const LaBaG_1 = require("./LaBaG");
6
5
  const __1 = require("..");
7
- class JsonLaBaG extends LaBaG_1.BaseLaBaG {
6
+ const BaseLaBaG_1 = require("./BaseLaBaG");
7
+ class JsonLaBaG extends BaseLaBaG_1.BaseLaBaG {
8
8
  jsonData;
9
9
  dataIndex;
10
10
  constructor() {
@@ -20,10 +20,9 @@ class JsonLaBaG extends LaBaG_1.BaseLaBaG {
20
20
  this.dataIndex = 0;
21
21
  }
22
22
  Random() {
23
- const currData = this.jsonData[this.dataIndex];
23
+ const currData = this.jsonData[`${this.dataIndex}`];
24
24
  if (!currData) {
25
- super.Random();
26
- return;
25
+ throw new Error("No data found for the current index");
27
26
  }
28
27
  try {
29
28
  const RandNums = [
@@ -1,8 +1,10 @@
1
1
  import { P } from "../types/P";
2
2
  import { ModeNames } from "../types/Mode";
3
+ export type OneDataType = Partial<Record<"SuperHHH" | "GreenWei" | `RandNum[${0 | 1 | 2}]`, number>>;
4
+ export type AllDataType = Record<`${number}`, OneDataType>;
3
5
  export interface LaBaG {
4
- AllData: Record<string, Record<string, number>>;
5
- OneData: Record<string, number>;
6
+ AllData: AllDataType;
7
+ OneData: OneDataType;
6
8
  DataIndex: number;
7
9
  Times: number;
8
10
  Played: number;
@@ -22,26 +24,3 @@ export interface LaBaG {
22
24
  JudgeMode(): void;
23
25
  Logic(): void;
24
26
  }
25
- export declare class BaseLaBaG implements LaBaG {
26
- AllData: Record<string, Record<string, number>>;
27
- OneData: Record<string, number>;
28
- DataIndex: number;
29
- Times: number;
30
- Played: number;
31
- Score: number;
32
- MarginScore: number;
33
- Ps: [P | null, P | null, P | null];
34
- RateRanges: Record<ModeNames, number[]>;
35
- ScoreTimes: Record<ModeNames, number>;
36
- ScoreTime: number;
37
- ModeToScreen: boolean;
38
- constructor();
39
- GameRunning(): boolean;
40
- NowMode(): ModeNames;
41
- Reset(): void;
42
- Random(): void;
43
- CalculateScore(): void;
44
- Result(): void;
45
- JudgeMode(): void;
46
- Logic(): void;
47
- }
@@ -1,174 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseLaBaG = void 0;
4
- const P_1 = require("../types/P");
5
- const RandInt_1 = require("../utils/RandInt");
6
- const __1 = require("..");
7
- class BaseLaBaG {
8
- AllData = {};
9
- OneData = {};
10
- DataIndex = 0;
11
- Times = 30;
12
- Played = 0;
13
- Score = 0;
14
- MarginScore = 0;
15
- Ps = [null, null, null];
16
- RateRanges = [
17
- "Normal",
18
- "SuperHHH",
19
- "GreenWei",
20
- "PiKaChu",
21
- ].reduce((Ranges, mode) => {
22
- const res = [];
23
- let accRate = 0;
24
- for (const p of P_1.P.Map.values()) {
25
- accRate += p.rates[mode];
26
- res.push(accRate);
27
- }
28
- Ranges[mode] = res;
29
- return Ranges;
30
- }, {});
31
- ScoreTimes = {
32
- Normal: 1,
33
- SuperHHH: 1,
34
- GreenWei: 3,
35
- PiKaChu: 1,
36
- };
37
- ScoreTime = 1;
38
- ModeToScreen = false;
39
- constructor() { }
40
- GameRunning() {
41
- //遊戲進行
42
- return this.Times > this.Played;
43
- }
44
- NowMode() {
45
- // 查找當前模式
46
- const mode = Object.entries(__1.Modes).find(([_, mode]) => mode.InMode ?? false);
47
- return mode ? mode[0] : "Normal";
48
- }
49
- Reset() {
50
- // 重置
51
- this.AllData = {};
52
- this.DataIndex = 0;
53
- this.Played = 0;
54
- this.Score = 0;
55
- this.MarginScore = 0;
56
- this.ScoreTime = 1;
57
- this.Ps = [null, null, null];
58
- Object.values(__1.Modes).forEach((mode) => {
59
- if (mode.InMode !== undefined)
60
- mode.InMode = false;
61
- if (mode.Score !== undefined)
62
- mode.Score = 0;
63
- if (mode.RandNum !== undefined)
64
- mode.RandNum = 0;
65
- if (mode.Times !== undefined)
66
- mode.Times = 0;
67
- });
68
- }
69
- Random() {
70
- const RandNums = Array.from({ length: 3 }, () => (0, RandInt_1.RandInt)());
71
- RandNums.forEach((RandNum, index) => {
72
- this.OneData[`RandNums[${index}]`] = RandNum;
73
- });
74
- Object.values(__1.Modes).forEach((mode) => {
75
- mode.Random?.();
76
- });
77
- this.OneData["SuperHHH"] = __1.Modes.SuperHHH.RandNum;
78
- this.OneData["GreenWei"] = __1.Modes.GreenWei.RandNum;
79
- const RateRange = this.RateRanges[this.NowMode()];
80
- const PCodes = Array.from(P_1.P.Map.keys());
81
- RandNums.forEach((RandNum, i) => {
82
- const code = PCodes.find((_, j) => RandNum <= RateRange[j]);
83
- if (code) {
84
- this.Ps[i] = P_1.P.Map.get(code) ?? null;
85
- }
86
- });
87
- // 累積咖波累積數
88
- this.Ps.forEach((p) => {
89
- if (__1.Modes.GreenWei.Score !== undefined) {
90
- if (p?.code === "A" && __1.Modes.GreenWei.Score < 20) {
91
- __1.Modes.GreenWei.Score += 1;
92
- }
93
- }
94
- });
95
- }
96
- CalculateScore() {
97
- //計算分數
98
- const UniqueCount = new Set(this.Ps.map((p) => p?.code)).size;
99
- switch (UniqueCount) {
100
- case 1: // 三個一樣
101
- this.MarginScore += this.Ps[0]?.scores?.[0];
102
- break;
103
- case 2: // 兩個一樣
104
- if (this.Ps[0]?.code === this.Ps[1]?.code) {
105
- this.MarginScore += this.Ps[0]?.scores?.[1];
106
- this.MarginScore += this.Ps[2]?.scores?.[2];
107
- this.MarginScore = Math.round(this.MarginScore / 1.4);
108
- }
109
- else if (this.Ps[1]?.code === this.Ps[2]?.code) {
110
- this.MarginScore += this.Ps[1]?.scores?.[1];
111
- this.MarginScore += this.Ps[0]?.scores?.[2];
112
- this.MarginScore = Math.round(this.MarginScore / 1.4);
113
- }
114
- else if (this.Ps[2]?.code === this.Ps[0]?.code) {
115
- this.MarginScore += this.Ps[2]?.scores?.[1];
116
- this.MarginScore += this.Ps[1]?.scores?.[2];
117
- this.MarginScore = Math.round(this.MarginScore / 1.4);
118
- }
119
- break;
120
- case 3: // 三個不一樣
121
- this.MarginScore += this.Ps[0]?.scores?.[2];
122
- this.MarginScore += this.Ps[1]?.scores?.[2];
123
- this.MarginScore += this.Ps[2]?.scores?.[2];
124
- this.MarginScore = Math.round(this.MarginScore / 3);
125
- break;
126
- }
127
- // 根據當前模式更新加分倍數
128
- this.ScoreTime = this.ScoreTimes[this.NowMode()];
129
- this.MarginScore *= this.ScoreTime;
130
- }
131
- Result() {
132
- // 結果
133
- this.Played += 1;
134
- this.DataIndex += 1;
135
- this.Score += this.MarginScore;
136
- this.AllData[`${this.DataIndex}`] = this.OneData;
137
- }
138
- JudgeMode() {
139
- if (!this.GameRunning()) {
140
- __1.Modes.PiKaChu.Judge?.(this);
141
- return;
142
- }
143
- const mode = this.NowMode();
144
- switch (mode) {
145
- case "Normal":
146
- case "PiKaChu":
147
- __1.Modes.SuperHHH.Judge?.(this);
148
- if (!__1.Modes.SuperHHH.InMode) {
149
- __1.Modes.GreenWei.Judge?.(this);
150
- }
151
- break;
152
- case "SuperHHH":
153
- __1.Modes.SuperHHH.Judge?.(this);
154
- break;
155
- case "GreenWei":
156
- __1.Modes.GreenWei.Judge?.(this);
157
- break;
158
- }
159
- }
160
- Logic() {
161
- // 邏輯流程
162
- this.Reset();
163
- while (this.GameRunning()) {
164
- this.ModeToScreen = false;
165
- this.OneData = {};
166
- this.MarginScore = 0;
167
- this.Random();
168
- this.CalculateScore();
169
- this.Result();
170
- this.JudgeMode();
171
- }
172
- }
173
- }
174
- exports.BaseLaBaG = BaseLaBaG;
@@ -1,4 +1,4 @@
1
- import { BaseLaBaG } from "./LaBaG";
1
+ import { BaseLaBaG } from "./BaseLaBaG";
2
2
  export declare class PlayLaBaG extends BaseLaBaG {
3
3
  Reset(): void;
4
4
  Random(): void;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlayLaBaG = void 0;
4
4
  const __1 = require("..");
5
- const LaBaG_1 = require("./LaBaG");
6
- class PlayLaBaG extends LaBaG_1.BaseLaBaG {
5
+ const BaseLaBaG_1 = require("./BaseLaBaG");
6
+ class PlayLaBaG extends BaseLaBaG_1.BaseLaBaG {
7
7
  Reset() {
8
8
  super.Reset();
9
9
  console.log("遊戲已重置");
@@ -1 +1 @@
1
- export declare function RandInt(): number;
1
+ export declare function RandInt(min: number, max: number): number;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RandInt = RandInt;
4
- function RandInt() {
5
- const min = 1;
6
- const max = 100;
4
+ function RandInt(min, max) {
7
5
  return Math.floor(Math.random() * (max - min + 1)) + min;
8
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LaBaG } from "./types/LaBaG";
1
+ import { LaBaG, OneDataType, AllDataType } from "./types/LaBaG";
2
2
  import { Mode, ModeNames } from "./types/Mode";
3
3
  import { RandInt } from "./utils/RandInt";
4
4
  import { PlayLaBaG } from "./types/PlayLaBaG";
@@ -179,4 +179,17 @@ const Modes: Record<Exclude<ModeNames, "Normal">, Mode> = {
179
179
  },
180
180
  };
181
181
 
182
- export { LaBaG, PlayLaBaG, JsonLaBaG, Modes, ModeNames, P, PData, PDatas };
182
+ export {
183
+ OneDataType,
184
+ AllDataType,
185
+ LaBaG,
186
+ PlayLaBaG,
187
+ JsonLaBaG,
188
+
189
+ Modes,
190
+ ModeNames,
191
+
192
+ P,
193
+ PData,
194
+ PDatas,
195
+ };
@@ -1,4 +1,4 @@
1
- import { Modes } from "src";
1
+ import { Modes } from "..";
2
2
  import { AllDataType, LaBaG, OneDataType } from "./LaBaG";
3
3
  import { Mode, ModeNames } from "./Mode";
4
4
  import { P } from "./P";
@@ -23,8 +23,7 @@ export class JsonLaBaG extends BaseLaBaG {
23
23
  Random(): void {
24
24
  const currData = this.jsonData[`${this.dataIndex}`];
25
25
  if (!currData) {
26
- super.Random();
27
- return;
26
+ throw new Error("No data found for the current index");
28
27
  }
29
28
 
30
29
  try {