Implement multi-hit moves
This commit is contained in:
1 parent
3723e25682
commit
7b216ce4c1
5 files changed
+124
-60
No files matched your search
+56
-28
@@ -1,7 +1,7 @@
|
||||
import BattleScene from "./battle-scene";
|
||||
import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove } from "./pokemon";
|
||||
import * as Utils from './utils';
|
||||
import { allMoves, MoveCategory, Moves } from "./move";
|
||||
import { allMoves, applyMoveAttrs, MoveCategory, Moves, MultiHitAttr } from "./move";
|
||||
import { Mode } from './ui/ui';
|
||||
import { Command } from "./ui/command-ui-handler";
|
||||
import { Stat } from "./pokemon-stat";
|
||||
@@ -450,34 +450,10 @@ abstract class MovePhase extends BattlePhase {
|
||||
console.log(this.pokemon.moveset);
|
||||
this.scene.ui.showText(`${this.pokemon.name} used\n${this.move.getName()}!`, null, () => {
|
||||
this.move.ppUsed++;
|
||||
|
||||
if (this.move.getMove().category !== MoveCategory.STATUS) {
|
||||
if (this.hitCheck())
|
||||
this.scene.unshiftPhase(this.getEffectPhase());
|
||||
else
|
||||
this.scene.unshiftPhase(new MessagePhase(this.scene, `${this.pokemon instanceof EnemyPokemon ? 'Foe ' : ''}${this.pokemon.name}'s\nattack missed!`));
|
||||
} else
|
||||
this.scene.unshiftPhase(this.getEffectPhase());
|
||||
this.scene.unshiftPhase(this.getEffectPhase());
|
||||
this.end();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
hitCheck(): boolean {
|
||||
if (this.move.getMove().category !== MoveCategory.STATUS) {
|
||||
const userAccuracyLevel = 0;
|
||||
const targetEvasionLevel = 0;
|
||||
const rand = Utils.randInt(100, 1);
|
||||
let accuracyMultiplier = 1;
|
||||
if (userAccuracyLevel !== targetEvasionLevel) {
|
||||
accuracyMultiplier = userAccuracyLevel > targetEvasionLevel
|
||||
? (3 + Math.min(userAccuracyLevel - targetEvasionLevel, 6)) / 3
|
||||
: 3 / (3 + Math.min(targetEvasionLevel - userAccuracyLevel, 6));
|
||||
}
|
||||
return rand <= this.move.getMove().accuracy * accuracyMultiplier;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class PlayerMovePhase extends MovePhase {
|
||||
@@ -515,8 +491,24 @@ abstract class MoveEffectPhase extends PokemonPhase {
|
||||
const user = this.getUserPokemon();
|
||||
const target = this.getTargetPokemon();
|
||||
|
||||
new MoveAnim(this.move.getMove().id as Moves, user, target).play(this.scene, () =>{
|
||||
this.getTargetPokemon().apply(this.getUserPokemon(), this.move, () => this.end());
|
||||
if (user.turnData.hitsLeft === undefined) {
|
||||
const hitCount = new Utils.IntegerHolder(1);
|
||||
applyMoveAttrs(MultiHitAttr, this.scene, user, target, this.move.getMove(), hitCount);
|
||||
user.turnData.hitCount = 0;
|
||||
user.turnData.hitsLeft = hitCount.value;
|
||||
}
|
||||
|
||||
if (!this.hitCheck()) {
|
||||
this.scene.unshiftPhase(new MessagePhase(this.scene, `${!this.player ? 'Foe ' : ''}${user.name}'s\nattack missed!`));
|
||||
this.end();
|
||||
return;
|
||||
}
|
||||
|
||||
new MoveAnim(this.move.getMove().id as Moves, user, target).play(this.scene, () => {
|
||||
this.getTargetPokemon().apply(this.getUserPokemon(), this.move, () => {
|
||||
++user.turnData.hitCount;
|
||||
this.end();
|
||||
});
|
||||
if (this.getUserPokemon().hp <= 0) {
|
||||
this.scene.pushPhase(new FaintPhase(this.scene, this.player));
|
||||
this.getTargetPokemon().resetBattleSummonData();
|
||||
@@ -528,9 +520,37 @@ abstract class MoveEffectPhase extends PokemonPhase {
|
||||
});
|
||||
}
|
||||
|
||||
end() {
|
||||
const user = this.getUserPokemon();
|
||||
if (--user.turnData.hitsLeft && this.getTargetPokemon().hp)
|
||||
this.scene.unshiftPhase(this.getNewHitPhase());
|
||||
else if (user.turnData.hitCount > 1)
|
||||
this.scene.unshiftPhase(new MessagePhase(this.scene, `Hit ${user.turnData.hitCount} time(s)!`));
|
||||
|
||||
super.end();
|
||||
}
|
||||
|
||||
hitCheck(): boolean {
|
||||
if (this.move.getMove().category !== MoveCategory.STATUS) {
|
||||
const userAccuracyLevel = 0;
|
||||
const targetEvasionLevel = 0;
|
||||
const rand = Utils.randInt(100, 1);
|
||||
let accuracyMultiplier = 1;
|
||||
if (userAccuracyLevel !== targetEvasionLevel) {
|
||||
accuracyMultiplier = userAccuracyLevel > targetEvasionLevel
|
||||
? (3 + Math.min(userAccuracyLevel - targetEvasionLevel, 6)) / 3
|
||||
: 3 / (3 + Math.min(targetEvasionLevel - userAccuracyLevel, 6));
|
||||
}
|
||||
return rand <= this.move.getMove().accuracy * accuracyMultiplier;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract getUserPokemon(): Pokemon;
|
||||
|
||||
abstract getTargetPokemon(): Pokemon;
|
||||
|
||||
abstract getNewHitPhase(): MoveEffectPhase;
|
||||
}
|
||||
|
||||
export class PlayerMoveEffectPhase extends MoveEffectPhase {
|
||||
@@ -547,6 +567,10 @@ export class PlayerMoveEffectPhase extends MoveEffectPhase {
|
||||
return this.getUserPokemon();*/
|
||||
return this.scene.getEnemyPokemon();
|
||||
}
|
||||
|
||||
getNewHitPhase() {
|
||||
return new PlayerMoveEffectPhase(this.scene, this.move);
|
||||
}
|
||||
}
|
||||
|
||||
export class EnemyMoveEffectPhase extends MoveEffectPhase {
|
||||
@@ -563,6 +587,10 @@ export class EnemyMoveEffectPhase extends MoveEffectPhase {
|
||||
return this.getUserPokemon();*/
|
||||
return this.scene.getPlayerPokemon();
|
||||
}
|
||||
|
||||
getNewHitPhase() {
|
||||
return new EnemyMoveEffectPhase(this.scene, this.move);
|
||||
}
|
||||
}
|
||||
|
||||
export class ObtainStatusEffectPhase extends PokemonPhase {
|
||||
|
||||
Reference in new issue
Block a user