labag 2.1.4 → 2.1.6

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/labag.d.ts CHANGED
@@ -36,6 +36,12 @@ export declare class LaBaG {
36
36
  * @param listener - 監聽器函式。
37
37
  */
38
38
  addEventListener(event: LaBaGEvent, callbackFn: (game: LaBaG) => void): void;
39
+ /**
40
+ * 移除事件監聽器。
41
+ * @param event - 事件名稱。
42
+ * @param listener - 監聽器函式。
43
+ */
44
+ removeEventListener(event: LaBaGEvent, callbackFn: (game: LaBaG) => void): void;
39
45
  /**
40
46
  * 新增遊戲模式。
41
47
  * @param mode - 要新增的模式。
package/dist/labag.js CHANGED
@@ -49,7 +49,7 @@ class LaBaG {
49
49
  * @param event - 要觸發的事件名稱。
50
50
  */
51
51
  emit(event) {
52
- this.eventListeners[event].forEach((fn) => fn(this));
52
+ [...this.eventListeners[event]].forEach((fn) => fn(this));
53
53
  }
54
54
  /**
55
55
  * 新增事件監聽器。
@@ -59,6 +59,17 @@ class LaBaG {
59
59
  addEventListener(event, callbackFn) {
60
60
  this.eventListeners[event].push(callbackFn);
61
61
  }
62
+ /**
63
+ * 移除事件監聽器。
64
+ * @param event - 事件名稱。
65
+ * @param listener - 監聽器函式。
66
+ */
67
+ removeEventListener(event, callbackFn) {
68
+ const index = this.eventListeners[event].indexOf(callbackFn);
69
+ if (index !== -1) {
70
+ this.eventListeners[event].splice(index, 1);
71
+ }
72
+ }
62
73
  /**
63
74
  * 新增遊戲模式。
64
75
  * @param mode - 要新增的模式。
@@ -14,11 +14,16 @@ exports.default = new mode_1.Mode(false, "pikachu", {
14
14
  mode.variable.times = 0;
15
15
  },
16
16
  roundEnd: (game, mode) => {
17
- if (!game.isRunning() &&
18
- game.patterns.some((p) => p && p.name === "kachu")) {
17
+ const { patterns } = game;
18
+ if (!game.isRunning() && patterns.some((p) => p && p.name === "kachu")) {
19
19
  mode.active = true;
20
20
  game.played -= 5;
21
21
  mode.variable.times += 1;
22
+ for (let i = 0; i < patterns.length; i++) {
23
+ if (patterns[i]?.name === 'kachu') {
24
+ patterns[i] = mode.variable.pattern;
25
+ }
26
+ }
22
27
  }
23
28
  },
24
29
  }, {
@@ -23,6 +23,15 @@ exports.default = new mode_1.Mode(false, "superhhh", {
23
23
  rollSlots: (_, mode) => {
24
24
  mode.variable.randNum = (0, randInt_1.randInt)(1, 100);
25
25
  },
26
+ calculateScore: (game, mode) => {
27
+ if (mode.active)
28
+ return;
29
+ if (game.patterns.every((p) => p?.name === "hhh") &&
30
+ mode.variable.randNum > mode.variable.rate) {
31
+ mode.variable.score += Math.round(game.score / 2);
32
+ game.marginScore = mode.variable.score;
33
+ }
34
+ },
26
35
  roundEnd: (game, mode) => {
27
36
  const { patterns } = game;
28
37
  const { variable } = mode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/labag.ts CHANGED
@@ -51,7 +51,7 @@ export class LaBaG {
51
51
  * @param event - 要觸發的事件名稱。
52
52
  */
53
53
  private emit(event: LaBaGEvent) {
54
- this.eventListeners[event].forEach((fn) => fn(this));
54
+ [...this.eventListeners[event]].forEach((fn) => fn(this));
55
55
  }
56
56
 
57
57
  /**
@@ -63,6 +63,18 @@ export class LaBaG {
63
63
  this.eventListeners[event].push(callbackFn);
64
64
  }
65
65
 
66
+ /**
67
+ * 移除事件監聽器。
68
+ * @param event - 事件名稱。
69
+ * @param listener - 監聽器函式。
70
+ */
71
+ removeEventListener(event: LaBaGEvent, callbackFn: (game: LaBaG) => void) {
72
+ const index = this.eventListeners[event].indexOf(callbackFn);
73
+ if (index !== -1) {
74
+ this.eventListeners[event].splice(index, 1);
75
+ }
76
+ }
77
+
66
78
  /**
67
79
  * 新增遊戲模式。
68
80
  * @param mode - 要新增的模式。
@@ -17,13 +17,16 @@ export default new Mode(
17
17
  mode.variable.times = 0;
18
18
  },
19
19
  roundEnd: (game, mode) => {
20
- if (
21
- !game.isRunning() &&
22
- game.patterns.some((p) => p && p.name === "kachu")
23
- ) {
20
+ const { patterns } = game;
21
+ if (!game.isRunning() && patterns.some((p) => p && p.name === "kachu")) {
24
22
  mode.active = true;
25
23
  game.played -= 5;
26
24
  mode.variable.times += 1;
25
+ for (let i = 0; i < patterns.length; i++) {
26
+ if (patterns[i]?.name === 'kachu') {
27
+ patterns[i] = mode.variable.pattern;
28
+ }
29
+ }
27
30
  }
28
31
  },
29
32
  },
@@ -25,6 +25,16 @@ export default new Mode(
25
25
  rollSlots: (_, mode) => {
26
26
  mode.variable.randNum = randInt(1, 100);
27
27
  },
28
+ calculateScore: (game, mode) => {
29
+ if (mode.active) return;
30
+ if (
31
+ game.patterns.every((p) => p?.name === "hhh") &&
32
+ mode.variable.randNum > mode.variable.rate
33
+ ) {
34
+ mode.variable.score += Math.round(game.score / 2);
35
+ game.marginScore = mode.variable.score;
36
+ }
37
+ },
28
38
  roundEnd: (game, mode) => {
29
39
  const { patterns } = game;
30
40
  const { variable } = mode;