pokemon-io-core 0.0.82 → 0.0.83
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/core/engine.js +43 -7
- package/package.json +1 -1
package/dist/core/engine.js
CHANGED
|
@@ -209,25 +209,26 @@ export const applyForcedSwitchChoice = (state, targetPlayer, newIndex) => {
|
|
|
209
209
|
if (forced.targetPlayer !== targetPlayer)
|
|
210
210
|
return { state, events: [] };
|
|
211
211
|
const self = targetPlayer === "player1" ? state.player1 : state.player2;
|
|
212
|
-
if (newIndex < 0 || newIndex >= self.fighterTeam.length)
|
|
212
|
+
if (newIndex < 0 || newIndex >= self.fighterTeam.length)
|
|
213
213
|
return { state, events: [] };
|
|
214
|
-
}
|
|
215
214
|
const fromIndex = self.activeIndex;
|
|
216
215
|
if (newIndex === fromIndex)
|
|
217
216
|
return { state, events: [] };
|
|
218
217
|
const toFighter = self.fighterTeam[newIndex];
|
|
219
|
-
if (!toFighter || !toFighter.isAlive || toFighter.currentHp <= 0)
|
|
218
|
+
if (!toFighter || !toFighter.isAlive || toFighter.currentHp <= 0)
|
|
220
219
|
return { state, events: [] };
|
|
221
|
-
}
|
|
222
220
|
const fromFighter = self.fighterTeam[fromIndex];
|
|
223
221
|
const events = [
|
|
224
222
|
{
|
|
225
|
-
...createBaseEvent(state.turnNumber, "fighter_switched", `El entrenador
|
|
223
|
+
...createBaseEvent(state.turnNumber, "fighter_switched", `El entrenador retira a ${fromFighter.fighterId} y manda a ${toFighter.fighterId}`),
|
|
226
224
|
fromFighterId: fromFighter.fighterId,
|
|
227
225
|
toFighterId: toFighter.fighterId,
|
|
228
226
|
},
|
|
227
|
+
{
|
|
228
|
+
...createBaseEvent(state.turnNumber, "turn_end", `Termina el turno ${state.turnNumber}`),
|
|
229
|
+
},
|
|
229
230
|
];
|
|
230
|
-
const
|
|
231
|
+
const switchedState = targetPlayer === "player1"
|
|
231
232
|
? {
|
|
232
233
|
...state,
|
|
233
234
|
forcedSwitch: null,
|
|
@@ -238,6 +239,10 @@ export const applyForcedSwitchChoice = (state, targetPlayer, newIndex) => {
|
|
|
238
239
|
forcedSwitch: null,
|
|
239
240
|
player2: { ...state.player2, activeIndex: newIndex },
|
|
240
241
|
};
|
|
242
|
+
const nextState = {
|
|
243
|
+
...switchedState,
|
|
244
|
+
turnNumber: switchedState.turnNumber + 1,
|
|
245
|
+
};
|
|
241
246
|
return { state: nextState, events };
|
|
242
247
|
};
|
|
243
248
|
let eventCounter = 0;
|
|
@@ -697,7 +702,32 @@ const resolveDamageMove = (state, playerKey, action) => {
|
|
|
697
702
|
// Todos los efectos (daño, aplicar estado, curas, etc.)
|
|
698
703
|
const { actor: finalSelf, target: finalOpp, events: extraEvents, } = applyEffectsOnTarget(state, updatedSelf, updatedOpponent, move.typeId, isCritical, move.effects);
|
|
699
704
|
events.push(...extraEvents);
|
|
700
|
-
|
|
705
|
+
let newState = updateFightersInState(state, playerKey, finalSelf, finalOpp);
|
|
706
|
+
// --- FORCED SWITCH (Roar) ---
|
|
707
|
+
const hasForceSwitch = move.effects.some((e) => e.kind === "force_switch");
|
|
708
|
+
if (hasForceSwitch) {
|
|
709
|
+
const targetPlayer = playerKey === "player1" ? "player2" : "player1";
|
|
710
|
+
const targetSide = targetPlayer === "player1" ? newState.player1 : newState.player2;
|
|
711
|
+
const activeIdx = targetSide.activeIndex;
|
|
712
|
+
const hasBenchAlive = targetSide.fighterTeam.some((f, idx) => {
|
|
713
|
+
if (idx === activeIdx)
|
|
714
|
+
return false;
|
|
715
|
+
return f.isAlive && f.currentHp > 0;
|
|
716
|
+
});
|
|
717
|
+
if (hasBenchAlive) {
|
|
718
|
+
newState = {
|
|
719
|
+
...newState,
|
|
720
|
+
forcedSwitch: {
|
|
721
|
+
targetPlayer,
|
|
722
|
+
reason: "roar",
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
events.push({
|
|
726
|
+
...createBaseEvent(state.turnNumber, "action_declared", `¡El entrenador rival debe cambiar de luchador!`),
|
|
727
|
+
actorId: self.fighterId,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
701
731
|
return { state: newState, events };
|
|
702
732
|
};
|
|
703
733
|
// ------------------------------------------------------
|
|
@@ -970,6 +1000,12 @@ export const resolveTurn = (state, actions) => {
|
|
|
970
1000
|
// switch_fighter u otros no implementados aún
|
|
971
1001
|
continue;
|
|
972
1002
|
}
|
|
1003
|
+
if (currentState.forcedSwitch) {
|
|
1004
|
+
return {
|
|
1005
|
+
newState: currentState,
|
|
1006
|
+
events,
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
973
1009
|
const winnerAfterAction = checkWinner(currentState);
|
|
974
1010
|
if (winnerAfterAction !== "none") {
|
|
975
1011
|
events.push({
|