Fix some bugs and re-implement unintentionally reverted weather logic

pull/1/head
Flashfyre 2023-04-19 14:07:38 -04:00
parent 64076a842d
commit 5a3f626776
10 changed files with 133 additions and 58 deletions

View File

@ -26,11 +26,12 @@ export class Arena {
}
randomSpecies(waveIndex: integer, level: integer): PokemonSpecies {
const isBoss = waveIndex % 10 === 0 && this.pokemonPool[BiomePoolTier.BOSS].length;
const isBoss = (waveIndex >= 100 || waveIndex % 10 === 0) && !!this.pokemonPool[BiomePoolTier.BOSS].length;
const tierValue = Utils.randInt(!isBoss ? 512 : 64);
let tier = !isBoss
? tierValue >= 156 ? BiomePoolTier.COMMON : tierValue >= 32 ? BiomePoolTier.UNCOMMON : tierValue >= 6 ? BiomePoolTier.RARE : tierValue >= 1 ? BiomePoolTier.SUPER_RARE : BiomePoolTier.ULTRA_RARE
: tierValue >= 20 ? BiomePoolTier.BOSS : tierValue >= 6 ? BiomePoolTier.BOSS_RARE : tierValue >= 1 ? BiomePoolTier.BOSS_SUPER_RARE : BiomePoolTier.BOSS_ULTRA_RARE;
console.log(BiomePoolTier[tier]);
while (!this.pokemonPool[tier].length) {
console.log(`Downgraded rarity tier from ${BiomePoolTier[tier]} to ${BiomePoolTier[tier - 1]}`);
tier--;
@ -38,7 +39,7 @@ export class Arena {
const tierPool = this.pokemonPool[tier];
let ret: PokemonSpecies;
if (!tierPool.length)
ret = this.scene.randomSpecies(level);
ret = this.scene.randomSpecies(waveIndex, level);
else {
const entry = tierPool[Utils.randInt(tierPool.length)];
let species: Species;
@ -101,6 +102,8 @@ export class Arena {
if (this.weather?.weatherType === (weather || undefined))
return false;
console.log('set weather', WeatherType[weather]);
const oldWeatherType = this.weather?.weatherType || WeatherType.NONE;
this.weather = weather ? new Weather(weather, viaMove ? 5 : 0) : null;

View File

@ -189,7 +189,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.lastMaxHp = pokemon.getMaxHp();
};
if (this.player && this.lastExp !== pokemon.exp) {
if (this.player && (this.lastExp !== pokemon.exp || this.lastLevel !== pokemon.level)) {
const originalResolve = resolve;
resolve = () => this.updatePokemonExp(pokemon).then(() => originalResolve());
}
@ -211,7 +211,12 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
const levelUp = this.lastLevel < battler.level;
const relLevelExp = getLevelRelExp(this.lastLevel + 1, battler.species.growthRate);
const levelExp = levelUp ? relLevelExp : battler.levelExp;
let ratio = levelExp / relLevelExp;
let ratio = relLevelExp ? levelExp / relLevelExp : 0;
if (this.lastLevel >= 100) {
if (levelUp)
ratio = 1;
instant = true;
}
let duration = this.visible && !instant ? ((levelExp - this.lastLevelExp) / relLevelExp) * 1650 : 0;
if (duration)
this.scene.sound.play('exp');

View File

@ -1,7 +1,7 @@
import BattleScene from "./battle-scene";
import BattleScene, { startingLevel, startingWave } from "./battle-scene";
import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult } from "./pokemon";
import * as Utils from './utils';
import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, ConditionalMoveAttr, HitsTagAttr, MissEffectAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr } from "./move";
import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, ConditionalMoveAttr, HitsTagAttr, MissEffectAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr } from "./move";
import { Mode } from './ui/ui';
import { Command } from "./ui/command-ui-handler";
import { Stat } from "./pokemon-stat";
@ -22,7 +22,7 @@ import { BattleTagLapseType, BattleTagType, HideSpriteTag as HiddenTag } from ".
import { getPokemonMessage } from "./messages";
import { Starter } from "./ui/starter-select-ui-handler";
import { Gender } from "./gender";
import { getRandomWeatherType } from "./weather";
import { Weather, WeatherType, getRandomWeatherType, getWeatherDamageMessage, getWeatherLapseMessage } from "./weather";
export class SelectStarterPhase extends BattlePhase {
constructor(scene: BattleScene) {
@ -41,7 +41,7 @@ export class SelectStarterPhase extends BattlePhase {
const starterGender = starter.species.malePercent !== null
? !starter.female ? Gender.MALE : Gender.FEMALE
: Gender.GENDERLESS;
const starterPokemon = new PlayerPokemon(this.scene, starter.species, 5, starter.formIndex, starterGender, starter.shiny);
const starterPokemon = new PlayerPokemon(this.scene, starter.species, startingLevel, starter.formIndex, starterGender, starter.shiny);
starterPokemon.setVisible(false);
party.push(starterPokemon);
loadPokemonAssets.push(starterPokemon.loadAssets());
@ -69,7 +69,7 @@ export class EncounterPhase extends BattlePhase {
this.scene.updateWaveText();
const battle = this.scene.currentBattle;
const enemySpecies = this.scene.arena.randomSpecies(1, battle.enemyLevel);
const enemySpecies = this.scene.arena.randomSpecies(battle.waveIndex, battle.enemyLevel);
battle.enemyPokemon = new EnemyPokemon(this.scene, enemySpecies, battle.enemyLevel);
const enemyPokemon = this.scene.getEnemyPokemon();
enemyPokemon.resetSummonData();
@ -89,6 +89,13 @@ export class EncounterPhase extends BattlePhase {
}
doEncounter() {
if (startingWave > 10) {
for (let m = 0; m < Math.floor(startingWave / 10); m++)
this.scene.addModifier(getModifierTypeOptionsForWave((m + 1) * 10, 1, this.scene.getParty())[0].type.newModifier());
}
this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena.biomeType), false);
const enemyPokemon = this.scene.getEnemyPokemon();
this.scene.tweens.add({
targets: [ this.scene.arenaEnemy, enemyPokemon, this.scene.arenaPlayer, this.scene.trainer ],
@ -405,9 +412,13 @@ export class CheckSwitchPhase extends BattlePhase {
this.scene.ui.showText('Will you switch\nPOKéMON?', null, () => {
this.scene.ui.setMode(Mode.CONFIRM, () => {
this.scene.ui.setMode(Mode.MESSAGE);
this.scene.unshiftPhase(new SwitchPhase(this.scene, false, true));
this.end();
}, () => this.end());
}, () => {
this.scene.ui.setMode(Mode.MESSAGE);
this.end();
});
});
}
}
@ -455,10 +466,12 @@ export class CommandPhase extends BattlePhase {
let isDelayed = (command: Command, playerMove: PokemonMove, enemyMove: PokemonMove) => {
switch (command) {
case Command.FIGHT:
if (playerMove && enemyMove) {
const playerMovePriority = playerMove.getMove().priority;
const enemyMovePriority = enemyMove.getMove().priority;
if (playerMovePriority !== enemyMovePriority)
return playerMovePriority < enemyMovePriority;
}
break;
case Command.BALL:
case Command.POKEMON:
@ -498,6 +511,9 @@ export class CommandPhase extends BattlePhase {
}
if (success) {
if (this.scene.arena.weather)
this.scene.unshiftPhase(new WeatherEffectPhase(this.scene, this.scene.arena.weather, isDelayed(command, null, null)));
const enemyMove = enemyPokemon.getNextMove();
const enemyPhase = new EnemyMovePhase(this.scene, enemyPokemon, enemyMove);
if (isDelayed(command, playerMove, enemyMove))
@ -552,6 +568,9 @@ export class TurnEndPhase extends BattlePhase {
enemyPokemon.battleSummonData.turnCount++;
}
if (this.scene.arena.weather && !this.scene.arena.weather.lapse())
this.scene.arena.trySetWeather(WeatherType.NONE, false);
this.end();
}
}
@ -663,6 +682,8 @@ export abstract class MovePhase extends BattlePhase {
const failed = new Utils.BooleanHolder(false);
applyMoveAttrs(ConditionalMoveAttr, this.pokemon, target, this.move.getMove(), failed);
if (!failed.value && this.scene.arena.isMoveWeatherCancelled(this.move.getMove()))
failed.value = true;
if (failed.value) {
this.pokemon.summonData.moveHistory.push({ move: this.move.moveId, result: MoveResult.FAILED });
this.scene.unshiftPhase(new MessagePhase(this.scene, 'But it failed!'));
@ -829,6 +850,12 @@ abstract class MoveEffectPhase extends PokemonPhase {
return false;
}
const moveAccuracy = new Utils.NumberHolder(this.move.getMove().accuracy);
applyMoveAttrs(VariableAccuracyAttr, this.getUserPokemon(), this.getTargetPokemon(), this.move.getMove(), moveAccuracy);
if (moveAccuracy.value === -1)
return true;
if (this.move.getMove().category !== MoveCategory.STATUS) {
const userAccuracyLevel = new Utils.IntegerHolder(this.getUserPokemon().summonData.battleStats[BattleStat.ACC]);
const targetEvasionLevel = new Utils.IntegerHolder(this.getTargetPokemon().summonData.battleStats[BattleStat.EVA]);
@ -1024,6 +1051,42 @@ export class StatChangePhase extends PokemonPhase {
}
}
export class WeatherEffectPhase extends CommonAnimPhase {
private weather: Weather;
private playerDelayed: boolean;
constructor(scene: BattleScene, weather: Weather, playerDelayed: boolean) {
super(scene, true, CommonAnim.SUNNY + (weather.weatherType - 1));
this.weather = weather;
this.playerDelayed = playerDelayed;
}
start() {
if (this.weather.isDamaging()) {
const inflictDamage = (pokemon: Pokemon) => {
this.scene.unshiftPhase(new MessagePhase(this.scene, getWeatherDamageMessage(this.weather.weatherType, pokemon)));
pokemon.damage(Math.ceil(pokemon.getMaxHp() / 16));
this.scene.unshiftPhase(new DamagePhase(this.scene, pokemon.isPlayer()));
};
const playerPokemon = this.scene.getPlayerPokemon();
const enemyPokemon = this.scene.getEnemyPokemon();
const playerImmune = !!playerPokemon.getTypes().filter(t => this.weather.isTypeDamageImmune(t)).length;
const enemyImmune = !!enemyPokemon.getTypes().filter(t => this.weather.isTypeDamageImmune(t)).length;
if (!this.playerDelayed && !playerImmune)
inflictDamage(playerPokemon);
if (!enemyImmune)
inflictDamage(enemyPokemon);
if (this.playerDelayed && !playerImmune)
inflictDamage(playerPokemon);
}
this.scene.ui.showText(getWeatherLapseMessage(this.weather.weatherType), null, () => super.start());
}
}
export class ObtainStatusEffectPhase extends PokemonPhase {
private statusEffect: StatusEffect;
private cureTurn: integer;
@ -1296,6 +1359,7 @@ export class LevelUpPhase extends PartyMemberPokemonPhase {
pokemon.updateInfo();
this.scene.playSoundWithoutBgm('level_up_fanfare', 1500);
this.scene.ui.showText(`${this.getPokemon().name} grew to\nLV. ${this.level}!`, null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false, () => this.end()), null, true);
if (this.level <= 100) {
const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1);
for (let lm of levelMoves)
this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm));
@ -1303,6 +1367,7 @@ export class LevelUpPhase extends PartyMemberPokemonPhase {
if (evolution)
this.scene.unshiftPhase(new EvolutionPhase(this.scene, this.partyMemberIndex, evolution, this.lastLevel));
}
}
}
export class LearnMovePhase extends PartyMemberPokemonPhase {

View File

@ -16,10 +16,12 @@ import { initGameSpeed } from './game-speed';
import { Arena } from './arena';
import { GameData } from './game-data';
import StarterSelectUiHandler from './ui/starter-select-ui-handler';
import { getRandomWeatherType } from './weather';
import { TextStyle, addTextObject } from './text';
const enableAuto = true;
export const startingLevel = 5;
export const startingWave = 1;
export const startingBiome = Biome.PLAINS;
export enum Button {
UP,
@ -301,7 +303,7 @@ export default class BattleScene extends Phaser.Scene {
const biomes = Utils.getEnumValues(Biome);
this.newArena(biomes[Utils.randInt(biomes.length)]);
} else
this.newArena(Biome.PLAINS);
this.newArena(startingBiome);
const biomeKey = this.arena.getBiomeKey();
this.arenaBg = this.add.sprite(0, 0, `${biomeKey}_bg`);
@ -321,8 +323,10 @@ export default class BattleScene extends Phaser.Scene {
if (this.quickStart) {
for (let s = 0; s < 3; s++) {
const playerSpecies = !isRandom ? getPokemonSpecies(s === 0 ? Species.TORCHIC : s === 1 ? Species.TREECKO : Species.MUDKIP) : this.randomSpecies(5);
const playerPokemon = new PlayerPokemon(this, playerSpecies, 5, 0);
const playerSpecies = (!isRandom
? getPokemonSpecies((getPokemonSpecies(s === 0 ? Species.TORCHIC : s === 1 ? Species.TREECKO : Species.MUDKIP)).getSpeciesForLevel(startingLevel, true))
: this.randomSpecies(startingWave, startingLevel));
const playerPokemon = new PlayerPokemon(this, playerSpecies, startingLevel, 0);
playerPokemon.setVisible(false);
loadPokemonAssets.push(playerPokemon.loadAssets());
@ -431,7 +435,7 @@ export default class BattleScene extends Phaser.Scene {
this.pushPhase(new SummonPhase(this));
}
this.currentBattle = new Battle((this.currentBattle?.waveIndex || 0) + 1);
this.currentBattle = new Battle((this.currentBattle?.waveIndex || (startingWave - 1)) + 1);
return this.currentBattle;
}
@ -448,9 +452,9 @@ export default class BattleScene extends Phaser.Scene {
this.waveCountText.setShadowColor(!isBoss ? '#ded6b5' : '#984038');
}
randomSpecies(level: integer, fromArenaPool?: boolean): PokemonSpecies {
randomSpecies(waveIndex: integer, level: integer, fromArenaPool?: boolean): PokemonSpecies {
return fromArenaPool
? this.arena.randomSpecies(1, level)
? this.arena.randomSpecies(waveIndex, level)
: getPokemonSpecies(allSpecies[(Utils.randInt(allSpecies.length)) - 1].getSpeciesForLevel(level));
}
@ -584,12 +588,13 @@ export default class BattleScene extends Phaser.Scene {
addModifier(modifier: Modifier, virtual?: boolean): Promise<void> {
return new Promise(resolve => {
if (modifier instanceof PersistentModifier) {
if ((modifier as PersistentModifier).add(this.modifiers, !!virtual) && !virtual)
if ((modifier as PersistentModifier).add(this.modifiers, !!virtual) && !virtual && !this.sound.get('restore'))
this.sound.play('restore');
if (!virtual)
this.updateModifiers().then(() => resolve());
} else if (modifier instanceof ConsumableModifier) {
if (!this.sound.get('restore'))
this.sound.play('restore');
if (modifier instanceof ConsumablePokemonModifier) {

View File

@ -13,14 +13,14 @@ export class Battle {
}
private getLevelForWave(): number {
let averageLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
let baseLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
if (!(this.waveIndex % 10))
return Math.floor(averageLevel * 1.2);
return Math.floor(baseLevel * 1.2);
const deviation = 10 / this.waveIndex;
return Math.max(Math.round(averageLevel + Utils.randGauss(deviation)), 1);
return Math.max(Math.round(baseLevel + Math.abs(Utils.randGauss(deviation))), 1);
}
addParticipant(playerPokemon: PlayerPokemon): void {

View File

@ -1,5 +1,4 @@
import { pokemonEvolutions, SpeciesEvolution } from "./pokemon-evolutions";
import { allSpecies } from "./pokemon-species";
import { Species } from "./species";
import { Type } from './type';
import * as Utils from './utils';
@ -460,7 +459,7 @@ export const biomePools: BiomePools = {
[BiomePoolTier.BOSS]: [ Species.PIDGEOT, Species.FEAROW, Species.SKARMORY, Species.SWELLOW, Species.AGGRON, Species.ALTARIA, Species.STARAPTOR, Species.UNFEZANT, Species.BRAVIARY, Species.MANDIBUZZ ],
[BiomePoolTier.BOSS_RARE]: [ Species.BLAZIKEN, Species.RAMPARDOS, Species.BASTIODON ],
[BiomePoolTier.BOSS_SUPER_RARE]: [ Species.TORNADUS ],
[BiomePoolTier.BOSS_ULTRA_RARE]: [ Species.HO_OH, Species.RAYQUAZA ]
[BiomePoolTier.BOSS_ULTRA_RARE]: [ Species.HO_OH ]
},
[Biome.LAND]: {
[BiomePoolTier.COMMON]: [
@ -651,11 +650,11 @@ export const biomePools: BiomePools = {
},
[Biome.WASTELAND]: {
[BiomePoolTier.COMMON]: [
{ 1: [ Species.LARVITAR ], 30: [ Species.PUPITAR ] },
{ 1: [ Species.LARVITAR ], 30: [ Species.PUPITAR ], 55: [ Species.TYRANITAR ] },
{ 1: [ Species.VIBRAVA ], 45: [ Species.FLYGON ] },
{ 1: [ Species.BAGON ], 30: [ Species.SHELGON ], 50: [ Species.SALAMENCE ] },
{ 1: [ Species.GIBLE ], 24: [ Species.GABITE ], 48: [ Species.GARCHOMP ] },
{ 1: [ Species.AXEW ], 38: [ Species.FRAXURE ] }
{ 1: [ Species.AXEW ], 38: [ Species.FRAXURE ], 48: [ Species.HAXORUS ] }
],
[BiomePoolTier.UNCOMMON]: [ { 1: [ Species.SWABLU ], 35: [ Species.ALTARIA ] }, { 1: [ Species.DEINO ], 50: [ Species.ZWEILOUS ], 64: [ Species.HYDREIGON ] } ],
[BiomePoolTier.RARE]: [ { 1: [ Species.DRATINI ], 30: [ Species.DRAGONAIR ], 55: [ Species.DRAGONITE ] } ],
@ -664,7 +663,7 @@ export const biomePools: BiomePools = {
[BiomePoolTier.BOSS]: [ Species.DRAGONITE, Species.TYRANITAR, Species.FLYGON, Species.SALAMENCE, Species.GARCHOMP, Species.HAXORUS ],
[BiomePoolTier.BOSS_RARE]: [ Species.AERODACTYL, Species.DRUDDIGON ],
[BiomePoolTier.BOSS_SUPER_RARE]: [],
[BiomePoolTier.BOSS_ULTRA_RARE]: [ Species.DIALGA ]
[BiomePoolTier.BOSS_ULTRA_RARE]: [ Species.RAYQUAZA, Species.DIALGA ]
},
[Biome.ABYSS]: {
[BiomePoolTier.COMMON]: [ Species.MURKROW, { 1: [ Species.HOUNDOUR ], 24: [ Species.HOUNDOOM ] }, Species.SABLEYE, { 1: [ Species.PURRLOIN ], 20: [ Species.LIEPARD ] }, { 1: [ Species.PAWNIARD ], 52: [ Species.BISHARP ] } ],
@ -1858,6 +1857,7 @@ export const biomePools: BiomePools = {
]
],
[ Species.TYRANITAR, Type.ROCK, Type.DARK, [
[ Biome.WASTELAND, BiomePoolTier.COMMON ],
[ Biome.WASTELAND, BiomePoolTier.BOSS ]
]
],
@ -2500,7 +2500,7 @@ export const biomePools: BiomePools = {
]
],
[ Species.RAYQUAZA, Type.DRAGON, Type.FLYING, [
[ Biome.MOUNTAIN, BiomePoolTier.BOSS_ULTRA_RARE ]
[ Biome.WASTELAND, BiomePoolTier.BOSS_ULTRA_RARE ]
]
],
[ Species.JIRACHI, Type.STEEL, Type.PSYCHIC, [
@ -3562,6 +3562,7 @@ export const biomePools: BiomePools = {
]
],
[ Species.HAXORUS, Type.DRAGON, -1, [
[ Biome.WASTELAND, BiomePoolTier.COMMON ],
[ Biome.WASTELAND, BiomePoolTier.BOSS ]
]
],

View File

@ -53,6 +53,9 @@ export class GameData {
}
private save(): boolean {
if (this.scene.quickStart)
return false;
const data: SaveData = {
trainerId: this.trainerId,
secretId: this.secretId,

View File

@ -453,19 +453,6 @@ class WeightedModifierType {
}
}
class WeightedModifierTypeGroup {
public modifierTypes: WeightedModifierType[];
constructor(...modifierTypes: WeightedModifierType[]) {
this.modifierTypes = modifierTypes;
}
setTier(tier: ModifierTier) {
for (let modifierType of this.modifierTypes)
modifierType.setTier(tier);
}
}
const modifierPool = {
[ModifierTier.COMMON]: [
new WeightedModifierType(new AddPokeballModifierType(PokeballType.POKEBALL, 5, 'pb'), 6),
@ -552,7 +539,7 @@ const modifierPool = {
].map(m => { m.setTier(ModifierTier.MASTER); return m; }),
[ModifierTier.LUXURY]: [
new ExpBoosterModifierType('GOLDEN EGG', 100),
new ModifierType(`GOLDEN ${getPokeballName(PokeballType.POKEBALL)}`, 'Adds 1 extra ITEM option at the end of every battle', (type, _args) => new Modifiers.ExtraModifierModifier(type), 'pb_gold')
new ModifierType(`GOLDEN ${getPokeballName(PokeballType.POKEBALL)}`, 'Adds 1 extra item option at the end of every battle', (type, _args) => new Modifiers.ExtraModifierModifier(type), 'pb_gold')
].map(m => { m.setTier(ModifierTier.LUXURY); return m; }),
};

View File

@ -28,13 +28,15 @@ export class ModifierBar extends Phaser.GameObjects.Container {
for (let modifier of modifiers) {
const icon = modifier.getIcon(this.scene as BattleScene);
this.add(icon);
this.setModifierIconPosition(icon);
this.setModifierIconPosition(icon, modifiers.length);
}
}
setModifierIconPosition(icon: Phaser.GameObjects.Container) {
const x = (this.getIndex(icon) % 12) * 26;
const y = Math.floor((this.getIndex(icon) * 6) / (this.scene.game.canvas.width / 6)) * 20;
setModifierIconPosition(icon: Phaser.GameObjects.Container, modifierCount: integer) {
let rowIcons: integer = 12 + 6 * Math.max((Math.ceil(modifierCount / 12) - 2), 0);
const x = (this.getIndex(icon) % rowIcons) * 26 / (rowIcons / 12);
const y = Math.floor(this.getIndex(icon) / rowIcons) * 20;
icon.setPosition(x, y);
}
@ -477,8 +479,10 @@ export class PokemonLevelIncrementModifier extends ConsumablePokemonModifier {
apply(args: any[]): boolean {
const pokemon = args[0] as PlayerPokemon;
pokemon.level++;
if (pokemon.level <= 100) {
pokemon.exp = getLevelTotalExp(pokemon.level, pokemon.species.growthRate);
pokemon.levelExp = 0;
}
pokemon.scene.unshiftPhase(new LevelUpPhase(pokemon.scene, pokemon.scene.getParty().indexOf(pokemon), pokemon.level - 1, pokemon.level));

View File

@ -61,6 +61,8 @@ export class Weather {
case WeatherType.HAIL:
return type === Type.ICE;
}
return false;
}
getAttackTypeMultiplier(attackType: Type): number {