More fixes for double battles

This commit is contained in:
Flashfyre 2023-05-12 11:08:33 -04:00
parent 51f51acc08
commit a33a49cbda
6 changed files with 71 additions and 27 deletions

View File

@ -1,5 +1,5 @@
import BattleScene, { maxExpLevel, startingLevel, startingWave } from "./battle-scene"; import BattleScene, { maxExpLevel, startingLevel, startingWave } from "./battle-scene";
import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult } from "./pokemon"; import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult, FieldPosition } from "./pokemon";
import * as Utils from './utils'; import * as Utils from './utils';
import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMoveAttrs, HitsTagAttr, MissEffectAttr, MoveAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr, MoveTarget, OneHitKOAttr } from "./data/move"; import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMoveAttrs, HitsTagAttr, MissEffectAttr, MoveAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr, MoveTarget, OneHitKOAttr } from "./data/move";
import { Mode } from './ui/ui'; import { Mode } from './ui/ui';
@ -213,11 +213,8 @@ export class EncounterPhase extends BattlePhase {
if (this.scene.getPlayerPokemon().visible) if (this.scene.getPlayerPokemon().visible)
this.scene.field.moveBelow(enemyPokemon, this.scene.getPlayerPokemon()); this.scene.field.moveBelow(enemyPokemon, this.scene.getPlayerPokemon());
enemyPokemon.tint(0, 0.5); enemyPokemon.tint(0, 0.5);
if (battle.enemyField.length > 1) { if (battle.enemyField.length > 1)
enemyPokemon.x += 32 * (e ? 1 : -1); enemyPokemon.setFieldPosition(e ? FieldPosition.RIGHT : FieldPosition.LEFT);
if (!e)
enemyPokemon.y += 8 * (e ? 1 : -1);
}
}); });
if (!this.loaded) { if (!this.loaded) {
@ -469,14 +466,10 @@ export class SummonPhase extends PartyMemberPokemonPhase {
const playerPokemon = this.getPokemon(); const playerPokemon = this.getPokemon();
if (this.fieldIndex === 1) { if (this.fieldIndex === 1) {
this.scene.tweens.add({ this.scene.getPlayerField()[0].setFieldPosition(FieldPosition.LEFT, 250);
targets: this.scene.getPlayerField(), playerPokemon.setFieldPosition(FieldPosition.RIGHT, 0);
ease: 'Sine.easeOut', } else
duration: 250, playerPokemon.setFieldPosition(!this.scene.currentBattle.double ? FieldPosition.CENTER : FieldPosition.LEFT);
x: (_target, _key, value: number, fieldIndex: integer) => value + 32 * (fieldIndex ? 1 : -1),
y: (_target, _key, value: number, fieldIndex: integer) => value + 8 * (fieldIndex ? 1 : -1)
});
}
pokeball.setVisible(true); pokeball.setVisible(true);
this.scene.tweens.add({ this.scene.tweens.add({
@ -744,7 +737,7 @@ export class CommandPhase extends FieldPhase {
if (cursor === -1 || playerPokemon.trySelectMove(cursor, args[0] as boolean)) { if (cursor === -1 || playerPokemon.trySelectMove(cursor, args[0] as boolean)) {
this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.FIGHT, cursor: cursor, this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.FIGHT, cursor: cursor,
move: cursor > -1 ? { move: playerPokemon.moveset[cursor].moveId } : null, args: args }; // TODO: Struggle logic move: cursor > -1 ? { move: playerPokemon.moveset[cursor].moveId } : null, targetIndex: targetIndex, args: args }; // TODO: Struggle logic
success = true; success = true;
} else if (cursor < playerPokemon.getMoveset().length) { } else if (cursor < playerPokemon.getMoveset().length) {
const move = playerPokemon.getMoveset()[cursor]; const move = playerPokemon.getMoveset()[cursor];
@ -872,8 +865,6 @@ export class TurnStartPhase extends FieldPhase {
const pokemon = field[o]; const pokemon = field[o];
const turnCommand = this.scene.currentBattle.turnCommands[o]; const turnCommand = this.scene.currentBattle.turnCommands[o];
console.log(pokemon, field, o);
switch (turnCommand.command) { switch (turnCommand.command) {
case Command.FIGHT: case Command.FIGHT:
const queuedMove = turnCommand.move; const queuedMove = turnCommand.move;

View File

@ -654,7 +654,7 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr {
if (pokemon.getHpRatio() < 1) { if (pokemon.getHpRatio() < 1) {
const scene = pokemon.scene; const scene = pokemon.scene;
scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby its ${pokemon.getAbility()}!`)); scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby its ${pokemon.getAbility()}!`));
scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), MoveResult.OTHER)); scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), pokemon.getFieldIndex(), MoveResult.OTHER));
pokemon.damage(Math.ceil(pokemon.getMaxHp() * (16 / this.damageFactor))); pokemon.damage(Math.ceil(pokemon.getMaxHp() * (16 / this.damageFactor)));
return true; return true;
} }

View File

@ -151,7 +151,7 @@ class SpikesTag extends ArenaTrapTag {
const damageHpRatio = 1 / (10 - 2 * this.layers); const damageHpRatio = 1 / (10 - 2 * this.layers);
pokemon.scene.queueMessage(getPokemonMessage(pokemon, ' is hurt\nby the spikes!')); pokemon.scene.queueMessage(getPokemonMessage(pokemon, ' is hurt\nby the spikes!'));
pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), MoveResult.OTHER)); pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), pokemon.getFieldIndex(), MoveResult.OTHER));
pokemon.damage(Math.ceil(pokemon.getMaxHp() * damageHpRatio)); pokemon.damage(Math.ceil(pokemon.getMaxHp() * damageHpRatio));
return true; return true;
} }
@ -225,7 +225,7 @@ class StealthRockTag extends ArenaTrapTag {
if (damageHpRatio) { if (damageHpRatio) {
pokemon.scene.queueMessage(`Pointed stones dug into\n${pokemon.name}!`); pokemon.scene.queueMessage(`Pointed stones dug into\n${pokemon.name}!`);
pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), MoveResult.OTHER)); pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.isPlayer(), pokemon.getFieldIndex(), MoveResult.OTHER));
pokemon.damage(Math.ceil(pokemon.getMaxHp() * damageHpRatio)); pokemon.damage(Math.ceil(pokemon.getMaxHp() * damageHpRatio));
} }

