pokemon-io-core 0.0.6 → 0.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.
|
@@ -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
|
}
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -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) =>
|
|
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():
|
|
10
|
-
getAmulets():
|
|
11
|
-
getStatuses():
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
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
|
-
|
|
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
|
|
62
|
+
return POKEMON_ITEMS;
|
|
33
63
|
}
|
|
34
64
|
getAmulets() {
|
|
35
|
-
return
|
|
65
|
+
return POKEMON_AMULETS;
|
|
36
66
|
}
|
|
37
67
|
getStatuses() {
|
|
38
|
-
return
|
|
68
|
+
return POKEMON_STATUSES;
|
|
39
69
|
}
|
|
40
70
|
buildPlayerConfig(loadout) {
|
|
41
71
|
if (!loadout.fighterId) {
|
|
42
|
-
throw new Error("
|
|
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
|
|
52
|
-
items: [], //
|
|
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,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pokemon-io-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
7
6
|
"private": false,
|
|
8
7
|
"publishConfig": {
|
|
9
8
|
"access": "public"
|
|
@@ -14,22 +13,27 @@
|
|
|
14
13
|
"types": "./dist/index.d.ts",
|
|
15
14
|
"exports": {
|
|
16
15
|
".": {
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
17
|
"import": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
},
|
|
20
20
|
"./core": {
|
|
21
|
+
"require": "./dist/core/index.js",
|
|
21
22
|
"import": "./dist/core/index.js",
|
|
22
23
|
"types": "./dist/core/index.d.ts"
|
|
23
24
|
},
|
|
24
25
|
"./skins": {
|
|
26
|
+
"require": "./dist/skins/index.js",
|
|
25
27
|
"import": "./dist/skins/index.js",
|
|
26
28
|
"types": "./dist/skins/index.d.ts"
|
|
27
29
|
},
|
|
28
30
|
"./api": {
|
|
31
|
+
"require": "./dist/api/index.js",
|
|
29
32
|
"import": "./dist/api/index.js",
|
|
30
33
|
"types": "./dist/api/index.d.ts"
|
|
31
34
|
},
|
|
32
35
|
"./engine": {
|
|
36
|
+
"require": "./dist/engine/index.js",
|
|
33
37
|
"import": "./dist/engine/index.js",
|
|
34
38
|
"types": "./dist/engine/index.d.ts"
|
|
35
39
|
}
|
|
@@ -64,4 +68,4 @@
|
|
|
64
68
|
"devDependencies": {
|
|
65
69
|
"typescript": "^5.8.3"
|
|
66
70
|
}
|
|
67
|
-
}
|
|
71
|
+
}
|