pokemon-io-core 0.0.74 → 0.0.75
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/api/battle.d.ts +1 -0
- package/dist/core/engine.js +54 -37
- package/package.json +1 -1
package/dist/api/battle.d.ts
CHANGED
package/dist/core/engine.js
CHANGED
|
@@ -488,34 +488,6 @@ const applyEffectsOnTarget = (state, actor, target, moveTypeId, isCritical, effe
|
|
|
488
488
|
}
|
|
489
489
|
return { actor: currentActor, target: currentTarget, events };
|
|
490
490
|
};
|
|
491
|
-
const resolveSwitchFighter = (state, playerKey, action) => {
|
|
492
|
-
if (action.kind !== "switch_fighter") {
|
|
493
|
-
return { state, events: [] };
|
|
494
|
-
}
|
|
495
|
-
const events = [];
|
|
496
|
-
const player = playerKey === "player1" ? state.player1 : state.player2;
|
|
497
|
-
const from = getActiveFighter(player);
|
|
498
|
-
const to = player.fighterTeam[action.newIndex];
|
|
499
|
-
if (!to)
|
|
500
|
-
return { state, events };
|
|
501
|
-
if (!to.isAlive || to.currentHp <= 0)
|
|
502
|
-
return { state, events };
|
|
503
|
-
if (action.newIndex === player.activeIndex)
|
|
504
|
-
return { state, events };
|
|
505
|
-
const updatedPlayer = {
|
|
506
|
-
...player,
|
|
507
|
-
activeIndex: action.newIndex,
|
|
508
|
-
};
|
|
509
|
-
const newState = playerKey === "player1"
|
|
510
|
-
? { ...state, player1: updatedPlayer }
|
|
511
|
-
: { ...state, player2: updatedPlayer };
|
|
512
|
-
events.push({
|
|
513
|
-
...createBaseEvent(state.turnNumber, "fighter_switched", `${from.fighterId} cambia a ${to.fighterId}`),
|
|
514
|
-
fromFighterId: from.fighterId,
|
|
515
|
-
toFighterId: to.fighterId,
|
|
516
|
-
});
|
|
517
|
-
return { state: newState, events };
|
|
518
|
-
};
|
|
519
491
|
const getMovePriorityAndSpeed = (state, playerKey, action) => {
|
|
520
492
|
const { self } = getOpponentAndSelf(state, playerKey);
|
|
521
493
|
if (action.kind === "no_action") {
|
|
@@ -545,6 +517,53 @@ const getMovePriorityAndSpeed = (state, playerKey, action) => {
|
|
|
545
517
|
speed: self.effectiveStats.speed,
|
|
546
518
|
};
|
|
547
519
|
};
|
|
520
|
+
const resolveSwitchFighter = (state, playerKey, action) => {
|
|
521
|
+
if (action.kind !== "switch_fighter")
|
|
522
|
+
return { state, events: [] };
|
|
523
|
+
const events = [];
|
|
524
|
+
const selfPlayer = playerKey === "player1" ? state.player1 : state.player2;
|
|
525
|
+
const fromIndex = selfPlayer.activeIndex;
|
|
526
|
+
const toIndex = action.newIndex;
|
|
527
|
+
// validaciones
|
|
528
|
+
if (toIndex < 0 || toIndex >= selfPlayer.fighterTeam.length) {
|
|
529
|
+
return { state, events };
|
|
530
|
+
}
|
|
531
|
+
if (toIndex === fromIndex) {
|
|
532
|
+
return { state, events };
|
|
533
|
+
}
|
|
534
|
+
const target = selfPlayer.fighterTeam[toIndex];
|
|
535
|
+
if (!target || !target.isAlive || target.currentHp <= 0) {
|
|
536
|
+
return { state, events };
|
|
537
|
+
}
|
|
538
|
+
const fromFighter = selfPlayer.fighterTeam[fromIndex];
|
|
539
|
+
events.push({
|
|
540
|
+
...createBaseEvent(state.turnNumber, "action_declared", `${fromFighter.fighterId} cambia a ${target.fighterId}`),
|
|
541
|
+
actorId: fromFighter.fighterId,
|
|
542
|
+
});
|
|
543
|
+
// actualizar activeIndex
|
|
544
|
+
if (playerKey === "player1") {
|
|
545
|
+
return {
|
|
546
|
+
state: {
|
|
547
|
+
...state,
|
|
548
|
+
player1: {
|
|
549
|
+
...state.player1,
|
|
550
|
+
activeIndex: toIndex,
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
events,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
state: {
|
|
558
|
+
...state,
|
|
559
|
+
player2: {
|
|
560
|
+
...state.player2,
|
|
561
|
+
activeIndex: toIndex,
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
events,
|
|
565
|
+
};
|
|
566
|
+
};
|
|
548
567
|
// ------------------------------------------------------
|
|
549
568
|
// use_move
|
|
550
569
|
// ------------------------------------------------------
|
|
@@ -732,10 +751,8 @@ const hasHardCc = (state, fighter) => fighter.statuses.some((st) => {
|
|
|
732
751
|
return def?.kind === "hard_cc";
|
|
733
752
|
});
|
|
734
753
|
const checkWinner = (state) => {
|
|
735
|
-
const
|
|
736
|
-
const
|
|
737
|
-
const p1Alive = f1.isAlive && f1.currentHp > 0;
|
|
738
|
-
const p2Alive = f2.isAlive && f2.currentHp > 0;
|
|
754
|
+
const p1Alive = state.player1.fighterTeam.some((f) => f.isAlive && f.currentHp > 0);
|
|
755
|
+
const p2Alive = state.player2.fighterTeam.some((f) => f.isAlive && f.currentHp > 0);
|
|
739
756
|
if (p1Alive && !p2Alive)
|
|
740
757
|
return "player1";
|
|
741
758
|
if (!p1Alive && p2Alive)
|
|
@@ -888,6 +905,11 @@ export const resolveTurn = (state, actions) => {
|
|
|
888
905
|
});
|
|
889
906
|
continue;
|
|
890
907
|
}
|
|
908
|
+
if (action.kind === "switch_fighter") {
|
|
909
|
+
const result = resolveSwitchFighter(currentState, playerKey, action);
|
|
910
|
+
currentState = result.state;
|
|
911
|
+
events.push(...result.events);
|
|
912
|
+
}
|
|
891
913
|
if (action.kind === "use_move") {
|
|
892
914
|
const result = resolveDamageMove(currentState, playerKey, action);
|
|
893
915
|
currentState = result.state;
|
|
@@ -898,11 +920,6 @@ export const resolveTurn = (state, actions) => {
|
|
|
898
920
|
currentState = result.state;
|
|
899
921
|
events.push(...result.events);
|
|
900
922
|
}
|
|
901
|
-
if (action.kind === "switch_fighter") {
|
|
902
|
-
const result = resolveSwitchFighter(currentState, playerKey, action);
|
|
903
|
-
currentState = result.state;
|
|
904
|
-
events.push(...result.events);
|
|
905
|
-
}
|
|
906
923
|
else {
|
|
907
924
|
// switch_fighter u otros no implementados aún
|
|
908
925
|
continue;
|