View File

@ -889,7 +889,7 @@ export class RecoilAttr extends MoveEffectAttr {
return false; return false;
const recoilDamage = Math.max(Math.floor((!this.useHp ? user.turnData.damageDealt : user.getMaxHp()) / 4), 1); const recoilDamage = Math.max(Math.floor((!this.useHp ? user.turnData.damageDealt : user.getMaxHp()) / 4), 1);
user.scene.unshiftPhase(new DamagePhase(user.scene, user.isPlayer(), MoveResult.OTHER)); user.scene.unshiftPhase(new DamagePhase(user.scene, user.isPlayer(), user.getFieldIndex(), MoveResult.OTHER));
user.scene.queueMessage(getPokemonMessage(user, ' is hit\nwith recoil!')); user.scene.queueMessage(getPokemonMessage(user, ' is hit\nwith recoil!'));
user.damage(recoilDamage); user.damage(recoilDamage);
@ -906,7 +906,7 @@ export class SacrificialAttr extends MoveEffectAttr {
if (!super.apply(user, target, move, args)) if (!super.apply(user, target, move, args))
return false; return false;
user.scene.unshiftPhase(new DamagePhase(user.scene, user.isPlayer(), MoveResult.OTHER)); user.scene.unshiftPhase(new DamagePhase(user.scene, user.isPlayer(), user.getFieldIndex(), MoveResult.OTHER));
user.damage(user.getMaxHp()); user.damage(user.getMaxHp());
return true; return true;

View File

@ -26,6 +26,12 @@ import { Biome } from './data/biome';
import { Abilities, Ability, BattleStatMultiplierAbAttr, BlockCritAbAttr, PreApplyBattlerTagAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, abilities, applyBattleStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs } from './data/ability'; import { Abilities, Ability, BattleStatMultiplierAbAttr, BlockCritAbAttr, PreApplyBattlerTagAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, abilities, applyBattleStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs } from './data/ability';
import PokemonData from './system/pokemon-data'; import PokemonData from './system/pokemon-data';
export enum FieldPosition {
CENTER,
LEFT,
RIGHT
}
export default abstract class Pokemon extends Phaser.GameObjects.Container { export default abstract class Pokemon extends Phaser.GameObjects.Container {
public id: integer; public id: integer;
public name: string; public name: string;
@ -50,6 +56,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
public battleSummonData: PokemonBattleSummonData; public battleSummonData: PokemonBattleSummonData;
public turnData: PokemonTurnData; public turnData: PokemonTurnData;
public fieldPosition: FieldPosition;
public maskEnabled: boolean; public maskEnabled: boolean;
public maskSprite: Phaser.GameObjects.Sprite; public maskSprite: Phaser.GameObjects.Sprite;
@ -139,6 +147,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.calculateStats(); this.calculateStats();
this.fieldPosition = FieldPosition.CENTER;
scene.fieldUI.addAt(this.battleInfo, 0); scene.fieldUI.addAt(this.battleInfo, 0);
this.battleInfo.initInfo(this); this.battleInfo.initInfo(this);
@ -268,6 +278,49 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.getTintSprite().play(this.getBattleSpriteKey()); this.getTintSprite().play(this.getBattleSpriteKey());
} }
getFieldPositionOffset(): [ number, number ] {
switch (this.fieldPosition) {
case FieldPosition.CENTER:
return [ 0, 0 ];
case FieldPosition.LEFT:
return [ -32, -8 ];
case FieldPosition.RIGHT:
return [ 32, 0 ];
}
}
setFieldPosition(fieldPosition: FieldPosition, duration?: integer): Promise<void> {
return new Promise(resolve => {
if (fieldPosition === this.fieldPosition) {
resolve();
return;
}
const initialOffset = this.getFieldPositionOffset();
this.fieldPosition = fieldPosition;
const newOffset = this.getFieldPositionOffset();
let relX = newOffset[0] - initialOffset[0];
let relY = newOffset[1] - initialOffset[1];
if (duration) {
this.scene.tweens.add({
targets: this,
x: (_target, _key, value: number) => value + relX,
y: (_target, _key, value: number) => value + relY,
duration: duration,
ease: 'Sine.easeOut',
onComplete: () => resolve()
});
} else {
this.x += relX;
this.y += relY;
}
});
}
getBattleStat(stat: Stat): integer { getBattleStat(stat: Stat): integer {
if (stat === Stat.HP) if (stat === Stat.HP)
return this.stats[Stat.HP]; return this.stats[Stat.HP];
@ -597,7 +650,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
} }
if (damage) { if (damage) {
this.scene.unshiftPhase(new DamagePhase(this.scene, this.isPlayer(), result as DamageResult)); this.scene.unshiftPhase(new DamagePhase(this.scene, this.isPlayer(), this.getFieldIndex(), result as DamageResult));
if (isCritical) if (isCritical)
this.scene.queueMessage('A critical hit!'); this.scene.queueMessage('A critical hit!');
this.damage(damage); this.damage(damage);

View File

@ -127,8 +127,8 @@ export class GameData {
const sessionData = { const sessionData = {
party: scene.getParty().map(p => new PokemonData(p)), party: scene.getParty().map(p => new PokemonData(p)),
enemyField: scene.getEnemyField().map(p => new PokemonData(p)), enemyField: scene.getEnemyField().map(p => new PokemonData(p)),
modifiers: scene.findModifiers(m => true).map(m => new PersistentModifierData(m, true)), modifiers: scene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)),
enemyModifiers: scene.findModifiers(m => true, false).map(m => new PersistentModifierData(m, false)), enemyModifiers: scene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)),
arena: new ArenaData(scene.arena), arena: new ArenaData(scene.arena),
pokeballCounts: scene.pokeballCounts, pokeballCounts: scene.pokeballCounts,
waveIndex: scene.currentBattle.waveIndex, waveIndex: scene.currentBattle.waveIndex,
@ -153,7 +153,7 @@ export class GameData {
try { try {
const sessionData = JSON.parse(atob(localStorage.getItem('sessionData')), (k: string, v: any) => { const sessionData = JSON.parse(atob(localStorage.getItem('sessionData')), (k: string, v: any) => {
if (k === 'party' || k === 'enemyParty') { if (k === 'party' || k === 'enemyField') {
const ret: PokemonData[] = []; const ret: PokemonData[] = [];
for (let pd of v) for (let pd of v)
ret.push(new PokemonData(pd)); ret.push(new PokemonData(pd));