Add rare candy modifier

This commit is contained in:
Flashfyre 2023-04-04 18:28:21 -04:00
parent 2c71550b35
commit a1b857fbc6
6 changed files with 92 additions and 41 deletions

Binary file not shown.

View File

@ -102,8 +102,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
} }
updateInfo(pokemon: Pokemon, callback?: Function) { updateInfo(pokemon: Pokemon, callback?: Function) {
if (!this.scene) if (!this.scene) {
if (callback)
callback();
return; return;
}
const updatePokemonHp = () => { const updatePokemonHp = () => {
const duration = Utils.clampInt(Math.abs((this.lastHp) - pokemon.hp) * 5, 250, 5000); const duration = Utils.clampInt(Math.abs((this.lastHp) - pokemon.hp) * 5, 250, 5000);
@ -158,8 +161,9 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
const relLevelExp = getLevelRelExp(this.lastLevel + 1, battler.species.growthRate); const relLevelExp = getLevelRelExp(this.lastLevel + 1, battler.species.growthRate);
const levelExp = levelUp ? relLevelExp : battler.levelExp; const levelExp = levelUp ? relLevelExp : battler.levelExp;
let ratio = levelExp / relLevelExp; let ratio = levelExp / relLevelExp;
let duration = ((levelExp - this.lastLevelExp) / relLevelExp) * 1650; let duration = this.visible ? ((levelExp - this.lastLevelExp) / relLevelExp) * 1650 : 0;
this.scene.sound.play('exp'); if (duration)
this.scene.sound.play('exp');
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.expBar, targets: this.expBar,
ease: 'Sine.easeIn', ease: 'Sine.easeIn',
@ -179,7 +183,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
} }
}, },
onComplete: () => { onComplete: () => {
this.scene.sound.stopByKey('exp'); if (duration)
this.scene.sound.stopByKey('exp');
if (ratio === 1) { if (ratio === 1) {
this.lastLevelExp = 0; this.lastLevelExp = 0;
this.lastLevel++; this.lastLevel++;

View File

@ -9,7 +9,7 @@ import { ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, getModifie
import PartyUiHandler from "./ui/party-ui-handler"; import PartyUiHandler from "./ui/party-ui-handler";
import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor as getPokeballTintColor, PokeballType } from "./pokeball"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor as getPokeballTintColor, PokeballType } from "./pokeball";
import { pokemonLevelMoves } from "./pokemon-level-moves"; import { pokemonLevelMoves } from "./pokemon-level-moves";
import { MoveAnim, loadMoveAnimAssets } from "./battle-anims"; import { MoveAnim, initAnim, loadMoveAnimAssets } from "./battle-anims";
import { StatusEffect } from "./status-effect"; import { StatusEffect } from "./status-effect";
export class BattlePhase { export class BattlePhase {
@ -776,10 +776,12 @@ export class LearnMovePhase extends PartyMemberPokemonPhase {
if (pokemon.moveset.length < 4) { if (pokemon.moveset.length < 4) {
pokemon.moveset.push(new PokemonMove(this.moveId, 0, 0)); pokemon.moveset.push(new PokemonMove(this.moveId, 0, 0));
loadMoveAnimAssets(this.scene, [ this.moveId ]) initAnim(this.moveId).then(() => {
.then(() => { loadMoveAnimAssets(this.scene, [ this.moveId ], true)
this.scene.sound.play('level_up_fanfare'); .then(() => {
this.scene.ui.showText(`${pokemon.name} learned\n${Utils.toPokemonUpperCase(move.name)}!`, null, () => this.end(), null, true); this.scene.sound.play('level_up_fanfare');
this.scene.ui.showText(`${pokemon.name} learned\n${Utils.toPokemonUpperCase(move.name)}!`, null, () => this.end(), null, true);
});
}); });
} else } else
this.end(); this.end();
@ -965,16 +967,14 @@ export class SelectModifierPhase extends BattlePhase {
this.scene.ui.setModeWithoutClear(Mode.PARTY, false, (slotIndex: integer) => { this.scene.ui.setModeWithoutClear(Mode.PARTY, false, (slotIndex: integer) => {
if (slotIndex < 6) { if (slotIndex < 6) {
this.scene.ui.setMode(Mode.MODIFIER_SELECT); this.scene.ui.setMode(Mode.MODIFIER_SELECT);
this.scene.addModifier(types[cursor].newModifier(this.scene.getParty()[slotIndex])); this.scene.addModifier(types[cursor].newModifier(this.scene.getParty()[slotIndex])).then(() => super.end());
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
super.end();
} else } else
this.scene.ui.setMode(Mode.MODIFIER_SELECT); this.scene.ui.setMode(Mode.MODIFIER_SELECT);
}, pokemonModifierType.selectFilter); }, pokemonModifierType.selectFilter);
} else { } else {
this.scene.addModifier(types[cursor].newModifier()) this.scene.addModifier(types[cursor].newModifier()).then(() => super.end());
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
super.end();
} }
}); });
} }

View File

