pokemon-io-core 0.0.6 → 0.0.7

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.
@@ -1,3 +1,4 @@
1
+ import { BattleRuntime } from "./engine";
1
2
  import type { FighterId, TypeId, MoveId, ItemId, AmuletId, StatusId } from "./ids";
2
3
  import type { FighterStats } from "./types";
3
4
  export interface EquippedMove {
@@ -34,4 +35,5 @@ export interface BattleState {
34
35
  turnNumber: number;
35
36
  player1: PlayerBattleState;
36
37
  player2: PlayerBattleState;
38
+ runtime: BattleRuntime;
37
39
  }
@@ -7,7 +7,7 @@ interface BattleRules {
7
7
  randomMinDamageFactor: number;
8
8
  randomMaxDamageFactor: number;
9
9
  }
10
- interface BattleRuntime {
10
+ export interface BattleRuntime {
11
11
  rules: BattleRules;
12
12
  typesById: Record<TypeId, TypeDefinition>;
13
13
  movesById: Record<MoveId, MoveDefinition>;
@@ -37,7 +37,7 @@ export interface BattleConfig {
37
37
  export interface RuntimeBattleState extends BattleState {
38
38
  runtime: BattleRuntime;
39
39
  }
40
- export declare const createInitialBattleState: (config: BattleConfig) => RuntimeBattleState;
40
+ export declare const createInitialBattleState: (config: BattleConfig) => BattleState;
41
41
  export declare const resolveTurn: (state: BattleState, actions: BattleActions) => {
42
42
  newState: BattleState;
43
43
  events: BattleEvent[];
@@ -1,13 +1,14 @@
1
1
  import type { CombatSkin, FighterLoadout } from "../CombatSkin";
2
- import type { MoveDefinition } from "../../core";
3
- import { PlayerBattleConfig } from "../../core/engine";
2
+ import type { MoveDefinition, ItemDefinition, AmuletDefinition, StatusDefinition } from "../../core";
3
+ import type { PlayerBattleConfig } from "../../core/engine";
4
4
  export declare class PokemonSkin implements CombatSkin {
5
5
  readonly id = "pokemon";
6
6
  getTypes(): import("../..").TypeDefinition[];
7
7
  getTypeEffectiveness(): import("../..").TypeEffectivenessMatrix;
8
8
  getMoves(): MoveDefinition[];
9
- getItems(): never[];
10
- getAmulets(): never[];
11
- getStatuses(): never[];
9
+ getItems(): ItemDefinition[];
10
+ getAmulets(): AmuletDefinition[];
11
+ getStatuses(): StatusDefinition[];
12
12
  buildPlayerConfig(loadout: FighterLoadout): PlayerBattleConfig;
13
13
  }
14
+ export declare const createPokemonSkin: () => CombatSkin;
@@ -1,22 +1,52 @@
1
+ // src/skins/pokemon/pokemonSkin.ts
1
2
  import { POKEMON_TYPES, POKEMON_TYPE_MATRIX, POKEMON_MOVES, POKEMON_FIGHTERS } from "./index";
2
3
  const MAX_HP_DEFAULT = 100;
4
+ // Helpers locales
3
5
  const findPokemonById = (id) => {
4
6
  const lower = id.toLowerCase();
5
7
  return (POKEMON_FIGHTERS.find((f) => f.id.toLowerCase() === lower || f.name.toLowerCase() === lower) ?? null);
6
8
  };
7
- const findMovesForFighter = (fighter) => {
8
- const moveIds = fighter.recommendedMoves ?? [];
9
- const moves = POKEMON_MOVES.filter((m) => moveIds.includes(m.id));
10
- if (moves.length >= 4) {
11
- return moves.slice(0, 4);
12
- }
13
- const result = [...moves];
14
- const filler = POKEMON_MOVES.find((m) => m.id === "tackle");
9
+ const findMoveById = (id) => {
10
+ return POKEMON_MOVES.find((m) => m.id === id) ?? null;
11
+ };
12
+ const FILLER_MOVE_ID = "tackle";
13
+ const buildMovesFromLoadout = (fighter, loadout) => {
14
+ // 1) si el jugador ha elegido moveIds, intentamos respetarlos
15
+ const selectedMoveIds = loadout.moveIds ?? [];
16
+ const selectedMoves = selectedMoveIds
17
+ .map((id) => findMoveById(id))
18
+ .filter((m) => m !== null);
19
+ // 2) si ya hay 4 válidos → nos quedamos con los primeros 4
20
+ if (selectedMoves.length >= 4) {
21
+ return selectedMoves.slice(0, 4);
22
+ }
23
+ const result = [...selectedMoves];
24
+ // 3) completamos con recommendedMoves del fighter
25
+ const recommendedIds = fighter.recommendedMoves ?? [];
26
+ for (const recId of recommendedIds) {
27
+ if (result.length >= 4)
28
+ break;
29
+ const move = findMoveById(recId);
30
+ if (move && !result.some((m) => m.id === move.id)) {
31
+ result.push(move);
32
+ }
33
+ }
34
+ // 4) si sigue faltando, rellenamos con "tackle"
35
+ const filler = findMoveById(FILLER_MOVE_ID);
15
36
  while (result.length < 4 && filler) {
16
37
  result.push(filler);
17
38
  }
18
- return result;
39
+ // Garantizamos que haya al menos 1 movimiento
40
+ if (result.length === 0 && filler) {
41
+ result.push(filler);
42
+ }
43
+ // Cortamos por si acaso
44
+ return result.slice(0, 4);
19
45
  };
46
+ // De momento no tenemos objetos / amuletos / estados modelados para Pokémon
47
+ const POKEMON_ITEMS = [];
48
+ const POKEMON_AMULETS = [];
49
+ const POKEMON_STATUSES = [];
20
50
  export class PokemonSkin {
21
51
  id = "pokemon";
22
52
  getTypes() {
@@ -29,28 +59,34 @@ export class PokemonSkin {
29
59
  return POKEMON_MOVES;
30
60
  }
31
61
  getItems() {
32
- return []; // más adelante
62
+ return POKEMON_ITEMS;
33
63
  }
34
64
  getAmulets() {
35
- return []; // más adelante
65
+ return POKEMON_AMULETS;
36
66
  }
37
67
  getStatuses() {
38
- return []; // más adelante
68
+ return POKEMON_STATUSES;
39
69
  }
40
70
  buildPlayerConfig(loadout) {
41
71
  if (!loadout.fighterId) {
42
- throw new Error("FighterId is required in FighterLoadout");
72
+ throw new Error("fighterId is required in FighterLoadout");
43
73
  }
44
74
  const fighter = findPokemonById(loadout.fighterId);
45
75
  if (!fighter) {
46
76
  throw new Error(`Unknown fighterId for Pokemon skin: ${loadout.fighterId}`);
47
77
  }
78
+ const moves = buildMovesFromLoadout(fighter, loadout);
79
+ // Importante: aquí aún no aplicamos items/amuletos, pero dejamos el contrato listo
48
80
  return {
49
81
  fighter,
50
82
  maxHp: MAX_HP_DEFAULT,
51
- moves: findMovesForFighter(fighter),
52
- items: [], // luego mapearemos loadout.itemIds
53
- amulet: null // loadout.amuletId
83
+ moves,
84
+ items: [], // Más adelante: mapear loadout.itemIds -> ItemDefinition[]
85
+ amulet: null // Más adelante: loadout.amuletId -> AmuletDefinition
54
86
  };
55
87
  }
56
88
  }
89
+ // Helper para crear la skin (así importas siempre una factoría)
90
+ export const createPokemonSkin = () => {
91
+ return new PokemonSkin();
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pokemon-io-core",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",