2024-04-09 07:45:48 +01:00
|
|
|
import Phaser, { Time } from 'phaser';
|
2023-10-26 21:33:59 +01:00
|
|
|
import UI, { Mode } from './ui/ui';
|
2024-04-06 06:36:20 +01:00
|
|
|
import { NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, TurnInitPhase, ReturnPhase, LevelCapPhase, ShowTrainerPhase, LoginPhase, MovePhase, TitlePhase, SwitchPhase } from './phases';
|
2024-03-01 01:08:50 +00:00
|
|
|
import Pokemon, { PlayerPokemon, EnemyPokemon } from './field/pokemon';
|
2024-04-13 23:59:58 +01:00
|
|
|
import PokemonSpecies, { PokemonSpeciesFilter, allSpecies, getPokemonSpecies, initSpecies, speciesStarters } from './data/pokemon-species';
|
2023-03-28 19:54:52 +01:00
|
|
|
import * as Utils from './utils';
|
2024-02-17 05:40:03 +00:00
|
|
|
import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier, PokemonHeldItemModifier, ModifierPredicate, DoubleBattleChanceBoosterModifier, FusePokemonModifier, PokemonFormChangeItemModifier, TerastallizeModifier } from './modifier/modifier';
|
2023-04-20 20:46:05 +01:00
|
|
|
import { PokeballType } from './data/pokeball';
|
|
|
|
import { initCommonAnims, initMoveAnim, loadCommonAnimAssets, loadMoveAnimAssets, populateAnims } from './data/battle-anims';
|
2024-02-22 04:57:49 +00:00
|
|
|
import { Phase } from './phase';
|
2023-04-20 20:46:05 +01:00
|
|
|
import { initGameSpeed } from './system/game-speed';
|
2024-01-13 17:24:24 +00:00
|
|
|
import { Biome } from "./data/enums/biome";
|
2024-04-04 03:52:39 +01:00
|
|
|
import { Arena, ArenaBase } from './field/arena';
|
2024-02-06 21:15:35 +00:00
|
|
|
import { GameData, PlayerGender } from './system/game-data';
|
2023-04-18 03:44:41 +01:00
|
|
|
import StarterSelectUiHandler from './ui/starter-select-ui-handler';
|
2023-04-20 20:46:05 +01:00
|
|
|
import { TextStyle, addTextObject } from './ui/text';
|
2024-01-13 17:24:24 +00:00
|
|
|
import { Moves } from "./data/enums/moves";
|
|
|
|
import { } from "./data/move";
|
|
|
|
import { initMoves } from './data/move';
|
2024-03-18 00:58:12 +00:00
|
|
|
import { ModifierPoolType, getDefaultModifierTypeForTier, getEnemyModifierTypesForWave } from './modifier/modifier-type';
|
2023-04-27 06:14:15 +01:00
|
|
|
import AbilityBar from './ui/ability-bar';
|
2024-04-11 14:24:03 +01:00
|
|
|
import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, IncrementMovePriorityAbAttr, applyAbAttrs, initAbilities } from './data/ability';
|
|
|
|
import { Abilities } from "./data/enums/abilities";
|
2023-10-18 23:01:15 +01:00
|
|
|
import Battle, { BattleType, FixedBattleConfig, fixedBattles } from './battle';
|
2024-03-14 20:26:57 +00:00
|
|
|
import { GameMode, GameModes, gameModes } from './game-mode';
|
2023-12-30 02:04:40 +00:00
|
|
|
import FieldSpritePipeline from './pipelines/field-sprite';
|
2023-06-02 23:33:51 +01:00
|
|
|
import SpritePipeline from './pipelines/sprite';
|
2023-10-04 22:24:28 +01:00
|
|
|
import PartyExpBar from './ui/party-exp-bar';
|
2024-03-21 04:57:28 +00:00
|
|
|
import { TrainerSlot, trainerConfigs } from './data/trainer-config';
|
|
|
|
import Trainer, { TrainerVariant } from './field/trainer';
|
2023-10-07 21:08:33 +01:00
|
|
|
import TrainerData from './system/trainer-data';
|
2023-10-10 01:20:02 +01:00
|
|
|
import SoundFade from 'phaser3-rex-plugins/plugins/soundfade';
|
|
|
|
import { pokemonPrevolutions } from './data/pokemon-evolutions';
|
2023-10-18 23:01:15 +01:00
|
|
|
import PokeballTray from './ui/pokeball-tray';
|
2023-10-26 21:33:59 +01:00
|
|
|
import { Setting, settingOptions } from './system/settings';
|
|
|
|
import SettingsUiHandler from './ui/settings-ui-handler';
|
|
|
|
import MessageUiHandler from './ui/message-ui-handler';
|
2024-01-13 17:24:24 +00:00
|
|
|
import { Species } from './data/enums/species';
|
2023-11-08 03:23:42 +00:00
|
|
|
import InvertPostFX from './pipelines/invert';
|
2023-11-12 05:55:13 +00:00
|
|
|
import { Achv, ModifierAchv, achvs } from './system/achv';
|
2023-12-20 04:51:48 +00:00
|
|
|
import { Voucher, vouchers } from './system/voucher';
|
2023-12-26 06:29:05 +00:00
|
|
|
import { Gender } from './data/gender';
|
2023-12-30 23:41:25 +00:00
|
|
|
import UIPlugin from 'phaser3-rex-plugins/templates/ui/ui-plugin';
|
2024-04-04 03:52:39 +01:00
|
|
|
import { addUiThemeOverrides } from './ui/ui-theme';
|
2024-01-08 04:17:24 +00:00
|
|
|
import PokemonData from './system/pokemon-data';
|
|
|
|
import { Nature } from './data/nature';
|
2024-01-13 17:24:24 +00:00
|
|
|
import { SpeciesFormChangeTimeOfDayTrigger, SpeciesFormChangeTrigger, pokemonFormChanges } from './data/pokemon-forms';
|
2024-01-10 04:34:43 +00:00
|
|
|
import { FormChangePhase, QuietFormChangePhase } from './form-change-phase';
|
2024-01-15 01:47:08 +00:00
|
|
|
import { BattleSpec } from './enums/battle-spec';
|
2024-02-17 05:40:03 +00:00
|
|
|
import { getTypeRgb } from './data/type';
|
2024-03-01 01:08:50 +00:00
|
|
|
import PokemonSpriteSparkleHandler from './field/pokemon-sprite-sparkle-handler';
|
2024-02-22 23:03:36 +00:00
|
|
|
import CharSprite from './ui/char-sprite';
|
2024-03-01 05:27:46 +00:00
|
|
|
import DamageNumberHandler from './field/damage-number-handler';
|
2024-03-08 03:43:15 +00:00
|
|
|
import PokemonInfoContainer from './ui/pokemon-info-container';
|
2024-03-16 01:59:34 +00:00
|
|
|
import { biomeDepths } from './data/biomes';
|
2024-03-25 20:10:43 +00:00
|
|
|
import { initTouchControls } from './touch-controls';
|
2024-04-01 02:14:35 +01:00
|
|
|
import { UiTheme } from './enums/ui-theme';
|
2024-04-02 00:56:46 +01:00
|
|
|
import { SceneBase } from './scene-base';
|
2024-04-13 23:59:58 +01:00
|
|
|
import CandyBar from './ui/candy-bar';
|
2024-04-19 03:52:26 +01:00
|
|
|
import { Variant, variantData } from './data/variant';
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-04-04 17:34:23 +01:00
|
|
|
export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1";
|
2024-03-16 01:59:34 +00:00
|
|
|
|
2024-03-30 00:11:52 +00:00
|
|
|
export const SEED_OVERRIDE = '';
|
2024-03-30 22:46:33 +00:00
|
|
|
export const STARTER_SPECIES_OVERRIDE = 0;
|
|
|
|
export const STARTER_FORM_OVERRIDE = 0;
|
2024-03-16 01:59:34 +00:00
|
|
|
export const STARTING_LEVEL_OVERRIDE = 0;
|
|
|
|
export const STARTING_WAVE_OVERRIDE = 0;
|
|
|
|
export const STARTING_BIOME_OVERRIDE = Biome.TOWN;
|
|
|
|
export const STARTING_MONEY_OVERRIDE = 0;
|
2024-04-02 02:02:48 +01:00
|
|
|
|
|
|
|
export const ABILITY_OVERRIDE = Abilities.NONE;
|
|
|
|
export const MOVE_OVERRIDE = Moves.NONE;
|
|
|
|
export const OPP_SPECIES_OVERRIDE = 0;
|
|
|
|
export const OPP_ABILITY_OVERRIDE = Abilities.NONE;
|
|
|
|
export const OPP_MOVE_OVERRIDE = Moves.NONE;
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
const DEBUG_RNG = false;
|
2024-03-16 01:59:34 +00:00
|
|
|
|
|
|
|
export const startingWave = STARTING_WAVE_OVERRIDE || 1;
|
2023-04-09 05:22:14 +01:00
|
|
|
|
2024-02-25 02:16:19 +00:00
|
|
|
const expSpriteKeys: string[] = [];
|
2024-04-09 07:45:48 +01:00
|
|
|
const repeatInputDelayMillis = 250;
|
2024-02-25 02:16:19 +00:00
|
|
|
|
2024-04-13 23:59:58 +01:00
|
|
|
export let starterColors: StarterColors;
|
|
|
|
interface StarterColors {
|
|
|
|
[key: string]: [string, string]
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
export enum Button {
|
|
|
|
UP,
|
|
|
|
DOWN,
|
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
2023-12-30 23:41:25 +00:00
|
|
|
SUBMIT,
|
2023-04-11 05:24:55 +01:00
|
|
|
ACTION,
|
|
|
|
CANCEL,
|
2023-10-26 21:33:59 +01:00
|
|
|
MENU,
|
2023-04-18 03:44:41 +01:00
|
|
|
CYCLE_SHINY,
|
|
|
|
CYCLE_FORM,
|
|
|
|
CYCLE_GENDER,
|
2023-04-26 17:50:21 +01:00
|
|
|
CYCLE_ABILITY,
|
2024-01-06 03:24:05 +00:00
|
|
|
CYCLE_NATURE,
|
2024-04-19 03:52:26 +01:00
|
|
|
CYCLE_VARIANT,
|
2023-04-11 05:24:55 +01:00
|
|
|
SPEED_UP,
|
|
|
|
SLOW_DOWN
|
|
|
|
}
|
|
|
|
|
2023-04-28 20:03:42 +01:00
|
|
|
export interface PokeballCounts {
|
2023-04-22 03:59:09 +01:00
|
|
|
[pb: string]: integer;
|
|
|
|
}
|
|
|
|
|
2023-10-26 21:33:59 +01:00
|
|
|
export type AnySound = Phaser.Sound.WebAudioSound | Phaser.Sound.HTML5AudioSound | Phaser.Sound.NoAudioSound;
|
|
|
|
|
2024-04-02 00:56:46 +01:00
|
|
|
export default class BattleScene extends SceneBase {
|
2023-12-30 23:41:25 +00:00
|
|
|
public rexUI: UIPlugin;
|
|
|
|
|
2024-01-12 01:27:50 +00:00
|
|
|
public sessionPlayTime: integer = null;
|
2023-10-26 21:33:59 +01:00
|
|
|
public masterVolume: number = 0.5;
|
|
|
|
public bgmVolume: number = 1;
|
|
|
|
public seVolume: number = 1;
|
2023-04-12 16:30:47 +01:00
|
|
|
public gameSpeed: integer = 1;
|
2024-03-01 05:27:46 +00:00
|
|
|
public damageNumbersMode: integer = 0;
|
2023-11-05 01:53:38 +00:00
|
|
|
public showLevelUpStats: boolean = true;
|
2024-04-04 17:34:23 +01:00
|
|
|
public enableTutorials: boolean = import.meta.env.VITE_BYPASS_TUTORIAL === "1";
|
2024-04-04 20:22:05 +01:00
|
|
|
public enableRetries: boolean = false;
|
2024-04-01 02:14:35 +01:00
|
|
|
public uiTheme: UiTheme = UiTheme.DEFAULT;
|
|
|
|
public windowType: integer = 0;
|
2024-02-25 02:16:19 +00:00
|
|
|
public experimentalSprites: boolean = false;
|
2024-04-09 20:06:47 +01:00
|
|
|
public moveAnimations: boolean = true;
|
2024-04-18 05:49:44 +01:00
|
|
|
public expGainsSpeed: integer = 0;
|
2024-04-09 20:34:57 +01:00
|
|
|
public hpBarSpeed: integer = 0;
|
2024-03-06 02:54:26 +00:00
|
|
|
public fusionPaletteSwaps: boolean = true;
|
2024-04-16 01:13:58 +01:00
|
|
|
public gamepadSupport: boolean = true;
|
2023-12-25 20:48:16 +00:00
|
|
|
public enableTouchControls: boolean = false;
|
|
|
|
public enableVibration: boolean = false;
|
2023-10-21 13:58:39 +01:00
|
|
|
|
2024-04-17 20:56:29 +01:00
|
|
|
public disableMenu: boolean = false;
|
|
|
|
|
2023-04-18 06:32:26 +01:00
|
|
|
public gameData: GameData;
|
2024-03-15 01:49:49 +00:00
|
|
|
public sessionSlotId: integer;
|
2023-04-18 03:44:41 +01:00
|
|
|
|
2024-02-22 04:57:49 +00:00
|
|
|
private phaseQueue: Phase[];
|
|
|
|
private phaseQueuePrepend: Phase[];
|
2023-04-27 19:30:03 +01:00
|
|
|
private phaseQueuePrependSpliceIndex: integer;
|
2024-03-11 22:13:07 +00:00
|
|
|
private nextCommandPhaseQueue: Phase[];
|
2024-02-22 04:57:49 +00:00
|
|
|
private currentPhase: Phase;
|
|
|
|
private standbyPhase: Phase;
|
2023-03-28 19:54:52 +01:00
|
|
|
public field: Phaser.GameObjects.Container;
|
|
|
|
public fieldUI: Phaser.GameObjects.Container;
|
2024-02-22 23:03:36 +00:00
|
|
|
public charSprite: CharSprite;
|
2023-10-18 23:01:15 +01:00
|
|
|
public pbTray: PokeballTray;
|
|
|
|
public pbTrayEnemy: PokeballTray;
|
2023-04-27 06:14:15 +01:00
|
|
|
public abilityBar: AbilityBar;
|
2023-10-04 22:24:28 +01:00
|
|
|
public partyExpBar: PartyExpBar;
|
2024-04-13 23:59:58 +01:00
|
|
|
public candyBar: CandyBar;
|
2024-03-31 20:49:45 +01:00
|
|
|
public arenaBg: Phaser.GameObjects.Sprite;
|
|
|
|
public arenaBgTransition: Phaser.GameObjects.Sprite;
|
2023-05-09 17:43:28 +01:00
|
|
|
public arenaPlayer: ArenaBase;
|
|
|
|
public arenaPlayerTransition: ArenaBase;
|
|
|
|
public arenaEnemy: ArenaBase;
|
|
|
|
public arenaNextEnemy: ArenaBase;
|
2023-04-17 05:46:50 +01:00
|
|
|
public arena: Arena;
|
2023-06-01 00:54:57 +01:00
|
|
|
public gameMode: GameMode;
|
2024-03-17 15:36:19 +00:00
|
|
|
public score: integer;
|
2024-04-05 15:14:49 +01:00
|
|
|
public lockModifierTiers: boolean;
|
2023-03-28 19:54:52 +01:00
|
|
|
public trainer: Phaser.GameObjects.Sprite;
|
2023-10-18 23:01:15 +01:00
|
|
|
public lastEnemyTrainer: Trainer;
|
2023-03-31 04:02:35 +01:00
|
|
|
public currentBattle: Battle;
|
2023-04-22 03:59:09 +01:00
|
|
|
public pokeballCounts: PokeballCounts;
|
2023-10-22 01:23:43 +01:00
|
|
|
public money: integer;
|
2024-03-08 03:43:15 +00:00
|
|
|
public pokemonInfoContainer: PokemonInfoContainer;
|
2023-03-28 19:54:52 +01:00
|
|
|
private party: PlayerPokemon[];
|
2023-04-19 04:54:07 +01:00
|
|
|
private waveCountText: Phaser.GameObjects.Text;
|
2023-10-22 01:23:43 +01:00
|
|
|
private moneyText: Phaser.GameObjects.Text;
|
2024-03-19 04:03:41 +00:00
|
|
|
private scoreText: Phaser.GameObjects.Text;
|
2023-03-28 19:54:52 +01:00
|
|
|
private modifierBar: ModifierBar;
|
2023-04-21 00:44:56 +01:00
|
|
|
private enemyModifierBar: ModifierBar;
|
2023-11-10 20:51:34 +00:00
|
|
|
private fieldOverlay: Phaser.GameObjects.Rectangle;
|
2023-04-10 00:15:21 +01:00
|
|
|
private modifiers: PersistentModifier[];
|
2023-10-28 18:24:57 +01:00
|
|
|
private enemyModifiers: PersistentModifier[];
|
2023-03-28 19:54:52 +01:00
|
|
|
public uiContainer: Phaser.GameObjects.Container;
|
|
|
|
public ui: UI;
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
public seed: string;
|
|
|
|
public waveSeed: string;
|
2024-03-16 01:59:34 +00:00
|
|
|
public waveCycleOffset: integer;
|
2024-03-25 15:00:42 +00:00
|
|
|
public offsetGym: boolean;
|
2023-10-18 23:01:15 +01:00
|
|
|
|
2024-03-01 05:27:46 +00:00
|
|
|
public damageNumberHandler: DamageNumberHandler
|
2024-02-17 05:40:03 +00:00
|
|
|
private spriteSparkleHandler: PokemonSpriteSparkleHandler;
|
|
|
|
|
2023-12-30 02:04:40 +00:00
|
|
|
public fieldSpritePipeline: FieldSpritePipeline;
|
2023-06-02 23:33:51 +01:00
|
|
|
public spritePipeline: SpritePipeline;
|
2023-04-04 01:47:41 +01:00
|
|
|
|
2023-10-26 21:33:59 +01:00
|
|
|
private bgm: AnySound;
|
2023-04-18 06:32:26 +01:00
|
|
|
private bgmResumeTimer: Phaser.Time.TimerEvent;
|
2023-10-26 21:33:59 +01:00
|
|
|
private bgmCache: Set<string> = new Set();
|
2024-01-12 01:27:50 +00:00
|
|
|
private playTimeTimer: Phaser.Time.TimerEvent;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
2024-04-09 07:45:48 +01:00
|
|
|
private lastProcessedButtonPressTimes: Map<Button, number> = new Map();
|
|
|
|
// movementButtonLock ensures only a single movement key is firing repeated inputs
|
2024-04-09 17:34:28 +01:00
|
|
|
// (i.e. by holding down a button) at a time
|
2024-04-09 07:45:48 +01:00
|
|
|
private movementButtonLock: Button;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-04-15 23:55:03 +01:00
|
|
|
// using a dualshock controller as a map
|
|
|
|
private gamepadKeyConfig = {
|
|
|
|
[Button.UP]: 12, // up
|
|
|
|
[Button.DOWN]: 13, // down
|
|
|
|
[Button.LEFT]: 14, // left
|
|
|
|
[Button.RIGHT]: 15, // right
|
|
|
|
[Button.SUBMIT]: 17, // touchpad
|
|
|
|
[Button.ACTION]: 0, // X
|
|
|
|
[Button.CANCEL]: 1, // O
|
|
|
|
[Button.MENU]: 9, // options
|
|
|
|
[Button.CYCLE_SHINY]: 5, // RB
|
|
|
|
[Button.CYCLE_FORM]: 4, // LB
|
|
|
|
[Button.CYCLE_GENDER]: 6, // LT
|
|
|
|
[Button.CYCLE_ABILITY]: 7, // RT
|
|
|
|
[Button.CYCLE_NATURE]: 2, // square
|
2024-04-19 03:52:26 +01:00
|
|
|
[Button.CYCLE_VARIANT]: 3, // triangle
|
2024-04-15 23:55:03 +01:00
|
|
|
[Button.SPEED_UP]: 10, // L3
|
|
|
|
[Button.SLOW_DOWN]: 11 // R3
|
2024-04-16 00:44:30 +01:00
|
|
|
};
|
2024-04-15 23:55:03 +01:00
|
|
|
public gamepadButtonStates: boolean[] = new Array(17).fill(false);
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
public rngCounter: integer = 0;
|
|
|
|
public rngSeedOverride: string = '';
|
|
|
|
public rngOffset: integer = 0;
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
constructor() {
|
|
|
|
super('battle');
|
|
|
|
|
2023-04-27 19:30:03 +01:00
|
|
|
initSpecies();
|
|
|
|
initMoves();
|
|
|
|
initAbilities();
|
2023-04-18 03:44:41 +01:00
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
this.phaseQueue = [];
|
|
|
|
this.phaseQueuePrepend = [];
|
2023-04-27 19:30:03 +01:00
|
|
|
this.phaseQueuePrependSpliceIndex = -1;
|
2024-03-11 22:13:07 +00:00
|
|
|
this.nextCommandPhaseQueue = [];
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-02-25 02:16:19 +00:00
|
|
|
loadPokemonAtlas(key: string, atlasPath: string, experimental?: boolean) {
|
|
|
|
if (experimental === undefined)
|
|
|
|
experimental = this.experimentalSprites;
|
2024-04-19 03:52:26 +01:00
|
|
|
let variant = atlasPath.includes('variant/');
|
|
|
|
if (experimental)
|
|
|
|
experimental = this.hasExpSprite(key);
|
|
|
|
if (variant)
|
|
|
|
atlasPath = atlasPath.replace('variant/', '');
|
|
|
|
this.load.atlas(key, `images/pokemon/${variant ? 'variant/' : ''}${experimental ? 'exp/' : ''}${atlasPath}.png`, `images/pokemon/${variant ? 'variant/' : ''}${experimental ? 'exp/' : ''}${atlasPath}.json`);
|
2024-02-25 02:16:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-19 03:52:26 +01:00
|
|
|
async preload() {
|
2024-04-01 17:48:35 +01:00
|
|
|
if (DEBUG_RNG) {
|
|
|
|
const scene = this;
|
|
|
|
const originalRealInRange = Phaser.Math.RND.realInRange;
|
|
|
|
Phaser.Math.RND.realInRange = function (min: number, max: number): number {
|
|
|
|
const ret = originalRealInRange.apply(this, [ min, max ]);
|
|
|
|
const args = [ 'RNG', ++scene.rngCounter, ret / (max - min), `min: ${min} / max: ${max}` ];
|
|
|
|
args.push(`seed: ${scene.rngSeedOverride || scene.waveSeed || scene.seed}`);
|
|
|
|
if (scene.rngOffset)
|
|
|
|
args.push(`offset: ${scene.rngOffset}`);
|
|
|
|
console.log(...args);
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
}
|
2023-04-27 19:30:03 +01:00
|
|
|
|
2023-04-04 01:47:41 +01:00
|
|
|
populateAnims();
|
2024-04-19 03:52:26 +01:00
|
|
|
|
|
|
|
await fetch('./images/pokemon/variant/_masterlist.json').then(res => res.json()).then(v => Object.keys(v).forEach(k => variantData[k] = v[k]));
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
create() {
|
2023-04-12 16:30:47 +01:00
|
|
|
initGameSpeed.apply(this);
|
|
|
|
|
2023-12-14 05:41:35 +00:00
|
|
|
this.gameData = new GameData(this);
|
|
|
|
|
2024-04-01 02:14:35 +01:00
|
|
|
addUiThemeOverrides(this);
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
this.setupControls();
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
this.load.setBaseURL();
|
|
|
|
|
2023-06-02 23:33:51 +01:00
|
|
|
this.spritePipeline = new SpritePipeline(this.game);
|
|
|
|
(this.renderer as Phaser.Renderer.WebGL.WebGLRenderer).pipelines.add('Sprite', this.spritePipeline);
|
2023-04-04 01:47:41 +01:00
|
|
|
|
2023-12-30 02:04:40 +00:00
|
|
|
this.fieldSpritePipeline = new FieldSpritePipeline(this.game);
|
|
|
|
(this.renderer as Phaser.Renderer.WebGL.WebGLRenderer).pipelines.add('FieldSprite', this.fieldSpritePipeline);
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
this.time.delayedCall(20, () => this.launchBattle());
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
this.checkInput();
|
2023-11-04 04:32:12 +00:00
|
|
|
this.ui?.update();
|
2023-04-11 05:24:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
launchBattle() {
|
2024-03-31 20:49:45 +01:00
|
|
|
this.arenaBg = this.add.sprite(0, 0, 'plains_bg');
|
|
|
|
this.arenaBgTransition = this.add.sprite(0, 0, 'plains_bg');
|
2024-01-15 01:47:08 +00:00
|
|
|
|
|
|
|
[ this.arenaBgTransition, this.arenaBg ].forEach(a => {
|
2024-03-21 17:12:05 +00:00
|
|
|
a.setPipeline(this.fieldSpritePipeline);
|
2024-01-15 01:47:08 +00:00
|
|
|
a.setScale(6);
|
|
|
|
a.setOrigin(0);
|
2024-03-21 17:12:05 +00:00
|
|
|
a.setSize(320, 240);
|
2024-01-15 01:47:08 +00:00
|
|
|
});
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const field = this.add.container(0, 0);
|
|
|
|
field.setScale(6);
|
|
|
|
|
|
|
|
this.field = field;
|
|
|
|
|
|
|
|
const fieldUI = this.add.container(0, this.game.canvas.height);
|
2023-04-11 04:15:06 +01:00
|
|
|
fieldUI.setDepth(1);
|
2023-03-28 19:54:52 +01:00
|
|
|
fieldUI.setScale(6);
|
|
|
|
|
|
|
|
this.fieldUI = fieldUI;
|
|
|
|
|
2024-04-02 00:56:46 +01:00
|
|
|
const transition = this.make.rexTransitionImagePack({
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
scale: 6,
|
|
|
|
key: 'loading_bg',
|
|
|
|
origin: { x: 0, y: 0 }
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
transition.transit({
|
|
|
|
mode: 'blinds',
|
|
|
|
ease: 'Cubic.easeInOut',
|
|
|
|
duration: 1250,
|
|
|
|
oncomplete: () => transition.destroy()
|
|
|
|
});
|
|
|
|
|
|
|
|
this.add.existing(transition);
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const uiContainer = this.add.container(0, 0);
|
2023-04-11 04:15:06 +01:00
|
|
|
uiContainer.setDepth(2);
|
2023-03-28 19:54:52 +01:00
|
|
|
uiContainer.setScale(6);
|
|
|
|
|
|
|
|
this.uiContainer = uiContainer;
|
|
|
|
|
2023-11-10 20:51:34 +00:00
|
|
|
const overlayWidth = this.game.canvas.width / 6;
|
|
|
|
const overlayHeight = (this.game.canvas.height / 6) - 48;
|
|
|
|
this.fieldOverlay = this.add.rectangle(0, overlayHeight * -1 - 48, overlayWidth, overlayHeight, 0x424242);
|
|
|
|
this.fieldOverlay.setOrigin(0, 0);
|
|
|
|
this.fieldOverlay.setAlpha(0);
|
|
|
|
this.fieldUI.add(this.fieldOverlay);
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
this.modifiers = [];
|
2023-04-21 00:44:56 +01:00
|
|
|
this.enemyModifiers = [];
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
this.modifierBar = new ModifierBar(this);
|
2023-03-29 05:31:25 +01:00
|
|
|
this.add.existing(this.modifierBar);
|
|
|
|
uiContainer.add(this.modifierBar);
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-04-21 00:44:56 +01:00
|
|
|
this.enemyModifierBar = new ModifierBar(this, true);
|
|
|
|
this.add.existing(this.enemyModifierBar);
|
|
|
|
uiContainer.add(this.enemyModifierBar);
|
|
|
|
|
2024-02-22 23:03:36 +00:00
|
|
|
this.charSprite = new CharSprite(this);
|
|
|
|
this.charSprite.setup();
|
|
|
|
|
|
|
|
this.fieldUI.add(this.charSprite);
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
this.pbTray = new PokeballTray(this, true);
|
|
|
|
this.pbTray.setup();
|
|
|
|
|
|
|
|
this.pbTrayEnemy = new PokeballTray(this, false);
|
|
|
|
this.pbTrayEnemy.setup();
|
|
|
|
|
|
|
|
this.fieldUI.add(this.pbTray);
|
|
|
|
this.fieldUI.add(this.pbTrayEnemy);
|
|
|
|
|
2023-04-27 06:14:15 +01:00
|
|
|
this.abilityBar = new AbilityBar(this);
|
|
|
|
this.abilityBar.setup();
|
|
|
|
this.fieldUI.add(this.abilityBar);
|
|
|
|
|
2023-10-04 22:24:28 +01:00
|
|
|
this.partyExpBar = new PartyExpBar(this);
|
|
|
|
this.partyExpBar.setup();
|
|
|
|
this.fieldUI.add(this.partyExpBar);
|
|
|
|
|
2024-04-13 23:59:58 +01:00
|
|
|
this.candyBar = new CandyBar(this);
|
|
|
|
this.candyBar.setup();
|
|
|
|
this.fieldUI.add(this.candyBar);
|
|
|
|
|
2023-04-22 03:59:09 +01:00
|
|
|
this.waveCountText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, startingWave.toString(), TextStyle.BATTLE_INFO);
|
2023-04-19 04:54:07 +01:00
|
|
|
this.waveCountText.setOrigin(1, 0);
|
|
|
|
this.fieldUI.add(this.waveCountText);
|
|
|
|
|
2024-03-19 04:03:41 +00:00
|
|
|
this.moneyText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, '', TextStyle.MONEY);
|
2023-10-22 01:23:43 +01:00
|
|
|
this.moneyText.setOrigin(1, 0);
|
|
|
|
this.fieldUI.add(this.moneyText);
|
|
|
|
|
2024-03-19 04:03:41 +00:00
|
|
|
this.scoreText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, '', TextStyle.PARTY, { fontSize: '54px' });
|
|
|
|
this.scoreText.setOrigin(1, 0);
|
|
|
|
this.fieldUI.add(this.scoreText);
|
|
|
|
|
2023-10-22 01:23:43 +01:00
|
|
|
this.updateUIPositions();
|
|
|
|
|
2024-03-01 05:27:46 +00:00
|
|
|
this.damageNumberHandler = new DamageNumberHandler();
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
this.spriteSparkleHandler = new PokemonSpriteSparkleHandler();
|
|
|
|
this.spriteSparkleHandler.setup(this);
|
|
|
|
|
2024-03-08 03:43:15 +00:00
|
|
|
this.pokemonInfoContainer = new PokemonInfoContainer(this, (this.game.canvas.width / 6) + 52, -(this.game.canvas.height / 6) + 66);
|
|
|
|
this.pokemonInfoContainer.setup();
|
|
|
|
|
|
|
|
this.fieldUI.add(this.pokemonInfoContainer);
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
this.party = [];
|
|
|
|
|
2023-03-29 05:31:25 +01:00
|
|
|
let loadPokemonAssets = [];
|
|
|
|
|
2023-05-09 17:43:28 +01:00
|
|
|
this.arenaPlayer = new ArenaBase(this, true);
|
|
|
|
this.arenaPlayerTransition = new ArenaBase(this, true);
|
|
|
|
this.arenaEnemy = new ArenaBase(this, false);
|
|
|
|
this.arenaNextEnemy = new ArenaBase(this, false);
|
2023-04-12 05:37:56 +01:00
|
|
|
|
|
|
|
this.arenaBgTransition.setVisible(false);
|
|
|
|
this.arenaPlayerTransition.setVisible(false);
|
2024-01-15 01:47:08 +00:00
|
|
|
this.arenaNextEnemy.setVisible(false);
|
2023-04-12 05:37:56 +01:00
|
|
|
|
2024-01-15 01:47:08 +00:00
|
|
|
[ this.arenaPlayer, this.arenaPlayerTransition, this.arenaEnemy, this.arenaNextEnemy ].forEach(a => {
|
2023-05-09 17:43:28 +01:00
|
|
|
if (a instanceof Phaser.GameObjects.Sprite)
|
|
|
|
a.setOrigin(0, 0);
|
2023-04-12 05:37:56 +01:00
|
|
|
field.add(a);
|
|
|
|
});
|
|
|
|
|
2024-02-06 21:15:35 +00:00
|
|
|
const trainer = this.addFieldSprite(0, 0, `trainer_${this.gameData.gender === PlayerGender.FEMALE ? 'f' : 'm'}_back`);
|
2023-03-28 19:54:52 +01:00
|
|
|
trainer.setOrigin(0.5, 1);
|
|
|
|
|
|
|
|
field.add(trainer);
|
|
|
|
|
|
|
|
this.trainer = trainer;
|
|
|
|
|
|
|
|
this.anims.create({
|
|
|
|
key: 'prompt',
|
|
|
|
frames: this.anims.generateFrameNumbers('prompt', { start: 1, end: 4 }),
|
|
|
|
frameRate: 6,
|
|
|
|
repeat: -1,
|
|
|
|
showOnStart: true
|
|
|
|
});
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
this.anims.create({
|
|
|
|
key: 'tera_sparkle',
|
|
|
|
frames: this.anims.generateFrameNumbers('tera_sparkle', { start: 0, end: 12 }),
|
|
|
|
frameRate: 18,
|
|
|
|
repeat: 0,
|
|
|
|
showOnStart: true,
|
|
|
|
hideOnComplete: true
|
|
|
|
});
|
|
|
|
|
2023-04-22 03:59:09 +01:00
|
|
|
this.reset();
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const ui = new UI(this);
|
|
|
|
this.uiContainer.add(ui);
|
|
|
|
|
|
|
|
this.ui = ui;
|
|
|
|
|
|
|
|
ui.setup();
|
|
|
|
|
2024-04-04 14:45:25 +01:00
|
|
|
const defaultMoves = [ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ];
|
|
|
|
|
2023-04-19 23:19:55 +01:00
|
|
|
Promise.all([
|
|
|
|
Promise.all(loadPokemonAssets),
|
|
|
|
initCommonAnims().then(() => loadCommonAnimAssets(this, true)),
|
2024-04-13 23:59:58 +01:00
|
|
|
Promise.all([ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ].map(m => initMoveAnim(m))).then(() => loadMoveAnimAssets(this, defaultMoves, true)),
|
|
|
|
this.initStarterColors()
|
2023-04-19 23:19:55 +01:00
|
|
|
]).then(() => {
|
2024-02-27 20:16:06 +00:00
|
|
|
this.pushPhase(new LoginPhase(this));
|
2024-03-15 01:49:49 +00:00
|
|
|
this.pushPhase(new TitlePhase(this));
|
2023-03-29 05:31:25 +01:00
|
|
|
|
|
|
|
this.shiftPhase();
|
|
|
|
});
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-01-12 01:27:50 +00:00
|
|
|
initSession(): void {
|
2024-03-15 19:13:32 +00:00
|
|
|
if (this.sessionPlayTime === null)
|
|
|
|
this.sessionPlayTime = 0;
|
2024-01-12 01:27:50 +00:00
|
|
|
|
|
|
|
if (this.playTimeTimer)
|
|
|
|
this.playTimeTimer.destroy();
|
|
|
|
|
|
|
|
this.playTimeTimer = this.time.addEvent({
|
|
|
|
delay: Utils.fixedInt(1000),
|
|
|
|
repeat: -1,
|
|
|
|
callback: () => {
|
|
|
|
if (this.gameData)
|
|
|
|
this.gameData.gameStats.playTime++;
|
|
|
|
if (this.sessionPlayTime !== null)
|
|
|
|
this.sessionPlayTime++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.updateWaveCountText();
|
|
|
|
this.updateMoneyText();
|
2024-03-19 04:03:41 +00:00
|
|
|
this.updateScoreText();
|
2024-01-12 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2024-04-19 03:52:26 +01:00
|
|
|
async initExpSprites(): Promise<void> {
|
|
|
|
if (expSpriteKeys.length)
|
|
|
|
return;
|
|
|
|
fetch('./exp-sprites.json').then(res => res.json()).then(keys => {
|
|
|
|
if (Array.isArray(keys))
|
|
|
|
expSpriteKeys.push(...keys);
|
|
|
|
Promise.resolve();
|
2024-04-13 23:59:58 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initStarterColors(): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (starterColors)
|
|
|
|
return resolve();
|
|
|
|
|
|
|
|
fetch('./starter-colors.json').then(res => res.json()).then(sc => {
|
|
|
|
starterColors = {};
|
|
|
|
Object.keys(sc).forEach(key => {
|
|
|
|
starterColors[key] = sc[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
/*const loadPokemonAssets: Promise<void>[] = [];
|
|
|
|
|
|
|
|
for (let s of Object.keys(speciesStarters)) {
|
|
|
|
const species = getPokemonSpecies(parseInt(s));
|
|
|
|
loadPokemonAssets.push(species.loadAssets(this, false, 0, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all(loadPokemonAssets).then(() => {
|
|
|
|
const starterCandyColors = {};
|
|
|
|
const rgbaToHexFunc = (r, g, b) => [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
|
|
|
|
|
|
for (let s of Object.keys(speciesStarters)) {
|
|
|
|
const species = getPokemonSpecies(parseInt(s));
|
|
|
|
|
|
|
|
starterCandyColors[species.speciesId] = species.generateCandyColors(this).map(c => rgbaToHexFunc(c[0], c[1], c[2]));
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(JSON.stringify(starterCandyColors));
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});*/
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
2024-02-25 02:16:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-19 03:52:26 +01:00
|
|
|
hasExpSprite(key: string): boolean {
|
|
|
|
const keyMatch = /^pkmn__?(back__)?(shiny__)?(female__)?(\d+)(\-.*?)?(?:_[1-3])?$/g.exec(key);
|
2024-04-19 06:25:19 +01:00
|
|
|
let k = keyMatch[4];
|
|
|
|
if (keyMatch[2])
|
|
|
|
k += 's';
|
|
|
|
if (keyMatch[1])
|
|
|
|
k += 'b';
|
|
|
|
if (keyMatch[3])
|
|
|
|
k += 'f';
|
|
|
|
if (keyMatch[5])
|
|
|
|
k += keyMatch[5];
|
|
|
|
if (!expSpriteKeys.includes(k))
|
|
|
|
return false;
|
|
|
|
return true;
|
2024-04-19 03:52:26 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
setupControls() {
|
|
|
|
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
|
|
|
|
const keyConfig = {
|
|
|
|
[Button.UP]: [keyCodes.UP, keyCodes.W],
|
|
|
|
[Button.DOWN]: [keyCodes.DOWN, keyCodes.S],
|
|
|
|
[Button.LEFT]: [keyCodes.LEFT, keyCodes.A],
|
|
|
|
[Button.RIGHT]: [keyCodes.RIGHT, keyCodes.D],
|
2023-12-30 23:41:25 +00:00
|
|
|
[Button.SUBMIT]: [keyCodes.ENTER],
|
2024-01-02 22:31:44 +00:00
|
|
|
[Button.ACTION]: [keyCodes.SPACE, keyCodes.ENTER, keyCodes.Z],
|
2023-10-26 21:33:59 +01:00
|
|
|
[Button.CANCEL]: [keyCodes.BACKSPACE, keyCodes.X],
|
|
|
|
[Button.MENU]: [keyCodes.ESC, keyCodes.M],
|
2023-04-18 03:44:41 +01:00
|
|
|
[Button.CYCLE_SHINY]: [keyCodes.R],
|
|
|
|
[Button.CYCLE_FORM]: [keyCodes.F],
|
|
|
|
[Button.CYCLE_GENDER]: [keyCodes.G],
|
2023-04-26 17:50:21 +01:00
|
|
|
[Button.CYCLE_ABILITY]: [keyCodes.E],
|
2024-01-06 03:24:05 +00:00
|
|
|
[Button.CYCLE_NATURE]: [keyCodes.N],
|
2024-04-19 03:52:26 +01:00
|
|
|
[Button.CYCLE_VARIANT]: [keyCodes.V],
|
2023-04-11 05:24:55 +01:00
|
|
|
[Button.SPEED_UP]: [keyCodes.PLUS],
|
|
|
|
[Button.SLOW_DOWN]: [keyCodes.MINUS]
|
|
|
|
};
|
2023-12-25 20:03:50 +00:00
|
|
|
const mobileKeyConfig = {};
|
2023-04-11 05:24:55 +01:00
|
|
|
this.buttonKeys = [];
|
|
|
|
for (let b of Utils.getEnumValues(Button)) {
|
|
|
|
const keys: Phaser.Input.Keyboard.Key[] = [];
|
|
|
|
if (keyConfig.hasOwnProperty(b)) {
|
|
|
|
for (let k of keyConfig[b])
|
2023-12-30 23:41:25 +00:00
|
|
|
keys.push(this.input.keyboard.addKey(k, false));
|
2023-12-25 20:03:50 +00:00
|
|
|
mobileKeyConfig[Button[b]] = keys[0];
|
2023-04-11 05:24:55 +01:00
|
|
|
}
|
|
|
|
this.buttonKeys[b] = keys;
|
|
|
|
}
|
2023-12-25 20:03:50 +00:00
|
|
|
|
|
|
|
initTouchControls(mobileKeyConfig);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getParty(): PlayerPokemon[] {
|
|
|
|
return this.party;
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
getPlayerPokemon(): PlayerPokemon {
|
|
|
|
return this.getPlayerField().find(p => p.isActive());
|
2023-04-21 00:44:56 +01:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
getPlayerField(): PlayerPokemon[] {
|
|
|
|
const party = this.getParty();
|
|
|
|
return party.slice(0, Math.min(party.length, this.currentBattle?.double ? 2 : 1));
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-07 21:08:33 +01:00
|
|
|
getEnemyParty(): EnemyPokemon[] {
|
|
|
|
return this.currentBattle?.enemyParty || [];
|
|
|
|
}
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
getEnemyPokemon(): EnemyPokemon {
|
2023-05-18 16:11:06 +01:00
|
|
|
return this.getEnemyField().find(p => p.isActive());
|
|
|
|
}
|
|
|
|
|
|
|
|
getEnemyField(): EnemyPokemon[] {
|
2023-10-07 21:08:33 +01:00
|
|
|
const party = this.getEnemyParty();
|
|
|
|
return party.slice(0, Math.min(party.length, this.currentBattle?.double ? 2 : 1));
|
2023-05-18 16:11:06 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 00:55:41 +00:00
|
|
|
getField(activeOnly: boolean = false): Pokemon[] {
|
2023-05-18 16:11:06 +01:00
|
|
|
const ret = new Array(4).fill(null);
|
|
|
|
const playerField = this.getPlayerField();
|
|
|
|
const enemyField = this.getEnemyField();
|
|
|
|
ret.splice(0, playerField.length, ...playerField);
|
|
|
|
ret.splice(2, enemyField.length, ...enemyField);
|
2024-03-12 00:55:41 +00:00
|
|
|
return activeOnly
|
|
|
|
? ret.filter(p => p?.isActive())
|
|
|
|
: ret;
|
2023-04-22 03:59:09 +01:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:14:53 +01:00
|
|
|
getPokemonById(pokemonId: integer): Pokemon {
|
|
|
|
const findInParty = (party: Pokemon[]) => party.find(p => p.id === pokemonId);
|
2023-10-24 15:05:07 +01:00
|
|
|
return findInParty(this.getParty()) || findInParty(this.getEnemyParty());
|
2023-04-23 03:14:53 +01:00
|
|
|
}
|
|
|
|
|
2024-04-19 03:52:26 +01:00
|
|
|
addPlayerPokemon(species: PokemonSpecies, level: integer, abilityIndex: integer, formIndex: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData, postProcess?: (playerPokemon: PlayerPokemon) => void): PlayerPokemon {
|
|
|
|
const pokemon = new PlayerPokemon(this, species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource);
|
2024-01-08 04:17:24 +00:00
|
|
|
if (postProcess)
|
|
|
|
postProcess(pokemon);
|
|
|
|
pokemon.init();
|
|
|
|
return pokemon;
|
|
|
|
}
|
|
|
|
|
2024-03-21 04:57:28 +00:00
|
|
|
addEnemyPokemon(species: PokemonSpecies, level: integer, trainerSlot: TrainerSlot, boss: boolean = false, dataSource?: PokemonData, postProcess?: (enemyPokemon: EnemyPokemon) => void): EnemyPokemon {
|
2024-04-02 02:02:48 +01:00
|
|
|
if (OPP_SPECIES_OVERRIDE)
|
|
|
|
species = getPokemonSpecies(OPP_SPECIES_OVERRIDE);
|
2024-03-21 04:57:28 +00:00
|
|
|
const pokemon = new EnemyPokemon(this, species, level, trainerSlot, boss, dataSource);
|
2024-03-29 04:03:54 +00:00
|
|
|
if (boss) {
|
|
|
|
const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967295));
|
|
|
|
|
|
|
|
for (let s = 0; s < pokemon.ivs.length; s++)
|
|
|
|
pokemon.ivs[s] = Math.round(Phaser.Math.Linear(Math.min(pokemon.ivs[s], secondaryIvs[s]), Math.max(pokemon.ivs[s], secondaryIvs[s]), 0.75));
|
|
|
|
}
|
2024-01-08 04:17:24 +00:00
|
|
|
if (postProcess)
|
|
|
|
postProcess(pokemon);
|
|
|
|
pokemon.init();
|
|
|
|
return pokemon;
|
|
|
|
}
|
|
|
|
|
2024-04-10 15:57:06 +01:00
|
|
|
addPokemonIcon(pokemon: Pokemon, x: number, y: number, originX: number = 0.5, originY: number = 0.5, ignoreOverride: boolean = false): Phaser.GameObjects.Container {
|
|
|
|
const container = this.add.container(x, y);
|
|
|
|
|
|
|
|
const icon = this.add.sprite(0, 0, pokemon.getIconAtlasKey(ignoreOverride));
|
|
|
|
icon.setFrame(pokemon.getIconId(true));
|
|
|
|
icon.setOrigin(0.5, 0);
|
|
|
|
|
|
|
|
container.add(icon);
|
|
|
|
|
|
|
|
if (pokemon.isFusion()) {
|
|
|
|
const fusionIcon = this.add.sprite(0, 0, pokemon.getFusionIconAtlasKey(ignoreOverride));
|
|
|
|
fusionIcon.setOrigin(0.5, 0)
|
|
|
|
fusionIcon.setFrame(pokemon.getFusionIconId(true));
|
|
|
|
|
|
|
|
const originalWidth = icon.width;
|
|
|
|
const originalHeight = icon.height;
|
|
|
|
const originalFrame = icon.frame;
|
|
|
|
|
|
|
|
const iconHeight = (icon.frame.cutHeight <= fusionIcon.frame.cutHeight ? Math.ceil : Math.floor)((icon.frame.cutHeight + fusionIcon.frame.cutHeight) / 4);
|
|
|
|
|
2024-04-10 18:30:04 +01:00
|
|
|
// Inefficient, but for some reason didn't work with only the unique properties as part of the name
|
|
|
|
const iconFrameId = `${icon.frame.name}f${fusionIcon.frame.name}`;
|
2024-04-10 15:57:06 +01:00
|
|
|
|
|
|
|
if (!icon.frame.texture.has(iconFrameId))
|
|
|
|
icon.frame.texture.add(iconFrameId, icon.frame.sourceIndex, icon.frame.cutX, icon.frame.cutY, icon.frame.cutWidth, iconHeight);
|
|
|
|
|
|
|
|
icon.setFrame(iconFrameId);
|
|
|
|
|
|
|
|
fusionIcon.y = icon.frame.cutHeight;
|
|
|
|
|
|
|
|
const originalFusionFrame = fusionIcon.frame;
|
|
|
|
|
|
|
|
const fusionIconY = fusionIcon.frame.cutY + icon.frame.cutHeight;
|
|
|
|
const fusionIconHeight = fusionIcon.frame.cutHeight - icon.frame.cutHeight;
|
2024-04-10 18:30:04 +01:00
|
|
|
|
|
|
|
// Inefficient, but for some reason didn't work with only the unique properties as part of the name
|
|
|
|
const fusionIconFrameId = `${fusionIcon.frame.name}f${icon.frame.name}`;
|
2024-04-10 15:57:06 +01:00
|
|
|
|
|
|
|
if (!fusionIcon.frame.texture.has(fusionIconFrameId))
|
|
|
|
fusionIcon.frame.texture.add(fusionIconFrameId, fusionIcon.frame.sourceIndex, fusionIcon.frame.cutX, fusionIconY, fusionIcon.frame.cutWidth, fusionIconHeight);
|
|
|
|
fusionIcon.setFrame(fusionIconFrameId);
|
|
|
|
|
|
|
|
const frameY = (originalFrame.y + originalFusionFrame.y) / 2;
|
|
|
|
icon.frame.y = fusionIcon.frame.y = frameY;
|
|
|
|
|
|
|
|
container.add(fusionIcon);
|
|
|
|
|
|
|
|
if (originX !== 0.5)
|
|
|
|
container.x -= originalWidth * (originX - 0.5);
|
|
|
|
if (originY !== 0)
|
|
|
|
container.y -= (originalHeight) * originY;
|
|
|
|
} else {
|
|
|
|
if (originX !== 0.5)
|
|
|
|
container.x -= icon.width * (originX - 0.5);
|
|
|
|
if (originY !== 0)
|
|
|
|
container.y -= icon.height * originY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2024-03-16 01:59:34 +00:00
|
|
|
setSeed(seed: string): void {
|
|
|
|
this.seed = seed;
|
2024-04-01 17:48:35 +01:00
|
|
|
this.rngCounter = 0;
|
2024-03-25 15:00:42 +00:00
|
|
|
this.waveCycleOffset = this.getGeneratedWaveCycleOffset();
|
|
|
|
this.offsetGym = this.gameMode.isClassic && this.getGeneratedOffsetGym();
|
2024-03-16 01:59:34 +00:00
|
|
|
}
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
randBattleSeedInt(range: integer, min: integer = 0): integer {
|
|
|
|
return this.currentBattle.randSeedInt(this, range, min);
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:48:34 +01:00
|
|
|
reset(clearScene: boolean = false, clearData: boolean = false): void {
|
|
|
|
if (clearData)
|
|
|
|
this.gameData = new GameData(this);
|
|
|
|
|
2024-03-25 15:00:42 +00:00
|
|
|
this.gameMode = gameModes[GameModes.CLASSIC];
|
|
|
|
|
2024-03-30 00:11:52 +00:00
|
|
|
this.setSeed(SEED_OVERRIDE || Utils.randomString(24));
|
2023-10-20 03:19:14 +01:00
|
|
|
console.log('Seed:', this.seed);
|
|
|
|
|
2024-04-17 20:56:29 +01:00
|
|
|
this.disableMenu = false;
|
|
|
|
|
2024-03-17 15:36:19 +00:00
|
|
|
this.score = 0;
|
2024-03-16 01:59:34 +00:00
|
|
|
this.money = 0;
|
2023-10-22 01:23:43 +01:00
|
|
|
|
2024-04-05 15:14:49 +01:00
|
|
|
this.lockModifierTiers = false;
|
|
|
|
|
2023-04-22 03:59:09 +01:00
|
|
|
this.pokeballCounts = Object.fromEntries(Utils.getEnumValues(PokeballType).filter(p => p <= PokeballType.MASTER_BALL).map(t => [ t, 0 ]));
|
2023-04-25 03:32:12 +01:00
|
|
|
this.pokeballCounts[PokeballType.POKEBALL] += 5;
|
2023-04-22 03:59:09 +01:00
|
|
|
|
|
|
|
this.modifiers = [];
|
|
|
|
this.enemyModifiers = [];
|
|
|
|
this.modifierBar.removeAll(true);
|
|
|
|
this.enemyModifierBar.removeAll(true);
|
|
|
|
|
|
|
|
for (let p of this.getParty())
|
|
|
|
p.destroy();
|
|
|
|
this.party = [];
|
2023-10-24 15:05:07 +01:00
|
|
|
for (let p of this.getEnemyParty())
|
2023-04-22 03:59:09 +01:00
|
|
|
p.destroy();
|
|
|
|
|
|
|
|
this.currentBattle = null;
|
2024-03-16 01:59:34 +00:00
|
|
|
|
2023-04-22 03:59:09 +01:00
|
|
|
this.waveCountText.setText(startingWave.toString());
|
2023-04-28 20:03:42 +01:00
|
|
|
this.waveCountText.setVisible(false);
|
2023-04-22 03:59:09 +01:00
|
|
|
|
2023-10-22 01:23:43 +01:00
|
|
|
this.updateMoneyText();
|
|
|
|
this.moneyText.setVisible(false);
|
|
|
|
|
2024-03-22 13:16:49 +00:00
|
|
|
this.updateScoreText();
|
|
|
|
this.scoreText.setVisible(false);
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
this.newArena(STARTING_BIOME_OVERRIDE || Biome.TOWN);
|
2023-04-22 03:59:09 +01:00
|
|
|
|
|
|
|
this.arenaBgTransition.setPosition(0, 0);
|
2023-04-30 04:29:02 +01:00
|
|
|
this.arenaPlayer.setPosition(300, 0);
|
2023-04-30 16:38:46 +01:00
|
|
|
this.arenaPlayerTransition.setPosition(0, 0);
|
2023-05-09 17:43:28 +01:00
|
|
|
[ this.arenaEnemy, this.arenaNextEnemy ].forEach(a => a.setPosition(-280, 0));
|
2024-01-15 01:47:08 +00:00
|
|
|
this.arenaNextEnemy.setVisible(false);
|
2023-04-22 03:59:09 +01:00
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
this.arena.init();
|
|
|
|
|
2024-02-06 21:15:35 +00:00
|
|
|
this.trainer.setTexture(`trainer_${this.gameData.gender === PlayerGender.FEMALE ? 'f' : 'm'}_back`);
|
2024-02-06 04:05:56 +00:00
|
|
|
this.trainer.setPosition(406, 186);
|
2024-02-23 00:24:00 +00:00
|
|
|
this.trainer.setVisible(true)
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
if (clearScene) {
|
|
|
|
this.fadeOutBgm(250, false);
|
|
|
|
this.tweens.add({
|
|
|
|
targets: [ this.uiContainer ],
|
|
|
|
alpha: 0,
|
|
|
|
duration: 250,
|
|
|
|
ease: 'Sine.easeInOut',
|
|
|
|
onComplete: () => {
|
|
|
|
this.clearPhaseQueue();
|
|
|
|
|
|
|
|
this.children.removeAll(true);
|
|
|
|
this.game.domContainer.innerHTML = '';
|
|
|
|
this.launchBattle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-07 21:08:33 +01:00
|
|
|
newBattle(waveIndex?: integer, battleType?: BattleType, trainerData?: TrainerData, double?: boolean): Battle {
|
2023-05-18 16:11:06 +01:00
|
|
|
let newWaveIndex = waveIndex || ((this.currentBattle?.waveIndex || (startingWave - 1)) + 1);
|
|
|
|
let newDouble: boolean;
|
2023-10-07 21:08:33 +01:00
|
|
|
let newBattleType: BattleType;
|
|
|
|
let newTrainer: Trainer;
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
let battleConfig: FixedBattleConfig = null;
|
2023-10-07 21:08:33 +01:00
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
this.resetSeed(newWaveIndex);
|
2024-03-21 04:57:28 +00:00
|
|
|
|
|
|
|
const playerField = this.getPlayerField();
|
2023-10-18 23:01:15 +01:00
|
|
|
|
2024-03-14 20:26:57 +00:00
|
|
|
if (this.gameMode.hasFixedBattles && fixedBattles.hasOwnProperty(newWaveIndex) && trainerData === undefined) {
|
2023-10-18 23:01:15 +01:00
|
|
|
battleConfig = fixedBattles[newWaveIndex];
|
|
|
|
newDouble = battleConfig.double;
|
|
|
|
newBattleType = battleConfig.battleType;
|
2024-01-05 00:37:07 +00:00
|
|
|
this.executeWithSeedOffset(() => newTrainer = battleConfig.getTrainer(this), (battleConfig.seedOffsetWaveIndex || newWaveIndex) << 8);
|
2023-10-18 23:01:15 +01:00
|
|
|
if (newTrainer)
|
|
|
|
this.field.add(newTrainer);
|
|
|
|
} else {
|
2024-03-14 20:26:57 +00:00
|
|
|
if (!this.gameMode.hasTrainers)
|
2023-10-24 15:05:07 +01:00
|
|
|
newBattleType = BattleType.WILD;
|
2024-03-17 02:06:56 +00:00
|
|
|
else if (battleType === undefined)
|
|
|
|
newBattleType = this.gameMode.isWaveTrainer(newWaveIndex, this.arena) ? BattleType.TRAINER : BattleType.WILD;
|
|
|
|
else
|
2023-10-18 23:01:15 +01:00
|
|
|
newBattleType = battleType;
|
|
|
|
|
|
|
|
if (newBattleType === BattleType.TRAINER) {
|
2024-03-21 04:57:28 +00:00
|
|
|
const trainerType = this.arena.randomTrainerType(newWaveIndex);
|
|
|
|
let doubleTrainer = false;
|
|
|
|
if (trainerConfigs[trainerType].doubleOnly)
|
|
|
|
doubleTrainer = true;
|
|
|
|
else if (trainerConfigs[trainerType].hasDouble) {
|
|
|
|
const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8);
|
|
|
|
this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance);
|
|
|
|
playerField.forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, doubleChance));
|
|
|
|
doubleTrainer = !Utils.randSeedInt(doubleChance.value);
|
|
|
|
}
|
|
|
|
newTrainer = trainerData !== undefined ? trainerData.toTrainer(this) : new Trainer(this, trainerType, doubleTrainer ? TrainerVariant.DOUBLE : Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT);
|
2023-10-18 23:01:15 +01:00
|
|
|
this.field.add(newTrainer);
|
|
|
|
}
|
2023-10-07 21:08:33 +01:00
|
|
|
}
|
2023-05-18 16:11:06 +01:00
|
|
|
|
2023-07-05 01:07:05 +01:00
|
|
|
if (double === undefined && newWaveIndex > 1) {
|
2024-03-14 20:26:57 +00:00
|
|
|
if (newBattleType === BattleType.WILD && !this.gameMode.isWaveFinal(newWaveIndex)) {
|
2023-10-07 21:08:33 +01:00
|
|
|
const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8);
|
|
|
|
this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance);
|
2023-10-18 23:01:15 +01:00
|
|
|
playerField.forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, doubleChance));
|
|
|
|
newDouble = !Utils.randSeedInt(doubleChance.value);
|
2023-10-10 01:20:02 +01:00
|
|
|
} else if (newBattleType === BattleType.TRAINER)
|
2024-03-21 04:57:28 +00:00
|
|
|
newDouble = newTrainer.variant === TrainerVariant.DOUBLE;
|
2023-10-18 23:01:15 +01:00
|
|
|
} else if (!battleConfig)
|
2023-07-05 01:07:05 +01:00
|
|
|
newDouble = !!double;
|
2023-05-18 16:11:06 +01:00
|
|
|
|
|
|
|
const lastBattle = this.currentBattle;
|
|
|
|
|
2024-04-06 06:36:20 +01:00
|
|
|
if (lastBattle?.double && !newDouble)
|
|
|
|
this.tryRemovePhase(p => p instanceof SwitchPhase);
|
|
|
|
|
2023-10-03 17:50:31 +01:00
|
|
|
const maxExpLevel = this.getMaxExpLevel();
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
this.lastEnemyTrainer = lastBattle?.trainer ?? null;
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
this.executeWithSeedOffset(() => {
|
|
|
|
this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble);
|
|
|
|
}, newWaveIndex << 3, this.waveSeed);
|
2023-05-18 16:11:06 +01:00
|
|
|
this.currentBattle.incrementTurn(this);
|
|
|
|
|
2024-02-22 23:03:36 +00:00
|
|
|
//this.pushPhase(new TrainerMessageTestPhase(this, TrainerType.RIVAL, TrainerType.RIVAL_2, TrainerType.RIVAL_3, TrainerType.RIVAL_4, TrainerType.RIVAL_5, TrainerType.RIVAL_6));
|
2023-12-20 05:35:41 +00:00
|
|
|
|
2023-12-30 02:04:40 +00:00
|
|
|
if (!waveIndex && lastBattle) {
|
2024-03-17 02:06:56 +00:00
|
|
|
const isNewBiome = !(lastBattle.waveIndex % 10) || (this.gameMode.isDaily && lastBattle.waveIndex === 49);
|
2024-01-15 01:47:08 +00:00
|
|
|
const resetArenaState = isNewBiome || this.currentBattle.battleType === BattleType.TRAINER || this.currentBattle.battleSpec === BattleSpec.FINAL_BOSS;
|
2023-12-30 02:04:40 +00:00
|
|
|
this.getEnemyParty().forEach(enemyPokemon => enemyPokemon.destroy());
|
|
|
|
this.trySpreadPokerus();
|
2023-12-30 05:00:27 +00:00
|
|
|
if (!isNewBiome && (newWaveIndex % 10) == 5)
|
|
|
|
this.arena.updatePoolsForTimeOfDay();
|
2023-12-30 02:04:40 +00:00
|
|
|
if (resetArenaState) {
|
|
|
|
this.arena.removeAllTags();
|
|
|
|
playerField.forEach((_, p) => this.unshiftPhase(new ReturnPhase(this, p)));
|
|
|
|
this.unshiftPhase(new ShowTrainerPhase(this));
|
2024-01-10 04:34:43 +00:00
|
|
|
}
|
|
|
|
for (let pokemon of this.getParty()) {
|
|
|
|
if (pokemon) {
|
|
|
|
if (resetArenaState)
|
2023-12-30 02:04:40 +00:00
|
|
|
pokemon.resetBattleData();
|
2024-01-10 04:34:43 +00:00
|
|
|
this.triggerPokemonFormChange(pokemon, SpeciesFormChangeTimeOfDayTrigger);
|
2023-10-18 23:01:15 +01:00
|
|
|
}
|
2023-12-30 02:04:40 +00:00
|
|
|
}
|
2024-03-14 20:26:57 +00:00
|
|
|
if (!this.gameMode.hasRandomBiomes && !isNewBiome)
|
2023-12-30 02:04:40 +00:00
|
|
|
this.pushPhase(new NextEncounterPhase(this));
|
|
|
|
else {
|
|
|
|
this.pushPhase(new SelectBiomePhase(this));
|
|
|
|
this.pushPhase(new NewBiomeEncounterPhase(this));
|
|
|
|
|
|
|
|
const newMaxExpLevel = this.getMaxExpLevel();
|
|
|
|
if (newMaxExpLevel > maxExpLevel)
|
|
|
|
this.pushPhase(new LevelCapPhase(this));
|
|
|
|
}
|
2023-05-18 16:11:06 +01:00
|
|
|
}
|
2023-04-19 04:54:07 +01:00
|
|
|
|
2023-03-31 04:02:35 +01:00
|
|
|
return this.currentBattle;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-04-01 17:48:35 +01:00
|
|
|
newArena(biome: Biome): Arena {
|
2023-04-17 05:46:50 +01:00
|
|
|
this.arena = new Arena(this, biome, Biome[biome].toLowerCase());
|
2023-04-28 20:03:42 +01:00
|
|
|
|
2024-03-31 17:00:54 +01:00
|
|
|
this.arenaBg.pipelineData = { terrainColorRatio: this.arena.getBgTerrainColorRatioForBiome() };
|
|
|
|
|
2023-03-31 21:04:39 +01:00
|
|
|
return this.arena;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-02-15 04:25:12 +00:00
|
|
|
updateFieldScale(): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
2024-03-12 00:55:41 +00:00
|
|
|
const fieldScale = Math.floor(Math.pow(1 / this.getField(true)
|
2024-02-15 04:25:12 +00:00
|
|
|
.map(p => p.getSpriteScale())
|
|
|
|
.reduce((highestScale: number, scale: number) => highestScale = Math.max(scale, highestScale), 0), 0.7) * 40
|
|
|
|
) / 40;
|
|
|
|
this.setFieldScale(fieldScale).then(() => resolve());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-15 01:47:08 +00:00
|
|
|
setFieldScale(scale: number, instant: boolean = false): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
scale *= 6;
|
|
|
|
if (this.field.scale === scale)
|
|
|
|
return resolve();
|
|
|
|
|
|
|
|
const defaultWidth = this.arenaBg.width * 6;
|
2024-03-24 21:32:44 +00:00
|
|
|
const defaultHeight = 132 * 6;
|
2024-01-15 01:47:08 +00:00
|
|
|
const scaledWidth = this.arenaBg.width * scale;
|
2024-03-24 21:32:44 +00:00
|
|
|
const scaledHeight = 132 * scale;
|
2024-01-15 01:47:08 +00:00
|
|
|
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.field,
|
|
|
|
scale: scale,
|
|
|
|
x: (defaultWidth - scaledWidth) / 2,
|
|
|
|
y: defaultHeight - scaledHeight,
|
|
|
|
duration: !instant ? Utils.fixedInt(Math.abs(this.field.scale - scale) * 200) : 0,
|
|
|
|
ease: 'Sine.easeInOut',
|
|
|
|
onComplete: () => resolve()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-10 04:34:43 +00:00
|
|
|
getSpeciesFormIndex(species: PokemonSpecies, gender?: Gender, nature?: Nature, ignoreArena?: boolean): integer {
|
2023-10-30 18:57:23 +00:00
|
|
|
if (!species.forms?.length)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (species.speciesId) {
|
|
|
|
case Species.UNOWN:
|
2024-03-04 07:46:36 +00:00
|
|
|
case Species.SHELLOS:
|
|
|
|
case Species.GASTRODON:
|
2024-03-28 22:04:29 +00:00
|
|
|
case Species.BASCULIN:
|
2023-10-30 18:57:23 +00:00
|
|
|
case Species.DEERLING:
|
|
|
|
case Species.SAWSBUCK:
|
2024-04-04 16:22:15 +01:00
|
|
|
case Species.VIVILLON:
|
2023-12-12 20:32:50 +00:00
|
|
|
case Species.ORICORIO:
|
2024-02-06 04:46:45 +00:00
|
|
|
case Species.SQUAWKABILLY:
|
|
|
|
case Species.TATSUGIRI:
|
2024-02-06 05:10:49 +00:00
|
|
|
case Species.PALDEA_TAUROS:
|
2023-10-30 18:57:23 +00:00
|
|
|
return Utils.randSeedInt(species.forms.length);
|
2024-04-15 02:30:54 +01:00
|
|
|
case Species.MINIOR:
|
|
|
|
return Utils.randSeedInt(6);
|
2023-12-26 06:29:05 +00:00
|
|
|
case Species.MEOWSTIC:
|
|
|
|
case Species.INDEEDEE:
|
2024-03-28 22:04:29 +00:00
|
|
|
case Species.BASCULEGION:
|
2024-02-06 04:46:45 +00:00
|
|
|
case Species.OINKOLOGNE:
|
2023-12-26 06:29:05 +00:00
|
|
|
return gender === Gender.FEMALE ? 1 : 0;
|
2024-01-10 04:34:43 +00:00
|
|
|
case Species.TOXTRICITY:
|
|
|
|
const lowkeyNatures = [ Nature.LONELY, Nature.BOLD, Nature.RELAXED, Nature.TIMID, Nature.SERIOUS, Nature.MODEST, Nature.MILD, Nature.QUIET, Nature.BASHFUL, Nature.CALM, Nature.GENTLE, Nature.CAREFUL ];
|
|
|
|
if (nature !== undefined && lowkeyNatures.indexOf(nature) > -1)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2023-10-30 18:57:23 +00:00
|
|
|
}
|
|
|
|
|
2023-12-26 06:29:05 +00:00
|
|
|
if (ignoreArena) {
|
|
|
|
switch (species.speciesId) {
|
|
|
|
case Species.BURMY:
|
|
|
|
case Species.WORMADAM:
|
2024-03-31 20:03:02 +01:00
|
|
|
case Species.ROTOM:
|
2023-12-26 06:29:05 +00:00
|
|
|
case Species.LYCANROC:
|
|
|
|
return Utils.randSeedInt(species.forms.length);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.arena.getSpeciesFormIndex(species);
|
2023-10-30 18:57:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 15:00:42 +00:00
|
|
|
private getGeneratedOffsetGym(): boolean {
|
|
|
|
let ret = false;
|
|
|
|
this.executeWithSeedOffset(() => {
|
|
|
|
ret = !Utils.randSeedInt(2);
|
|
|
|
}, 0, this.seed.toString());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getGeneratedWaveCycleOffset(): integer {
|
2023-12-30 02:04:40 +00:00
|
|
|
let ret = 0;
|
|
|
|
this.executeWithSeedOffset(() => {
|
|
|
|
ret = Utils.randSeedInt(8) * 5;
|
|
|
|
}, 0, this.seed.toString());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-08 04:17:24 +00:00
|
|
|
getEncounterBossSegments(waveIndex: integer, level: integer, species?: PokemonSpecies, forceBoss: boolean = false): integer {
|
2024-03-17 02:06:56 +00:00
|
|
|
if (this.gameMode.isDaily && this.gameMode.isWaveFinal(waveIndex))
|
|
|
|
return 5;
|
|
|
|
|
2024-01-08 04:17:24 +00:00
|
|
|
let isBoss: boolean;
|
|
|
|
if (forceBoss || (species && (species.pseudoLegendary || species.legendary || species.mythical)))
|
|
|
|
isBoss = true;
|
|
|
|
else {
|
|
|
|
this.executeWithSeedOffset(() => {
|
2024-03-14 20:26:57 +00:00
|
|
|
isBoss = waveIndex % 10 === 0 || (this.gameMode.hasRandomBosses && Utils.randSeedInt(100) < Math.min(Math.max(Math.ceil((waveIndex - 250) / 50), 0) * 2, 30));
|
2024-01-08 04:17:24 +00:00
|
|
|
}, waveIndex << 2);
|
|
|
|
}
|
|
|
|
if (!isBoss)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
let ret: integer = 2;
|
|
|
|
|
|
|
|
if (level >= 100)
|
|
|
|
ret++;
|
|
|
|
if (species) {
|
|
|
|
if (species.baseTotal >= 670)
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
ret += Math.floor(waveIndex / 250);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-25 19:15:44 +01:00
|
|
|
trySpreadPokerus(): void {
|
|
|
|
const party = this.getParty();
|
|
|
|
const infectedIndexes: integer[] = [];
|
2024-04-04 03:52:39 +01:00
|
|
|
const spread = (index: number, spreadTo: number) => {
|
|
|
|
const partyMember = party[index + spreadTo];
|
|
|
|
if (!partyMember.pokerus && !Utils.randSeedInt(10)) {
|
|
|
|
partyMember.pokerus = true;
|
|
|
|
infectedIndexes.push(index + spreadTo);
|
|
|
|
}
|
|
|
|
};
|
2023-10-25 19:15:44 +01:00
|
|
|
party.forEach((pokemon, p) => {
|
|
|
|
if (!pokemon.pokerus || infectedIndexes.indexOf(p) > -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.executeWithSeedOffset(() => {
|
2024-04-04 03:52:39 +01:00
|
|
|
if (p)
|
|
|
|
spread(p, -1);
|
|
|
|
if (p < party.length - 1)
|
|
|
|
spread(p, 1);
|
2023-10-25 19:15:44 +01:00
|
|
|
}, this.currentBattle.waveIndex + (p << 8));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
resetSeed(waveIndex?: integer): void {
|
2024-04-01 17:48:35 +01:00
|
|
|
const wave = waveIndex || this.currentBattle?.waveIndex || 0;
|
|
|
|
this.waveSeed = Utils.shiftCharCodes(this.seed, wave);
|
2023-10-18 23:01:15 +01:00
|
|
|
Phaser.Math.RND.sow([ this.waveSeed ]);
|
2024-04-01 17:48:35 +01:00
|
|
|
console.log('Wave Seed:', this.waveSeed, wave);
|
|
|
|
this.rngCounter = 0;
|
2023-10-18 23:01:15 +01:00
|
|
|
}
|
|
|
|
|
2023-10-25 19:15:44 +01:00
|
|
|
executeWithSeedOffset(func: Function, offset: integer, seedOverride?: string): void {
|
2023-10-18 23:01:15 +01:00
|
|
|
if (!func)
|
|
|
|
return;
|
2024-04-01 17:48:35 +01:00
|
|
|
const tempRngCounter = this.rngCounter;
|
|
|
|
const tempRngOffset = this.rngOffset;
|
|
|
|
const tempRngSeedOverride = this.rngSeedOverride;
|
2023-10-18 23:01:15 +01:00
|
|
|
const state = Phaser.Math.RND.state();
|
2023-10-25 19:15:44 +01:00
|
|
|
Phaser.Math.RND.sow([ Utils.shiftCharCodes(seedOverride || this.seed, offset) ]);
|
2024-04-01 17:48:35 +01:00
|
|
|
this.rngCounter = 0;
|
|
|
|
this.rngOffset = offset;
|
|
|
|
this.rngSeedOverride = seedOverride || '';
|
2023-10-18 23:01:15 +01:00
|
|
|
func();
|
|
|
|
Phaser.Math.RND.state(state);
|
2024-04-01 17:48:35 +01:00
|
|
|
this.rngCounter = tempRngCounter;
|
|
|
|
this.rngOffset = tempRngOffset;
|
|
|
|
this.rngSeedOverride = tempRngSeedOverride;
|
2023-10-18 23:01:15 +01:00
|
|
|
}
|
|
|
|
|
2024-03-10 02:57:33 +00:00
|
|
|
addFieldSprite(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, terrainColorRatio: number = 0): Phaser.GameObjects.Sprite {
|
2023-12-30 02:04:40 +00:00
|
|
|
const ret = this.add.sprite(x, y, texture, frame);
|
|
|
|
ret.setPipeline(this.fieldSpritePipeline);
|
2024-03-10 02:57:33 +00:00
|
|
|
if (terrainColorRatio)
|
|
|
|
ret.pipelineData['terrainColorRatio'] = terrainColorRatio;
|
2023-12-30 02:04:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
addPokemonSprite(pokemon: Pokemon, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, hasShadow: boolean = false, ignoreOverride: boolean = false): Phaser.GameObjects.Sprite {
|
|
|
|
const ret = this.addFieldSprite(x, y, texture, frame);
|
2024-02-19 03:21:57 +00:00
|
|
|
this.initPokemonSprite(ret, pokemon, hasShadow, ignoreOverride);
|
2024-02-17 05:40:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
initPokemonSprite(sprite: Phaser.GameObjects.Sprite, pokemon?: Pokemon, hasShadow: boolean = false, ignoreOverride: boolean = false): Phaser.GameObjects.Sprite {
|
|
|
|
sprite.setPipeline(this.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: hasShadow, ignoreOverride: ignoreOverride, teraColor: pokemon ? getTypeRgb(pokemon.getTeraType()) : undefined });
|
|
|
|
this.spriteSparkleHandler.add(sprite);
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2023-11-10 20:51:34 +00:00
|
|
|
showFieldOverlay(duration: integer): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.fieldOverlay,
|
|
|
|
alpha: 0.5,
|
|
|
|
ease: 'Sine.easeOut',
|
|
|
|
duration: duration,
|
|
|
|
onComplete: () => resolve()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
hideFieldOverlay(duration: integer): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.fieldOverlay,
|
|
|
|
alpha: 0,
|
|
|
|
duration: duration,
|
|
|
|
ease: 'Cubic.easeIn',
|
|
|
|
onComplete: () => resolve()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-21 00:44:56 +01:00
|
|
|
updateWaveCountText(): void {
|
2023-04-19 04:54:07 +01:00
|
|
|
const isBoss = !(this.currentBattle.waveIndex % 10);
|
|
|
|
this.waveCountText.setText(this.currentBattle.waveIndex.toString());
|
|
|
|
this.waveCountText.setColor(!isBoss ? '#404040' : '#f89890');
|
|
|
|
this.waveCountText.setShadowColor(!isBoss ? '#ded6b5' : '#984038');
|
2023-04-28 20:03:42 +01:00
|
|
|
this.waveCountText.setVisible(true);
|
2023-04-19 04:54:07 +01:00
|
|
|
}
|
|
|
|
|
2023-10-22 01:23:43 +01:00
|
|
|
updateMoneyText(): void {
|
|
|
|
this.moneyText.setText(`₽${this.money.toLocaleString('en-US')}`);
|
|
|
|
this.moneyText.setVisible(true);
|
|
|
|
}
|
|
|
|
|
2024-03-19 04:03:41 +00:00
|
|
|
updateScoreText(): void {
|
|
|
|
this.scoreText.setText(`Score: ${this.score.toString()}`);
|
|
|
|
this.scoreText.setVisible(this.gameMode.isDaily);
|
|
|
|
}
|
|
|
|
|
2023-10-04 22:24:28 +01:00
|
|
|
updateUIPositions(): void {
|
2023-11-26 15:00:58 +00:00
|
|
|
const enemyModifierCount = this.enemyModifiers.filter(m => m.isIconVisible(this)).length;
|
|
|
|
this.waveCountText.setY(-(this.game.canvas.height / 6) + (enemyModifierCount ? enemyModifierCount <= 12 ? 15 : 24 : 0));
|
2023-10-22 01:23:43 +01:00
|
|
|
this.moneyText.setY(this.waveCountText.y + 10);
|
2024-03-19 04:03:41 +00:00
|
|
|
this.scoreText.setY(this.moneyText.y + 10);
|
|
|
|
const offsetY = (this.scoreText.visible ? this.scoreText : this.moneyText).y + 15;
|
|
|
|
this.partyExpBar.setY(offsetY);
|
2024-04-13 23:59:58 +01:00
|
|
|
this.candyBar.setY(offsetY + 15);
|
2024-03-19 04:03:41 +00:00
|
|
|
this.ui?.achvBar.setY(this.game.canvas.height / 6 + offsetY);
|
2023-04-21 00:44:56 +01:00
|
|
|
}
|
|
|
|
|
2024-03-17 15:36:19 +00:00
|
|
|
addFaintedEnemyScore(enemy: EnemyPokemon): void {
|
|
|
|
let scoreIncrease = enemy.getSpeciesForm().getBaseExp() * (enemy.level / this.getMaxExpLevel()) * ((enemy.ivs.reduce((iv: integer, total: integer) => total += iv, 0) / 93) * 0.2 + 0.8);
|
|
|
|
this.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemy.id, false).map(m => scoreIncrease *= (m as PokemonHeldItemModifier).getScoreMultiplier());
|
|
|
|
if (enemy.isBoss())
|
|
|
|
scoreIncrease *= Math.sqrt(enemy.bossSegments);
|
|
|
|
this.currentBattle.battleScore += Math.ceil(scoreIncrease);
|
|
|
|
}
|
|
|
|
|
2024-02-29 21:41:14 +00:00
|
|
|
getMaxExpLevel(ignoreLevelCap?: boolean): integer {
|
|
|
|
if (ignoreLevelCap)
|
|
|
|
return Number.MAX_SAFE_INTEGER;
|
2024-03-27 01:40:10 +00:00
|
|
|
const waveIndex = Math.ceil((this.currentBattle?.waveIndex || 1) / 10) * 10;
|
|
|
|
const difficultyWaveIndex = this.gameMode.getWaveForDifficulty(waveIndex);
|
|
|
|
const baseLevel = (1 + difficultyWaveIndex / 2 + Math.pow(difficultyWaveIndex / 25, 2)) * 1.2;
|
2024-02-29 20:25:15 +00:00
|
|
|
return Math.ceil(baseLevel / 2) * 2 + 2;
|
2023-10-03 17:50:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-08 23:36:30 +00:00
|
|
|
randomSpecies(waveIndex: integer, level: integer, fromArenaPool?: boolean, speciesFilter?: PokemonSpeciesFilter, filterAllEvolutions?: boolean): PokemonSpecies {
|
2023-10-10 01:20:02 +01:00
|
|
|
if (fromArenaPool)
|
|
|
|
return this.arena.randomSpecies(waveIndex, level);
|
2023-12-21 06:24:24 +00:00
|
|
|
const filteredSpecies = speciesFilter ? [...new Set(allSpecies.filter(s => s.isCatchable()).filter(speciesFilter).map(s => {
|
2023-11-08 23:36:30 +00:00
|
|
|
if (!filterAllEvolutions) {
|
|
|
|
while (pokemonPrevolutions.hasOwnProperty(s.speciesId))
|
|
|
|
s = getPokemonSpecies(pokemonPrevolutions[s.speciesId]);
|
|
|
|
}
|
2023-10-10 01:20:02 +01:00
|
|
|
return s;
|
2023-12-21 06:24:24 +00:00
|
|
|
}))] : allSpecies.filter(s => s.isCatchable());
|
2023-12-31 04:31:26 +00:00
|
|
|
return filteredSpecies[Utils.randSeedInt(filteredSpecies.length)];
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-03-16 01:59:34 +00:00
|
|
|
generateRandomBiome(waveIndex: integer): Biome {
|
|
|
|
const relWave = waveIndex % 250;
|
|
|
|
const biomes = Utils.getEnumValues(Biome).slice(1, Utils.getEnumValues(Biome).filter(b => b >= 40).length * -1);
|
|
|
|
const maxDepth = biomeDepths[Biome.END][0] - 2;
|
|
|
|
const depthWeights = new Array(maxDepth + 1).fill(null)
|
|
|
|
.map((_, i: integer) => ((1 - Math.min(Math.abs((i / (maxDepth - 1)) - (relWave / 250)) + 0.25, 1)) / 0.75) * 250);
|
|
|
|
const biomeThresholds: integer[] = [];
|
|
|
|
let totalWeight = 0;
|
|
|
|
for (let biome of biomes) {
|
|
|
|
totalWeight += Math.ceil(depthWeights[biomeDepths[biome][0] - 1] / biomeDepths[biome][1]);
|
|
|
|
biomeThresholds.push(totalWeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
const randInt = Utils.randSeedInt(totalWeight);
|
|
|
|
|
|
|
|
for (let biome of biomes) {
|
|
|
|
if (randInt < biomeThresholds[biome])
|
|
|
|
return biome;
|
|
|
|
}
|
|
|
|
|
|
|
|
return biomes[Utils.randSeedInt(biomes.length)];
|
|
|
|
}
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
checkInput(): boolean {
|
2023-11-12 05:31:40 +00:00
|
|
|
let inputSuccess = false;
|
2023-12-25 20:48:16 +00:00
|
|
|
let vibrationLength = 0;
|
2024-04-09 07:45:48 +01:00
|
|
|
if (this.buttonJustPressed(Button.UP) || this.repeatInputDurationJustPassed(Button.UP)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.UP);
|
2023-12-25 20:48:16 +00:00
|
|
|
vibrationLength = 5;
|
2024-04-09 07:45:48 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.UP)
|
|
|
|
} else if (this.buttonJustPressed(Button.DOWN) || this.repeatInputDurationJustPassed(Button.DOWN)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.DOWN);
|
2023-12-25 20:48:16 +00:00
|
|
|
vibrationLength = 5;
|
2024-04-09 07:45:48 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.DOWN)
|
|
|
|
} else if (this.buttonJustPressed(Button.LEFT) || this.repeatInputDurationJustPassed(Button.LEFT)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.LEFT);
|
2023-12-25 20:48:16 +00:00
|
|
|
vibrationLength = 5;
|
2024-04-09 07:45:48 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.LEFT)
|
|
|
|
} else if (this.buttonJustPressed(Button.RIGHT) || this.repeatInputDurationJustPassed(Button.RIGHT)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.RIGHT);
|
2023-12-25 20:48:16 +00:00
|
|
|
vibrationLength = 5;
|
2024-04-09 07:45:48 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.RIGHT)
|
2024-04-09 14:14:11 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.SUBMIT) || this.repeatInputDurationJustPassed(Button.SUBMIT)) {
|
2023-12-30 23:41:25 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.SUBMIT) || this.ui.processInput(Button.ACTION);
|
2024-04-09 14:14:11 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.SUBMIT);
|
|
|
|
} else if (this.buttonJustPressed(Button.ACTION) || this.repeatInputDurationJustPassed(Button.ACTION)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.ACTION);
|
2024-04-09 14:14:11 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.ACTION);
|
|
|
|
} else if (this.buttonJustPressed(Button.CANCEL)|| this.repeatInputDurationJustPassed(Button.CANCEL)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CANCEL);
|
2024-04-09 14:14:11 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CANCEL);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.MENU)) {
|
2024-04-17 20:56:29 +01:00
|
|
|
if (this.disableMenu)
|
|
|
|
return;
|
2024-02-29 04:13:05 +00:00
|
|
|
switch (this.ui?.getMode()) {
|
2023-10-26 21:33:59 +01:00
|
|
|
case Mode.MESSAGE:
|
|
|
|
if (!(this.ui.getHandler() as MessageUiHandler).pendingPrompt)
|
|
|
|
return;
|
2024-03-21 18:15:39 +00:00
|
|
|
case Mode.TITLE:
|
2023-10-26 21:33:59 +01:00
|
|
|
case Mode.COMMAND:
|
|
|
|
case Mode.FIGHT:
|
|
|
|
case Mode.BALL:
|
|
|
|
case Mode.TARGET_SELECT:
|
2024-03-15 22:02:05 +00:00
|
|
|
case Mode.SAVE_SLOT:
|
2023-10-26 21:33:59 +01:00
|
|
|
case Mode.PARTY:
|
|
|
|
case Mode.SUMMARY:
|
|
|
|
case Mode.STARTER_SELECT:
|
|
|
|
case Mode.CONFIRM:
|
2024-03-15 01:49:49 +00:00
|
|
|
case Mode.OPTION_SELECT:
|
2023-11-12 05:31:40 +00:00
|
|
|
this.ui.setOverlayMode(Mode.MENU);
|
2023-12-25 20:48:16 +00:00
|
|
|
inputSuccess = true;
|
2023-10-26 21:33:59 +01:00
|
|
|
break;
|
2023-11-12 05:34:36 +00:00
|
|
|
case Mode.MENU:
|
2023-10-26 21:33:59 +01:00
|
|
|
case Mode.SETTINGS:
|
2023-11-12 05:34:36 +00:00
|
|
|
case Mode.ACHIEVEMENTS:
|
2023-10-26 21:33:59 +01:00
|
|
|
this.ui.revertMode();
|
|
|
|
this.playSound('select');
|
2023-12-25 20:48:16 +00:00
|
|
|
inputSuccess = true;
|
2023-10-26 21:33:59 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2023-11-12 05:31:40 +00:00
|
|
|
} else if (this.ui?.getHandler() instanceof StarterSelectUiHandler) {
|
2024-04-09 07:45:48 +01:00
|
|
|
if (this.buttonJustPressed(Button.CYCLE_SHINY)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_SHINY);
|
2024-04-16 05:03:18 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_SHINY);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.CYCLE_FORM)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_FORM);
|
2024-04-16 05:03:18 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_FORM);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.CYCLE_GENDER)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_GENDER);
|
2024-04-16 05:03:18 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_GENDER);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.CYCLE_ABILITY)) {
|
2023-11-12 05:31:40 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_ABILITY);
|
2024-04-16 05:03:18 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_ABILITY);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.CYCLE_NATURE)) {
|
2024-01-06 03:24:05 +00:00
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_NATURE);
|
2024-04-16 05:03:18 +01:00
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_NATURE);
|
2024-04-19 03:52:26 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.CYCLE_VARIANT)) {
|
|
|
|
inputSuccess = this.ui.processInput(Button.CYCLE_VARIANT);
|
|
|
|
this.setLastProcessedMovementTime(Button.CYCLE_VARIANT);
|
2024-04-09 07:45:48 +01:00
|
|
|
} else
|
2023-04-18 03:44:41 +01:00
|
|
|
return;
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.SPEED_UP)) {
|
2023-10-26 21:33:59 +01:00
|
|
|
if (this.gameSpeed < 5) {
|
|
|
|
this.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) + 1);
|
2024-02-29 04:13:05 +00:00
|
|
|
if (this.ui?.getMode() === Mode.SETTINGS)
|
2023-10-26 21:33:59 +01:00
|
|
|
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
|
|
|
}
|
2024-04-09 07:45:48 +01:00
|
|
|
} else if (this.buttonJustPressed(Button.SLOW_DOWN)) {
|
2023-04-12 16:30:47 +01:00
|
|
|
if (this.gameSpeed > 1) {
|
2023-10-26 21:33:59 +01:00
|
|
|
this.gameData.saveSetting(Setting.Game_Speed, Math.max(settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) - 1, 0));
|
2024-02-29 04:13:05 +00:00
|
|
|
if (this.ui?.getMode() === Mode.SETTINGS)
|
2023-10-26 21:33:59 +01:00
|
|
|
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
2023-04-09 05:22:14 +01:00
|
|
|
}
|
|
|
|
} else
|
2023-03-28 19:54:52 +01:00
|
|
|
return;
|
2024-02-28 18:01:38 +00:00
|
|
|
if (inputSuccess && this.enableVibration && typeof navigator.vibrate !== 'undefined')
|
2024-04-09 07:45:48 +01:00
|
|
|
navigator.vibrate(vibrationLength || 10);
|
|
|
|
}
|
|
|
|
|
2024-04-15 23:55:03 +01:00
|
|
|
/**
|
|
|
|
* gamepadButtonJustDown returns true if @param button has just been pressed down
|
|
|
|
* or not. It will only return true once, until the key is released and pressed down
|
|
|
|
* again.
|
|
|
|
*/
|
2024-04-16 00:47:12 +01:00
|
|
|
gamepadButtonJustDown(button: Phaser.Input.Gamepad.Button) : boolean {
|
2024-04-16 01:13:58 +01:00
|
|
|
if (!button || !this.gamepadSupport)
|
2024-04-16 00:44:30 +01:00
|
|
|
return false;
|
2024-04-15 23:55:03 +01:00
|
|
|
|
2024-04-16 00:44:30 +01:00
|
|
|
let ret = false;
|
|
|
|
if (button.pressed) {
|
|
|
|
if (!this.gamepadButtonStates[button.index])
|
|
|
|
ret = true;
|
|
|
|
this.gamepadButtonStates[button.index] = true;
|
|
|
|
} else
|
|
|
|
this.gamepadButtonStates[button.index] = false;
|
2024-04-15 23:55:03 +01:00
|
|
|
|
2024-04-16 00:44:30 +01:00
|
|
|
return ret;
|
2024-04-15 23:55:03 +01:00
|
|
|
}
|
|
|
|
|
2024-04-09 07:45:48 +01:00
|
|
|
buttonJustPressed(button: Button): boolean {
|
2024-04-16 00:44:30 +01:00
|
|
|
const gamepad = this.input.gamepad?.gamepads[0];
|
2024-04-15 23:55:03 +01:00
|
|
|
return this.buttonKeys[button].some(k => Phaser.Input.Keyboard.JustDown(k)) || this.gamepadButtonJustDown(gamepad?.buttons[this.gamepadKeyConfig[button]]);
|
2024-04-09 07:45:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* repeatInputDurationJustPassed returns true if @param button has been held down long
|
|
|
|
* enough to fire a repeated input. A button must claim the movementButtonLock before
|
|
|
|
* firing a repeated input - this is to prevent multiple buttons from firing repeatedly.
|
|
|
|
*/
|
|
|
|
repeatInputDurationJustPassed(button: Button): boolean {
|
|
|
|
if (this.movementButtonLock !== null && this.movementButtonLock !== button) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-04-15 23:55:03 +01:00
|
|
|
if (this.buttonKeys[button].every(k => k.isUp) && this.gamepadButtonStates.every(b => b == false)) {
|
2024-04-09 07:45:48 +01:00
|
|
|
this.movementButtonLock = null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (this.time.now - this.lastProcessedButtonPressTimes.get(button) >= repeatInputDelayMillis) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-04-09 07:45:48 +01:00
|
|
|
setLastProcessedMovementTime(button: Button) {
|
|
|
|
this.lastProcessedButtonPressTimes.set(button, this.time.now);
|
|
|
|
this.movementButtonLock = button;
|
2023-04-11 05:24:55 +01:00
|
|
|
}
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
isBgmPlaying(): boolean {
|
|
|
|
return this.bgm && this.bgm.isPlaying;
|
|
|
|
}
|
|
|
|
|
2023-10-10 01:20:02 +01:00
|
|
|
playBgm(bgmName?: string, fadeOut?: boolean): void {
|
|
|
|
if (bgmName === undefined)
|
2023-11-04 23:46:48 +00:00
|
|
|
bgmName = this.currentBattle.getBgmOverride(this) || this.arena.bgm;
|
2023-10-10 01:20:02 +01:00
|
|
|
if (this.bgm && bgmName === this.bgm.key) {
|
2023-10-18 23:01:15 +01:00
|
|
|
if (!this.bgm.isPlaying) {
|
2023-10-10 01:20:02 +01:00
|
|
|
this.bgm.play({
|
2023-10-26 21:33:59 +01:00
|
|
|
volume: this.masterVolume * this.bgmVolume
|
2023-10-10 01:20:02 +01:00
|
|
|
});
|
|
|
|
}
|
2023-04-10 18:54:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-10-10 01:20:02 +01:00
|
|
|
if (fadeOut && !this.bgm)
|
|
|
|
fadeOut = false;
|
2023-10-26 21:33:59 +01:00
|
|
|
this.bgmCache.add(bgmName);
|
2023-10-10 01:20:02 +01:00
|
|
|
this.loadBgm(bgmName);
|
|
|
|
let loopPoint = 0;
|
|
|
|
loopPoint = bgmName === this.arena.bgm
|
|
|
|
? this.arena.getBgmLoopPoint()
|
|
|
|
: this.getBgmLoopPoint(bgmName);
|
|
|
|
let loaded = false;
|
|
|
|
const playNewBgm = () => {
|
2023-11-12 02:04:20 +00:00
|
|
|
if (bgmName === null && this.bgm && !this.bgm.pendingRemove) {
|
2023-10-10 01:20:02 +01:00
|
|
|
this.bgm.play({
|
2023-10-26 21:33:59 +01:00
|
|
|
volume: this.masterVolume * this.bgmVolume
|
2023-10-10 01:20:02 +01:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2023-11-12 02:04:20 +00:00
|
|
|
if (this.bgm && !this.bgm.pendingRemove && this.bgm.isPlaying)
|
2023-10-10 01:20:02 +01:00
|
|
|
this.bgm.stop();
|
|
|
|
this.bgm = this.sound.add(bgmName, { loop: true });
|
2023-10-21 13:58:39 +01:00
|
|
|
this.bgm.play({
|
2023-10-26 21:33:59 +01:00
|
|
|
volume: this.masterVolume * this.bgmVolume
|
2023-10-21 13:58:39 +01:00
|
|
|
});
|
2023-10-10 01:20:02 +01:00
|
|
|
if (loopPoint)
|
|
|
|
this.bgm.on('looped', () => this.bgm.play({ seek: loopPoint }));
|
|
|
|
};
|
|
|
|
this.load.once(Phaser.Loader.Events.COMPLETE, () => {
|
|
|
|
loaded = true;
|
|
|
|
if (!fadeOut || !this.bgm.isPlaying)
|
|
|
|
playNewBgm();
|
|
|
|
});
|
|
|
|
if (fadeOut) {
|
2023-10-23 14:00:23 +01:00
|
|
|
const onBgmFaded = () => {
|
2023-11-12 02:04:20 +00:00
|
|
|
if (loaded && (!this.bgm.isPlaying || this.bgm.pendingRemove))
|
2023-10-10 01:20:02 +01:00
|
|
|
playNewBgm();
|
2023-10-23 14:00:23 +01:00
|
|
|
};
|
|
|
|
this.time.delayedCall(this.fadeOutBgm(500, true) ? 750 : 250, onBgmFaded);
|
2023-10-10 01:20:02 +01:00
|
|
|
}
|
|
|
|
if (!this.load.isLoading())
|
|
|
|
this.load.start();
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-26 21:33:59 +01:00
|
|
|
pauseBgm(): boolean {
|
2023-11-12 02:04:20 +00:00
|
|
|
if (this.bgm && !this.bgm.pendingRemove && this.bgm.isPlaying) {
|
2023-03-28 19:54:52 +01:00
|
|
|
this.bgm.pause();
|
2023-10-26 21:33:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-26 21:33:59 +01:00
|
|
|
resumeBgm(): boolean {
|
2023-11-12 02:04:20 +00:00
|
|
|
if (this.bgm && !this.bgm.pendingRemove && this.bgm.isPaused) {
|
2023-03-28 19:54:52 +01:00
|
|
|
this.bgm.resume();
|
2023-10-26 21:33:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSoundVolume(): void {
|
|
|
|
if (this.sound) {
|
|
|
|
for (let sound of this.sound.getAllPlaying())
|
|
|
|
(sound as AnySound).setVolume(this.masterVolume * (this.bgmCache.has(sound.key) ? this.bgmVolume : this.seVolume));
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-03-15 19:13:32 +00:00
|
|
|
fadeOutBgm(duration: integer = 500, destroy: boolean = true): boolean {
|
2023-10-10 01:20:02 +01:00
|
|
|
if (!this.bgm)
|
2023-12-30 23:41:25 +00:00
|
|
|
return false;
|
2024-01-15 01:47:08 +00:00
|
|
|
const bgm = this.sound.getAllPlaying().find(bgm => bgm.key === this.bgm.key);
|
2023-10-23 14:00:23 +01:00
|
|
|
if (bgm) {
|
2024-01-15 01:47:08 +00:00
|
|
|
SoundFade.fadeOut(this, this.bgm, duration, destroy);
|
2023-10-23 14:00:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2023-04-10 18:54:06 +01:00
|
|
|
}
|
|
|
|
|
2023-11-04 04:32:12 +00:00
|
|
|
playSound(sound: string | AnySound, config?: object): AnySound {
|
2023-10-21 13:58:39 +01:00
|
|
|
if (config) {
|
|
|
|
if (config.hasOwnProperty('volume'))
|
2023-10-26 21:33:59 +01:00
|
|
|
config['volume'] *= this.masterVolume * this.seVolume;
|
2023-10-21 13:58:39 +01:00
|
|
|
else
|
2023-10-26 21:33:59 +01:00
|
|
|
config['volume'] = this.masterVolume * this.seVolume;
|
2023-10-21 13:58:39 +01:00
|
|
|
} else
|
2023-10-26 21:33:59 +01:00
|
|
|
config = { volume: this.masterVolume * this.seVolume };
|
2024-04-02 16:53:27 +01:00
|
|
|
// PRSFX sounds are mixed too loud
|
|
|
|
if ((typeof sound === 'string' ? sound : sound.key).startsWith('PRSFX- '))
|
|
|
|
config['volume'] *= 0.5;
|
2023-11-04 04:32:12 +00:00
|
|
|
if (typeof sound === 'string') {
|
|
|
|
this.sound.play(sound, config);
|
|
|
|
return this.sound.get(sound) as AnySound;
|
|
|
|
} else {
|
|
|
|
sound.play(config);
|
|
|
|
return sound;
|
|
|
|
}
|
2023-10-21 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
2023-10-26 21:33:59 +01:00
|
|
|
playSoundWithoutBgm(soundName: string, pauseDuration?: integer): AnySound {
|
|
|
|
this.bgmCache.add(soundName);
|
|
|
|
const resumeBgm = this.pauseBgm();
|
2023-10-21 13:58:39 +01:00
|
|
|
this.playSound(soundName);
|
2023-10-26 21:33:59 +01:00
|
|
|
const sound = this.sound.get(soundName) as AnySound;
|
2023-04-18 06:32:26 +01:00
|
|
|
if (this.bgmResumeTimer)
|
|
|
|
this.bgmResumeTimer.destroy();
|
2023-10-26 21:33:59 +01:00
|
|
|
if (resumeBgm) {
|
|
|
|
this.bgmResumeTimer = this.time.delayedCall((pauseDuration || Utils.fixedInt(sound.totalDuration * 1000)), () => {
|
|
|
|
this.resumeBgm();
|
|
|
|
this.bgmResumeTimer = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return sound;
|
2023-04-18 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
2023-10-10 01:20:02 +01:00
|
|
|
getBgmLoopPoint(bgmName: string): number {
|
|
|
|
switch (bgmName) {
|
2024-03-06 23:55:55 +00:00
|
|
|
case 'battle_kanto_champion':
|
|
|
|
return 13.950;
|
|
|
|
case 'battle_johto_champion':
|
|
|
|
return 23.498;
|
|
|
|
case 'battle_hoenn_champion':
|
|
|
|
return 11.328;
|
|
|
|
case 'battle_sinnoh_champion':
|
2023-10-10 01:20:02 +01:00
|
|
|
return 12.235;
|
2024-03-06 23:55:55 +00:00
|
|
|
case 'battle_champion_alder':
|
|
|
|
return 27.653;
|
|
|
|
case 'battle_champion_iris':
|
|
|
|
return 10.145;
|
2023-10-10 01:20:02 +01:00
|
|
|
case 'battle_elite':
|
|
|
|
return 17.730;
|
2024-01-13 17:24:24 +00:00
|
|
|
case 'battle_final_encounter':
|
|
|
|
return 19.159;
|
2023-10-10 01:20:02 +01:00
|
|
|
case 'battle_final':
|
|
|
|
return 16.453;
|
2024-03-06 23:55:55 +00:00
|
|
|
case 'battle_kanto_gym':
|
|
|
|
return 13.857;
|
|
|
|
case 'battle_johto_gym':
|
|
|
|
return 12.911;
|
|
|
|
case 'battle_hoenn_gym':
|
|
|
|
return 12.379;
|
|
|
|
case 'battle_sinnoh_gym':
|
|
|
|
return 13.122;
|
|
|
|
case 'battle_unova_gym':
|
2023-10-10 01:20:02 +01:00
|
|
|
return 19.145;
|
|
|
|
case 'battle_legendary':
|
|
|
|
return 13.855;
|
|
|
|
case 'battle_legendary_k':
|
|
|
|
return 18.314;
|
|
|
|
case 'battle_legendary_rz':
|
|
|
|
return 18.329;
|
|
|
|
case 'battle_rival':
|
|
|
|
return 13.689;
|
|
|
|
case 'battle_rival_2':
|
|
|
|
return 17.714;
|
|
|
|
case 'battle_rival_3':
|
|
|
|
return 17.586;
|
|
|
|
case 'battle_trainer':
|
|
|
|
return 13.686;
|
|
|
|
case 'battle_wild':
|
|
|
|
return 12.703;
|
|
|
|
case 'battle_wild_strong':
|
|
|
|
return 13.940;
|
2024-01-13 17:24:24 +00:00
|
|
|
case 'end_summit':
|
|
|
|
return 30.025;
|
2023-10-10 01:20:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-08 03:23:42 +00:00
|
|
|
toggleInvert(invert: boolean): void {
|
|
|
|
if (invert)
|
|
|
|
this.cameras.main.setPostPipeline(InvertPostFX);
|
|
|
|
else
|
|
|
|
this.cameras.main.removePostPipeline('InvertPostFX');
|
|
|
|
}
|
|
|
|
|
2024-03-30 19:34:00 +00:00
|
|
|
/* Phase Functions */
|
2024-02-22 04:57:49 +00:00
|
|
|
getCurrentPhase(): Phase {
|
2023-03-28 19:54:52 +01:00
|
|
|
return this.currentPhase;
|
|
|
|
}
|
|
|
|
|
2024-02-22 04:57:49 +00:00
|
|
|
getStandbyPhase(): Phase {
|
2024-01-10 04:34:43 +00:00
|
|
|
return this.standbyPhase;
|
|
|
|
}
|
|
|
|
|
2024-03-11 22:13:07 +00:00
|
|
|
pushPhase(phase: Phase, defer: boolean = false): void {
|
|
|
|
(!defer ? this.phaseQueue : this.nextCommandPhaseQueue).push(phase);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-02-22 04:57:49 +00:00
|
|
|
unshiftPhase(phase: Phase): void {
|
2023-04-27 19:30:03 +01:00
|
|
|
if (this.phaseQueuePrependSpliceIndex === -1)
|
|
|
|
this.phaseQueuePrepend.push(phase);
|
|
|
|
else
|
|
|
|
this.phaseQueuePrepend.splice(this.phaseQueuePrependSpliceIndex, 0, phase);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
clearPhaseQueue(): void {
|
|
|
|
this.phaseQueue.splice(0, this.phaseQueue.length);
|
|
|
|
}
|
|
|
|
|
2023-04-27 19:30:03 +01:00
|
|
|
setPhaseQueueSplice(): void {
|
|
|
|
this.phaseQueuePrependSpliceIndex = this.phaseQueuePrepend.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearPhaseQueueSplice(): void {
|
|
|
|
this.phaseQueuePrependSpliceIndex = -1;
|
|
|
|
}
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
shiftPhase(): void {
|
2024-01-10 04:34:43 +00:00
|
|
|
if (this.standbyPhase) {
|
|
|
|
this.currentPhase = this.standbyPhase;
|
|
|
|
this.standbyPhase = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-27 19:30:03 +01:00
|
|
|
if (this.phaseQueuePrependSpliceIndex > -1)
|
|
|
|
this.clearPhaseQueueSplice();
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.phaseQueuePrepend.length) {
|
|
|
|
while (this.phaseQueuePrepend.length)
|
|
|
|
this.phaseQueue.unshift(this.phaseQueuePrepend.pop());
|
|
|
|
}
|
|
|
|
if (!this.phaseQueue.length)
|
|
|
|
this.populatePhaseQueue();
|
|
|
|
this.currentPhase = this.phaseQueue.shift();
|
|
|
|
this.currentPhase.start();
|
|
|
|
}
|
2024-01-10 04:34:43 +00:00
|
|
|
|
2024-02-22 04:57:49 +00:00
|
|
|
overridePhase(phase: Phase): boolean {
|
2024-01-10 04:34:43 +00:00
|
|
|
if (this.standbyPhase)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this.standbyPhase = this.currentPhase;
|
|
|
|
this.currentPhase = phase;
|
|
|
|
phase.start();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-02-22 04:57:49 +00:00
|
|
|
findPhase(phaseFilter: (phase: Phase) => boolean): Phase {
|
2024-01-13 17:24:24 +00:00
|
|
|
return this.phaseQueue.find(phaseFilter);
|
|
|
|
}
|
|
|
|
|
2024-03-19 01:22:27 +00:00
|
|
|
tryReplacePhase(phaseFilter: (phase: Phase) => boolean, phase: Phase): boolean {
|
|
|
|
const phaseIndex = this.phaseQueue.findIndex(phaseFilter);
|
|
|
|
if (phaseIndex > -1) {
|
|
|
|
this.phaseQueue[phaseIndex] = phase;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tryRemovePhase(phaseFilter: (phase: Phase) => boolean): boolean {
|
|
|
|
const phaseIndex = this.phaseQueue.findIndex(phaseFilter);
|
|
|
|
if (phaseIndex > -1) {
|
|
|
|
this.phaseQueue.splice(phaseIndex, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-20 18:15:53 +00:00
|
|
|
pushMovePhase(movePhase: MovePhase, priorityOverride?: integer): void {
|
2024-03-28 20:24:11 +00:00
|
|
|
const movePriority = new Utils.IntegerHolder(priorityOverride !== undefined ? priorityOverride : movePhase.move.getMove().priority);
|
|
|
|
applyAbAttrs(IncrementMovePriorityAbAttr, movePhase.pokemon, null, movePhase.move.getMove(), movePriority);
|
|
|
|
const lowerPriorityPhase = this.phaseQueue.find(p => p instanceof MovePhase && p.move.getMove().priority < movePriority.value);
|
2024-02-20 18:15:53 +00:00
|
|
|
if (lowerPriorityPhase)
|
|
|
|
this.phaseQueue.splice(this.phaseQueue.indexOf(lowerPriorityPhase), 0, movePhase);
|
|
|
|
else
|
|
|
|
this.pushPhase(movePhase);
|
|
|
|
}
|
|
|
|
|
2023-12-23 03:46:05 +00:00
|
|
|
queueMessage(message: string, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer, defer?: boolean) {
|
|
|
|
const phase = new MessagePhase(this, message, callbackDelay, prompt, promptDelay);
|
|
|
|
if (!defer)
|
|
|
|
this.unshiftPhase(phase);
|
|
|
|
else
|
|
|
|
this.pushPhase(phase);
|
2023-04-22 00:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
populatePhaseQueue(): void {
|
2024-03-11 22:13:07 +00:00
|
|
|
if (this.nextCommandPhaseQueue.length) {
|
|
|
|
this.phaseQueue.push(...this.nextCommandPhaseQueue);
|
|
|
|
this.nextCommandPhaseQueue.splice(0, this.nextCommandPhaseQueue.length);
|
|
|
|
}
|
2023-05-18 16:11:06 +01:00
|
|
|
this.phaseQueue.push(new TurnInitPhase(this));
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-02-04 05:30:19 +00:00
|
|
|
getWaveMoneyAmount(moneyMultiplier: number): integer {
|
2024-01-18 22:22:18 +00:00
|
|
|
const waveIndex = this.currentBattle.waveIndex;
|
|
|
|
const waveSetIndex = Math.ceil(waveIndex / 10) - 1;
|
|
|
|
const moneyValue = Math.pow((waveSetIndex + 1 + (0.75 + (((waveIndex - 1) % 10) + 1) / 10)) * 100, 1 + 0.005 * waveSetIndex) * moneyMultiplier;
|
|
|
|
return Math.floor(moneyValue / 10) * 10;
|
|
|
|
}
|
|
|
|
|
2024-04-16 17:04:52 +01:00
|
|
|
addModifier(modifier: Modifier, ignoreUpdate?: boolean, playSound?: boolean, virtual?: boolean, instant?: boolean): Promise<boolean> {
|
2023-04-04 23:28:21 +01:00
|
|
|
return new Promise(resolve => {
|
2024-04-16 17:04:52 +01:00
|
|
|
let success = false;
|
2023-04-20 16:29:26 +01:00
|
|
|
const soundName = modifier.type.soundName;
|
2023-11-12 05:55:13 +00:00
|
|
|
this.validateAchvs(ModifierAchv, modifier);
|
2024-02-17 05:40:03 +00:00
|
|
|
const modifiersToRemove: PersistentModifier[] = [];
|
2024-04-12 01:40:16 +01:00
|
|
|
const modifierPromises: Promise<boolean>[] = [];
|
2023-04-10 00:15:21 +01:00
|
|
|
if (modifier instanceof PersistentModifier) {
|
2024-02-17 05:40:03 +00:00
|
|
|
if (modifier instanceof TerastallizeModifier)
|
|
|
|
modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId)));
|
2023-12-09 05:33:29 +00:00
|
|
|
if ((modifier as PersistentModifier).add(this.modifiers, !!virtual, this)) {
|
2024-02-17 05:40:03 +00:00
|
|
|
if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier)
|
2024-04-16 17:04:52 +01:00
|
|
|
success = modifier.apply([ this.getPokemonById(modifier.pokemonId), true ]);
|
2023-04-21 00:44:56 +01:00
|
|
|
if (playSound && !this.sound.get(soundName))
|
2023-10-21 13:58:39 +01:00
|
|
|
this.playSound(soundName);
|
2023-04-20 20:46:05 +01:00
|
|
|
} else if (!virtual) {
|
2023-04-20 16:29:26 +01:00
|
|
|
const defaultModifierType = getDefaultModifierTypeForTier(modifier.type.tier);
|
2023-04-22 00:30:04 +01:00
|
|
|
this.queueMessage(`The stack for this item is full.\n You will receive ${defaultModifierType.name} instead.`, null, true);
|
2024-04-16 17:04:52 +01:00
|
|
|
return this.addModifier(defaultModifierType.newModifier(), ignoreUpdate, playSound, false, instant).then(success => resolve(success));
|
2023-04-20 16:29:26 +01:00
|
|
|
}
|
2024-02-17 05:40:03 +00:00
|
|
|
|
|
|
|
for (let rm of modifiersToRemove)
|
|
|
|
this.removeModifier(rm);
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-11-01 01:43:22 +00:00
|
|
|
if (!ignoreUpdate && !virtual)
|
2024-04-16 17:04:52 +01:00
|
|
|
return this.updateModifiers(true, instant).then(() => resolve(success));
|
2023-04-10 00:15:21 +01:00
|
|
|
} else if (modifier instanceof ConsumableModifier) {
|
2023-04-21 00:44:56 +01:00
|
|
|
if (playSound && !this.sound.get(soundName))
|
2023-10-21 13:58:39 +01:00
|
|
|
this.playSound(soundName);
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-04-10 00:15:21 +01:00
|
|
|
if (modifier instanceof ConsumablePokemonModifier) {
|
|
|
|
for (let p in this.party) {
|
|
|
|
const pokemon = this.party[p];
|
2023-04-04 23:28:21 +01:00
|
|
|
|
2023-04-10 00:15:21 +01:00
|
|
|
const args: any[] = [ pokemon ];
|
|
|
|
if (modifier instanceof PokemonHpRestoreModifier) {
|
2023-04-20 20:46:05 +01:00
|
|
|
if (!(modifier as PokemonHpRestoreModifier).fainted) {
|
|
|
|
const hpRestoreMultiplier = new Utils.IntegerHolder(1);
|
2023-04-21 00:44:56 +01:00
|
|
|
this.applyModifiers(HealingBoosterModifier, true, hpRestoreMultiplier);
|
2023-04-20 20:46:05 +01:00
|
|
|
args.push(hpRestoreMultiplier.value);
|
|
|
|
} else
|
|
|
|
args.push(1);
|
2023-11-04 04:32:12 +00:00
|
|
|
} else if (modifier instanceof FusePokemonModifier)
|
|
|
|
args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon);
|
2023-04-11 16:04:39 +01:00
|
|
|
|
2024-04-12 01:40:16 +01:00
|
|
|
if (modifier.shouldApply(args)) {
|
|
|
|
const result = modifier.apply(args);
|
|
|
|
if (result instanceof Promise)
|
2024-04-16 17:04:52 +01:00
|
|
|
modifierPromises.push(result.then(s => success ||= s));
|
|
|
|
else
|
|
|
|
success ||= result;
|
2024-04-12 01:40:16 +01:00
|
|
|
}
|
2023-04-04 23:28:21 +01:00
|
|
|
}
|
2023-04-10 00:15:21 +01:00
|
|
|
|
2024-04-16 17:04:52 +01:00
|
|
|
return Promise.allSettled([this.party.map(p => p.updateInfo(instant)), ...modifierPromises]).then(() => resolve(success));
|
2023-04-10 00:15:21 +01:00
|
|
|
} else {
|
|
|
|
const args = [ this ];
|
2024-04-16 17:04:52 +01:00
|
|
|
if (modifier.shouldApply(args)) {
|
|
|
|
const result = modifier.apply(args);
|
|
|
|
if (result instanceof Promise) {
|
|
|
|
return result.then(success => resolve(success));
|
|
|
|
} else
|
|
|
|
success ||= result;
|
|
|
|
}
|
2023-04-10 00:15:21 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-01 14:38:54 +00:00
|
|
|
|
2024-04-16 17:04:52 +01:00
|
|
|
resolve(success);
|
2023-04-10 00:15:21 +01:00
|
|
|
});
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
addEnemyModifier(modifier: PersistentModifier, ignoreUpdate?: boolean, instant?: boolean): Promise<void> {
|
2023-04-23 15:24:22 +01:00
|
|
|
return new Promise(resolve => {
|
2024-02-17 05:40:03 +00:00
|
|
|
const modifiersToRemove: PersistentModifier[] = [];
|
|
|
|
if (modifier instanceof TerastallizeModifier)
|
|
|
|
modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId, false)));
|
|
|
|
if ((modifier as PersistentModifier).add(this.enemyModifiers, false, this)) {
|
|
|
|
if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier)
|
|
|
|
modifier.apply([ this.getPokemonById(modifier.pokemonId), true ]);
|
|
|
|
for (let rm of modifiersToRemove)
|
|
|
|
this.removeModifier(rm, true);
|
|
|
|
}
|
2023-11-01 01:43:22 +00:00
|
|
|
if (!ignoreUpdate)
|
2023-12-23 04:57:05 +00:00
|
|
|
this.updateModifiers(false, instant).then(() => resolve());
|
2023-11-01 01:43:22 +00:00
|
|
|
else
|
|
|
|
resolve();
|
2023-04-23 15:24:22 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-02 15:23:54 +00:00
|
|
|
tryTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferStack: boolean, playSound: boolean, instant?: boolean, ignoreUpdate?: boolean): Promise<boolean> {
|
2023-04-21 20:45:48 +01:00
|
|
|
return new Promise(resolve => {
|
2024-03-07 02:05:23 +00:00
|
|
|
const source = itemModifier.pokemonId ? itemModifier.getPokemon(target.scene) : null;
|
2023-05-04 19:06:31 +01:00
|
|
|
const cancelled = new Utils.BooleanHolder(false);
|
2024-03-14 17:31:13 +00:00
|
|
|
Utils.executeIf(source && source.isPlayer() !== target.isPlayer(), () => applyAbAttrs(BlockItemTheftAbAttr, source, cancelled)).then(() => {
|
2023-12-23 04:57:05 +00:00
|
|
|
if (cancelled.value)
|
|
|
|
return resolve(false);
|
|
|
|
const newItemModifier = itemModifier.clone() as PokemonHeldItemModifier;
|
|
|
|
newItemModifier.pokemonId = target.id;
|
|
|
|
const matchingModifier = target.scene.findModifier(m => m instanceof PokemonHeldItemModifier
|
|
|
|
&& (m as PokemonHeldItemModifier).matchType(itemModifier) && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier;
|
|
|
|
let removeOld = true;
|
|
|
|
if (matchingModifier) {
|
2024-03-07 02:05:23 +00:00
|
|
|
const maxStackCount = matchingModifier.getMaxStackCount(target.scene);
|
2023-12-23 04:57:05 +00:00
|
|
|
if (matchingModifier.stackCount >= maxStackCount)
|
|
|
|
return resolve(false);
|
|
|
|
const countTaken = transferStack ? Math.min(itemModifier.stackCount, maxStackCount - matchingModifier.stackCount) : 1;
|
|
|
|
itemModifier.stackCount -= countTaken;
|
|
|
|
newItemModifier.stackCount = matchingModifier.stackCount + countTaken;
|
|
|
|
removeOld = !itemModifier.stackCount;
|
|
|
|
} else if (!transferStack) {
|
|
|
|
newItemModifier.stackCount = 1;
|
|
|
|
removeOld = !(--itemModifier.stackCount);
|
|
|
|
}
|
2024-03-07 02:05:23 +00:00
|
|
|
if (!removeOld || !source || this.removeModifier(itemModifier, !source.isPlayer())) {
|
2023-12-23 04:57:05 +00:00
|
|
|
const addModifier = () => {
|
|
|
|
if (!matchingModifier || this.removeModifier(matchingModifier, !target.isPlayer())) {
|
|
|
|
if (target.isPlayer())
|
2024-03-02 15:23:54 +00:00
|
|
|
this.addModifier(newItemModifier, ignoreUpdate, playSound, false, instant).then(() => resolve(true));
|
2023-12-23 04:57:05 +00:00
|
|
|
else
|
2024-03-02 15:23:54 +00:00
|
|
|
this.addEnemyModifier(newItemModifier, ignoreUpdate, instant).then(() => resolve(true));
|
2023-12-23 04:57:05 +00:00
|
|
|
} else
|
|
|
|
resolve(false);
|
|
|
|
};
|
2024-03-07 02:05:23 +00:00
|
|
|
if (source && source.isPlayer() !== target.isPlayer() && !ignoreUpdate)
|
2023-12-23 04:57:05 +00:00
|
|
|
this.updateModifiers(source.isPlayer(), instant).then(() => addModifier());
|
|
|
|
else
|
|
|
|
addModifier();
|
2023-04-21 20:45:48 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-12-23 04:57:05 +00:00
|
|
|
resolve(false);
|
|
|
|
});
|
2023-04-21 20:45:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-11 14:41:11 +01:00
|
|
|
removePartyMemberModifiers(partyMemberIndex: integer): Promise<void> {
|
2023-04-10 00:15:21 +01:00
|
|
|
return new Promise(resolve => {
|
2023-04-11 14:41:11 +01:00
|
|
|
const pokemonId = this.getParty()[partyMemberIndex].id;
|
2023-10-28 18:24:57 +01:00
|
|
|
const modifiersToRemove = this.modifiers.filter(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === pokemonId);
|
2023-04-11 14:41:11 +01:00
|
|
|
for (let m of modifiersToRemove)
|
|
|
|
this.modifiers.splice(this.modifiers.indexOf(m), 1);
|
|
|
|
this.updateModifiers().then(() => resolve());
|
2023-04-10 00:15:21 +01:00
|
|
|
});
|
|
|
|
}
|
2023-04-04 23:28:21 +01:00
|
|
|
|
2023-04-21 00:44:56 +01:00
|
|
|
generateEnemyModifiers(): Promise<void> {
|
2023-04-10 00:15:21 +01:00
|
|
|
return new Promise(resolve => {
|
2024-02-17 16:18:53 +00:00
|
|
|
if (this.currentBattle.battleSpec === BattleSpec.FINAL_BOSS)
|
|
|
|
return resolve();
|
2024-03-17 04:12:57 +00:00
|
|
|
const difficultyWaveIndex = this.gameMode.getWaveForDifficulty(this.currentBattle.waveIndex);
|
|
|
|
const isFinalBoss = this.gameMode.isWaveFinal(this.currentBattle.waveIndex);
|
|
|
|
let chances = Math.ceil(difficultyWaveIndex / 10);
|
|
|
|
if (isFinalBoss)
|
|
|
|
chances = Math.ceil(chances * 2.5);
|
2023-10-24 15:05:07 +01:00
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
const party = this.getEnemyParty();
|
|
|
|
|
|
|
|
if (this.currentBattle.trainer) {
|
|
|
|
const modifiers = this.currentBattle.trainer.genModifiers(party);
|
|
|
|
for (let modifier of modifiers)
|
|
|
|
this.addEnemyModifier(modifier, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
party.forEach((enemyPokemon: EnemyPokemon, i: integer) => {
|
2024-03-17 04:12:57 +00:00
|
|
|
const isBoss = enemyPokemon.isBoss() || (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer.config.isBoss);
|
|
|
|
let upgradeChance = 32;
|
|
|
|
if (isBoss)
|
|
|
|
upgradeChance /= 2;
|
|
|
|
if (isFinalBoss)
|
|
|
|
upgradeChance /= 8;
|
|
|
|
const modifierChance = this.gameMode.getEnemyModifierChance(isBoss);
|
2023-10-24 15:05:07 +01:00
|
|
|
let pokemonModifierChance = modifierChance;
|
2023-10-23 18:48:56 +01:00
|
|
|
if (this.currentBattle.battleType === BattleType.TRAINER)
|
2023-10-24 15:05:07 +01:00
|
|
|
pokemonModifierChance = Math.ceil(pokemonModifierChance * this.currentBattle.trainer.getPartyMemberModifierChanceMultiplier(i));
|
|
|
|
let count = 0;
|
|
|
|
for (let c = 0; c < chances; c++) {
|
|
|
|
if (!Utils.randSeedInt(modifierChance))
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (isBoss)
|
|
|
|
count = Math.max(count, Math.floor(chances / 2));
|
2024-03-17 04:12:57 +00:00
|
|
|
getEnemyModifierTypesForWave(difficultyWaveIndex, count, [ enemyPokemon ], this.currentBattle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD, upgradeChance)
|
2023-12-09 05:33:29 +00:00
|
|
|
.map(mt => mt.newModifier(enemyPokemon).add(this.enemyModifiers, false, this));
|
2023-10-24 15:05:07 +01:00
|
|
|
});
|
2023-04-21 00:44:56 +01:00
|
|
|
|
|
|
|
this.updateModifiers(false).then(() => resolve());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-28 18:24:57 +01:00
|
|
|
clearEnemyHeldItemModifiers(): void {
|
|
|
|
const modifiersToRemove = this.enemyModifiers.filter(m => m instanceof PokemonHeldItemModifier);
|
|
|
|
for (let m of modifiersToRemove)
|
|
|
|
this.enemyModifiers.splice(this.enemyModifiers.indexOf(m), 1);
|
2023-10-04 22:24:28 +01:00
|
|
|
this.updateModifiers(false).then(() => this.updateUIPositions());
|
2023-04-21 00:44:56 +01:00
|
|
|
}
|
|
|
|
|
2024-04-07 02:48:48 +01:00
|
|
|
setModifiersVisible(visible: boolean) {
|
|
|
|
[ this.modifierBar, this.enemyModifierBar ].map(m => m.setVisible(visible));
|
|
|
|
}
|
|
|
|
|
2023-12-23 04:57:05 +00:00
|
|
|
updateModifiers(player?: boolean, instant?: boolean): Promise<void> {
|
2023-04-21 00:44:56 +01:00
|
|
|
if (player === undefined)
|
|
|
|
player = true;
|
|
|
|
return new Promise(resolve => {
|
2023-04-24 05:38:28 +01:00
|
|
|
const modifiers = player ? this.modifiers : this.enemyModifiers as PersistentModifier[];
|
2023-07-05 18:03:51 +01:00
|
|
|
for (let m = 0; m < modifiers.length; m++) {
|
|
|
|
const modifier = modifiers[m];
|
|
|
|
if (modifier instanceof PokemonHeldItemModifier && !this.getPokemonById((modifier as PokemonHeldItemModifier).pokemonId))
|
|
|
|
modifiers.splice(m--, 1);
|
|
|
|
}
|
2023-04-21 00:44:56 +01:00
|
|
|
for (let modifier of modifiers) {
|
2023-04-10 00:15:21 +01:00
|
|
|
if (modifier instanceof PersistentModifier)
|
|
|
|
(modifier as PersistentModifier).virtualStackCount = 0;
|
|
|
|
}
|
|
|
|
|
2023-04-21 00:44:56 +01:00
|
|
|
const modifiersClone = modifiers.slice(0);
|
|
|
|
for (let modifier of modifiersClone) {
|
2023-04-10 00:15:21 +01:00
|
|
|
if (!modifier.getStackCount())
|
2023-04-21 00:44:56 +01:00
|
|
|
modifiers.splice(modifiers.indexOf(modifier), 1);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
2023-04-04 23:28:21 +01:00
|
|
|
|
2023-12-23 04:57:05 +00:00
|
|
|
this.updatePartyForModifiers(player ? this.getParty() : this.getEnemyParty(), instant).then(() => {
|
2023-04-21 00:44:56 +01:00
|
|
|
(player ? this.modifierBar : this.enemyModifierBar).updateModifiers(modifiers);
|
|
|
|
if (!player)
|
2023-10-04 22:24:28 +01:00
|
|
|
this.updateUIPositions();
|
2023-04-04 23:28:21 +01:00
|
|
|
resolve();
|
2023-04-10 00:15:21 +01:00
|
|
|
});
|
2023-04-04 23:28:21 +01:00
|
|
|
});
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-12-23 04:57:05 +00:00
|
|
|
updatePartyForModifiers(party: Pokemon[], instant?: boolean): Promise<void> {
|
2023-04-11 14:41:11 +01:00
|
|
|
return new Promise(resolve => {
|
2023-04-21 00:44:56 +01:00
|
|
|
Promise.allSettled(party.map(p => {
|
2023-12-26 17:01:56 +00:00
|
|
|
if (p.scene)
|
|
|
|
p.calculateStats();
|
2023-12-23 04:57:05 +00:00
|
|
|
return p.updateInfo(instant);
|
2023-04-11 14:41:11 +01:00
|
|
|
})).then(() => resolve());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-21 00:44:56 +01:00
|
|
|
removeModifier(modifier: PersistentModifier, enemy?: boolean): boolean {
|
|
|
|
const modifiers = !enemy ? this.modifiers : this.enemyModifiers;
|
|
|
|
const modifierIndex = modifiers.indexOf(modifier);
|
2023-04-19 03:09:37 +01:00
|
|
|
if (modifierIndex > -1) {
|
2023-04-21 00:44:56 +01:00
|
|
|
modifiers.splice(modifierIndex, 1);
|
2024-02-17 05:40:03 +00:00
|
|
|
if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier)
|
|
|
|
modifier.apply([ this.getPokemonById(modifier.pokemonId), false ]);
|
2023-04-19 03:09:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
getModifiers(modifierType: { new(...args: any[]): Modifier }, player: boolean = true): PersistentModifier[] {
|
2023-04-21 00:44:56 +01:00
|
|
|
return (player ? this.modifiers : this.enemyModifiers).filter(m => m instanceof modifierType);
|
|
|
|
}
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
findModifiers(modifierFilter: ModifierPredicate, player: boolean = true): PersistentModifier[] {
|
2023-04-21 00:44:56 +01:00
|
|
|
return (player ? this.modifiers : this.enemyModifiers).filter(m => (modifierFilter as ModifierPredicate)(m));
|
2023-03-31 04:02:35 +01:00
|
|
|
}
|
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
findModifier(modifierFilter: ModifierPredicate, player: boolean = true): PersistentModifier {
|
2023-04-21 00:44:56 +01:00
|
|
|
return (player ? this.modifiers : this.enemyModifiers).find(m => (modifierFilter as ModifierPredicate)(m));
|
2023-04-14 23:21:33 +01:00
|
|
|
}
|
|
|
|
|
2024-03-25 04:21:00 +00:00
|
|
|
applyModifiers(modifierType: { new(...args: any[]): Modifier }, player: boolean = true, ...args: any[]): PersistentModifier[] {
|
|
|
|
const appliedModifiers: PersistentModifier[] = [];
|
2023-04-21 00:44:56 +01:00
|
|
|
const modifiers = (player ? this.modifiers : this.enemyModifiers).filter(m => m instanceof modifierType && m.shouldApply(args));
|
2023-03-28 19:54:52 +01:00
|
|
|
for (let modifier of modifiers) {
|
2024-03-25 04:21:00 +00:00
|
|
|
if (modifier.apply(args)) {
|
2023-04-21 00:44:56 +01:00
|
|
|
console.log('Applied', modifier.type.name, !player ? '(enemy)' : '');
|
2024-03-25 04:21:00 +00:00
|
|
|
appliedModifiers.push(modifier);
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
2024-03-25 04:21:00 +00:00
|
|
|
|
|
|
|
return appliedModifiers;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
2023-04-20 20:46:05 +01:00
|
|
|
|
2024-02-17 05:40:03 +00:00
|
|
|
applyModifier(modifierType: { new(...args: any[]): Modifier }, player: boolean = true, ...args: any[]): PersistentModifier {
|
2023-04-21 00:44:56 +01:00
|
|
|
const modifiers = (player ? this.modifiers : this.enemyModifiers).filter(m => m instanceof modifierType && m.shouldApply(args));
|
2023-04-20 20:46:05 +01:00
|
|
|
for (let modifier of modifiers) {
|
|
|
|
if (modifier.apply(args)) {
|
2023-04-21 00:44:56 +01:00
|
|
|
console.log('Applied', modifier.type.name, !player ? '(enemy)' : '');
|
2023-04-20 20:46:05 +01:00
|
|
|
return modifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-11-12 05:31:40 +00:00
|
|
|
|
2024-01-10 04:34:43 +00:00
|
|
|
triggerPokemonFormChange(pokemon: Pokemon, formChangeTriggerType: { new(...args: any[]): SpeciesFormChangeTrigger }, delayed: boolean = false, modal: boolean = false): boolean {
|
|
|
|
if (pokemonFormChanges.hasOwnProperty(pokemon.species.speciesId)) {
|
|
|
|
const matchingFormChange = pokemonFormChanges[pokemon.species.speciesId].find(fc => fc.findTrigger(formChangeTriggerType) && fc.canChange(pokemon));
|
|
|
|
if (matchingFormChange) {
|
2024-02-22 04:57:49 +00:00
|
|
|
let phase: Phase;
|
2024-01-10 04:34:43 +00:00
|
|
|
if (pokemon instanceof PlayerPokemon && !matchingFormChange.quiet)
|
|
|
|
phase = new FormChangePhase(this, pokemon, matchingFormChange, modal);
|
|
|
|
else
|
|
|
|
phase = new QuietFormChangePhase(this, pokemon, matchingFormChange);
|
2024-01-13 17:24:24 +00:00
|
|
|
if (pokemon instanceof PlayerPokemon && !matchingFormChange.quiet && modal)
|
2024-01-10 04:34:43 +00:00
|
|
|
this.overridePhase(phase);
|
|
|
|
else if (delayed)
|
|
|
|
this.pushPhase(phase);
|
|
|
|
else
|
|
|
|
this.unshiftPhase(phase);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-12 05:31:40 +00:00
|
|
|
validateAchvs(achvType: { new(...args: any[]): Achv }, ...args: any[]): void {
|
|
|
|
const filteredAchvs = Object.values(achvs).filter(a => a instanceof achvType);
|
2023-11-13 04:47:04 +00:00
|
|
|
for (let achv of filteredAchvs)
|
|
|
|
this.validateAchv(achv, args);
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 04:47:04 +00:00
|
|
|
validateAchv(achv: Achv, args?: any[]): boolean {
|
2023-11-12 05:31:40 +00:00
|
|
|
if (!this.gameData.achvUnlocks.hasOwnProperty(achv.id) && achv.validate(this, args)) {
|
|
|
|
this.gameData.achvUnlocks[achv.id] = new Date().getTime();
|
|
|
|
this.ui.achvBar.showAchv(achv);
|
2023-12-20 04:51:48 +00:00
|
|
|
if (vouchers.hasOwnProperty(achv.id))
|
|
|
|
this.validateVoucher(vouchers[achv.id]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
validateVoucher(voucher: Voucher, args?: any[]): boolean {
|
|
|
|
if (!this.gameData.voucherUnlocks.hasOwnProperty(voucher.id) && voucher.validate(this, args)) {
|
|
|
|
this.gameData.voucherUnlocks[voucher.id] = new Date().getTime();
|
|
|
|
this.ui.achvBar.showAchv(voucher);
|
|
|
|
this.gameData.voucherCounts[voucher.voucherType]++;
|
2023-11-12 05:31:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2024-04-19 03:52:26 +01:00
|
|
|
}
|