@ -410,31 +410,44 @@ export default class BattleScene extends Phaser.Scene {
this.phaseQueue.push(new CommandPhase(this)); this.phaseQueue.push(new CommandPhase(this));
} }
addModifier(modifier: Modifier): void { addModifier(modifier: Modifier): Promise<void> {
if (modifier.add(this.modifierBar, this.modifiers)) return new Promise(resolve => {
this.sound.play('restore'); if (modifier.add(this.modifierBar, this.modifiers))
this.sound.play('restore');
if (modifier instanceof ConsumableModifier) { if (modifier instanceof ConsumableModifier) {
const args = [ this ]; const args = [ this ];
if (modifier.shouldApply(args)) if (modifier.shouldApply(args))
modifier.apply(args); modifier.apply(args);
return; resolve();
} return;
if (modifier instanceof PokemonModifier) {
for (let p in this.party) {
const pokemon = this.party[p];
if (modifier instanceof ConsumablePokemonModifier) {
const args = [ pokemon ];
if (modifier.shouldApply(args))
modifier.apply(args);
}
pokemon.calculateStats();
pokemon.updateInfo();
} }
}
let pokemonToUpdate = 0;
if (modifier instanceof PokemonModifier) {
for (let p in this.party) {
const pokemon = this.party[p];
if (modifier instanceof ConsumablePokemonModifier) {
const args = [ pokemon ];
if (modifier.shouldApply(args))
modifier.apply(args);
}
pokemonToUpdate++;
pokemon.calculateStats();
pokemon.updateInfo(() => {
if (!(--pokemonToUpdate))
resolve();
});
}
}
if (!pokemonToUpdate)
resolve();
});
} }
getModifier(modifierType: { new(...args: any[]): Modifier }): Modifier { getModifier(modifierType: { new(...args: any[]): Modifier }): Modifier {

View File

@ -1,4 +1,6 @@
import { LevelUpPhase } from "./battle-phase";
import BattleScene from "./battle-scene"; import BattleScene from "./battle-scene";
import { getLevelTotalExp } from "./exp";
import { getPokeballName, PokeballType } from "./pokeball"; import { getPokeballName, PokeballType } from "./pokeball";
import Pokemon, { PlayerPokemon } from "./pokemon"; import Pokemon, { PlayerPokemon } from "./pokemon";
import { Stat, getStatName } from "./pokemon-stat"; import { Stat, getStatName } from "./pokemon-stat";
@ -240,6 +242,24 @@ export class PokemonHpRestoreModifier extends ConsumablePokemonModifier {
} }
} }
export class PokemonLevelIncrementModifier extends ConsumablePokemonModifier {
constructor(type: ModifierType, pokemonId: integer) {
super(type, pokemonId);
}
apply(args: any[]): boolean {
const pokemon = args[0] as PlayerPokemon;
pokemon.level++;
pokemon.exp = getLevelTotalExp(pokemon.level, pokemon.species.growthRate);
pokemon.levelExp = 0;
const scene = pokemon.scene as BattleScene;
scene.unshiftPhase(new LevelUpPhase(scene, scene.getParty().indexOf(pokemon), pokemon.level));
return true;
}
}
export class ExpBoosterModifier extends Modifier { export class ExpBoosterModifier extends Modifier {
private boostMultiplier: integer; private boostMultiplier: integer;
@ -376,22 +396,34 @@ export abstract class PokemonModifierType extends ModifierType {
export class PokemonHpRestoreModifierType extends PokemonModifierType { export class PokemonHpRestoreModifierType extends PokemonModifierType {
protected restorePercent: integer; protected restorePercent: integer;
constructor(name: string, restorePercent: integer, newModifierFunc?: Function, iconImage?: string) { constructor(name: string, restorePercent: integer, newModifierFunc?: Function, selectFilter?: Function, iconImage?: string) {
super(name, `Restore ${restorePercent} HP or ${restorePercent}% HP for one POKéMON, whichever is higher`, super(name, `Restore ${restorePercent} HP or ${restorePercent}% HP for one POKéMON, whichever is higher`,
newModifierFunc || ((_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, false)), newModifierFunc || ((_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, false)),
(pokemon: PlayerPokemon) => { selectFilter || ((pokemon: PlayerPokemon) => {
if (pokemon.hp >= pokemon.getMaxHp()) if (!pokemon.hp || pokemon.hp >= pokemon.getMaxHp())
return PartyUiHandler.NoEffectMessage; return PartyUiHandler.NoEffectMessage;
return null; return null;
}, iconImage); }), iconImage);
this.restorePercent = restorePercent; this.restorePercent = restorePercent;
} }
} }
export class PokemonLevelIncrementModifierType extends PokemonModifierType {
constructor(name: string, iconImage?: string) {
super(name, `Increase a POKéMON\'s level by 1`, (type, args) => new PokemonLevelIncrementModifier(type, (args[0] as PlayerPokemon).id),
(_pokemon: PlayerPokemon) => null, iconImage);
}
}
export class PokemonReviveModifierType extends PokemonHpRestoreModifierType { export class PokemonReviveModifierType extends PokemonHpRestoreModifierType {
constructor(name: string, restorePercent: integer, iconImage?: string) { constructor(name: string, restorePercent: integer, iconImage?: string) {
super(name, restorePercent, (_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, true), iconImage); super(name, restorePercent, (_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, true),
((pokemon: PlayerPokemon) => {
if (pokemon.hp)
return PartyUiHandler.NoEffectMessage;
return null;
}), iconImage);
this.description = `Revive one POKéMON and restore ${restorePercent}% HP`; this.description = `Revive one POKéMON and restore ${restorePercent}% HP`;
this.selectFilter = (pokemon: PlayerPokemon) => { this.selectFilter = (pokemon: PlayerPokemon) => {
@ -471,6 +503,7 @@ const modifierPool = {
const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.6).length; const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.6).length;
return thresholdPartyMemberCount; return thresholdPartyMemberCount;
}), }),
new PokemonLevelIncrementModifierType('RARE CANDY'),
new PokemonBaseStatBoosterModifierType('HP-UP', Stat.HP), new PokemonBaseStatBoosterModifierType('HP-UP', Stat.HP),
new PokemonBaseStatBoosterModifierType('PROTEIN', Stat.ATK), new PokemonBaseStatBoosterModifierType('PROTEIN', Stat.ATK),
new PokemonBaseStatBoosterModifierType('IRON', Stat.DEF), new PokemonBaseStatBoosterModifierType('IRON', Stat.DEF),