pokemon-io-core 0.0.90 → 0.0.91

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.
@@ -4,6 +4,16 @@ export interface BattlePlayerStatusView {
4
4
  stacks: 1 | 2;
5
5
  remainingTurns: number;
6
6
  }
7
+ export interface BattleMovePpView {
8
+ moveId: string;
9
+ currentPP: number;
10
+ maxPP: number;
11
+ }
12
+ export interface BattleItemUsesView {
13
+ itemId: string;
14
+ usesRemaining: number;
15
+ maxUses: number;
16
+ }
7
17
  export interface BattlePlayerView {
8
18
  playerId: string;
9
19
  nickname: string;
@@ -11,6 +21,8 @@ export interface BattlePlayerView {
11
21
  statuses: BattlePlayerStatusView[];
12
22
  activeFighterId: string | null;
13
23
  activeIndex: number;
24
+ activeMoves?: BattleMovePpView[];
25
+ inventory?: BattleItemUsesView[];
14
26
  }
15
27
  export type BattleStatus = "ongoing" | "awaiting_forced_switch" | "finished";
16
28
  export type ForcedSwitchReason = "roar" | "faint";
@@ -17,28 +17,20 @@ export const applyForcedSwitchChoice = (state, targetPlayer, newIndex) => {
17
17
  const fromFighter = self.fighterTeam[fromIndex];
18
18
  const events = [
19
19
  {
20
- ...createBaseEvent(state.turnNumber, "fighter_switched", `El entrenador retira a ${fromFighter.fighterId} y manda a ${toFighter.fighterId}`),
20
+ ...createBaseEvent(state.turnNumber, "fighter_switched", `El entrenador cambia a ${toFighter.fighterId}`),
21
21
  fromFighterId: fromFighter.fighterId,
22
22
  toFighterId: toFighter.fighterId,
23
- },
24
- {
25
- ...createBaseEvent(state.turnNumber, "turn_end", `Termina el turno ${state.turnNumber}`),
23
+ // ✅ CLAVE para tu replay:
24
+ toHp: toFighter.currentHp,
25
+ toStatuses: (toFighter.statuses ?? []).map((st) => ({
26
+ statusId: st.statusId,
27
+ stacks: st.stacks,
28
+ remainingTurns: st.remainingTurns,
29
+ })),
26
30
  },
27
31
  ];
28
- const switchedState = targetPlayer === "player1"
29
- ? {
30
- ...state,
31
- forcedSwitch: null,
32
- player1: { ...state.player1, activeIndex: newIndex },
33
- }
34
- : {
35
- ...state,
36
- forcedSwitch: null,
37
- player2: { ...state.player2, activeIndex: newIndex },
38
- };
39
- const nextState = {
40
- ...switchedState,
41
- turnNumber: switchedState.turnNumber + 1,
42
- };
32
+ const nextState = targetPlayer === "player1"
33
+ ? { ...state, forcedSwitch: null, player1: { ...state.player1, activeIndex: newIndex } }
34
+ : { ...state, forcedSwitch: null, player2: { ...state.player2, activeIndex: newIndex } };
43
35
  return { state: nextState, events };
44
36
  };
@@ -1,22 +1,26 @@
1
1
  import { applyDamageToFighter } from "../combat/damage.js";
2
- import { dbg } from "../debug.js";
3
2
  import { createBaseEvent } from "../events.js";
4
3
  import { getActiveFighter } from "../fighters/selectors.js";
4
+ const isFainted = (f) => !f.isAlive || f.currentHp <= 0;
5
5
  export const applyEndOfTurnStatuses = (state) => {
6
6
  const events = [];
7
7
  const applyForPlayer = (player) => {
8
8
  const active = getActiveFighter(player);
9
+ // ✅ Si ya está KO, no hay ticks ni expiraciones
10
+ if (!active || isFainted(active)) {
11
+ return player;
12
+ }
9
13
  let updated = { ...active };
10
14
  const updatedStatuses = [];
11
15
  for (const st of active.statuses) {
16
+ // ✅ Si ha muerto durante ticks previos, paramos y limpiamos
17
+ if (isFainted(updated)) {
18
+ updated = { ...updated, statuses: [] };
19
+ break;
20
+ }
12
21
  const def = state.runtime.statusesById[st.statusId];
13
- if (!def) {
14
- dbg("STATUS_MISSING_DEF", {
15
- fighterId: active.fighterId,
16
- statusId: st.statusId,
17
- });
22
+ if (!def)
18
23
  continue;
19
- }
20
24
  let damageFromStatus = 0;
21
25
  def.effectsPerStack.forEach((eff) => {
22
26
  if (eff.kind === "damage") {
@@ -25,33 +29,25 @@ export const applyEndOfTurnStatuses = (state) => {
25
29
  ? eff.flatAmount
26
30
  : typeof eff.basePower === "number"
27
31
  ? eff.basePower
28
- : 10; // fallback
32
+ : 10;
29
33
  damageFromStatus += base * stacksMultiplier;
30
34
  }
31
35
  });
32
- if (damageFromStatus > 0 && updated.isAlive) {
33
- dbg("STATUS_DOT", {
34
- fighterId: updated.fighterId,
35
- statusId: st.statusId,
36
- damageFromStatus,
37
- stacks: st.stacks,
38
- });
36
+ if (damageFromStatus > 0) {
39
37
  const damageRes = applyDamageToFighter(state, updated, damageFromStatus, updated.fighterId, false);
40
38
  updated = damageRes.updatedDefender;
41
39
  events.push(...damageRes.events);
40
+ // ✅ Si muere por este tick: no expiraciones, no más ticks
41
+ if (isFainted(updated)) {
42
+ updated = { ...updated, statuses: [] };
43
+ break;
44
+ }
42
45
  }
46
+ // solo decrementamos si sigue vivo
43
47
  const remaining = st.remainingTurns - 1;
44
- if (remaining > 0) {
45
- updatedStatuses.push({
46
- ...st,
47
- remainingTurns: remaining,
48
- });
49
- }
48
+ if (remaining > 0)
49
+ updatedStatuses.push({ ...st, remainingTurns: remaining });
50
50
  else {
51
- dbg("STATUS_EXPIRE", {
52
- fighterId: updated.fighterId,
53
- statusId: st.statusId,
54
- });
55
51
  events.push({
56
52
  ...createBaseEvent(state.turnNumber, "status_expired", `El estado ${st.statusId} expira en ${updated.fighterId}`),
57
53
  targetId: updated.fighterId,
@@ -59,22 +55,13 @@ export const applyEndOfTurnStatuses = (state) => {
59
55
  });
60
56
  }
61
57
  }
62
- updated = {
63
- ...updated,
64
- statuses: updatedStatuses,
65
- };
58
+ if (!isFainted(updated)) {
59
+ updated = { ...updated, statuses: updatedStatuses };
60
+ }
66
61
  const newTeam = player.fighterTeam.map((f, idx) => idx === player.activeIndex ? updated : f);
67
- return {
68
- ...player,
69
- fighterTeam: newTeam,
70
- };
62
+ return { ...player, fighterTeam: newTeam };
71
63
  };
72
64
  const p1 = applyForPlayer(state.player1);
73
65
  const p2 = applyForPlayer(state.player2);
74
- const newState = {
75
- ...state,
76
- player1: p1,
77
- player2: p2,
78
- };
79
- return { state: newState, events };
66
+ return { state: { ...state, player1: p1, player2: p2 }, events };
80
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pokemon-io-core",
3
- "version": "0.0.90",
3
+ "version": "0.0.91",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",