move random selection behavior to seperate label

This commit is contained in:
OriShalhon 2025-01-03 21:25:41 +01:00
parent 8093b3117b
commit 5785a60af1
6 changed files with 129 additions and 114 deletions

@ -1 +1 @@
Subproject commit 6c6f0af398ae11f8d96c6ac064f171d927812c85 Subproject commit 9e563308054c6cd48d4a9e05b8529148db16ff99

View File

@ -183,7 +183,6 @@ const cfg_keyboard_qwerty = {
[SettingKeyboard.Button_Cycle_Variant]: Button.V, [SettingKeyboard.Button_Cycle_Variant]: Button.V,
[SettingKeyboard.Button_Speed_Up]: Button.SPEED_UP, [SettingKeyboard.Button_Speed_Up]: Button.SPEED_UP,
[SettingKeyboard.Button_Slow_Down]: Button.SLOW_DOWN, [SettingKeyboard.Button_Slow_Down]: Button.SLOW_DOWN,
[SettingKeyboard.Button_Randomize]: Button.RANDOMIZE,
[SettingKeyboard.Alt_Button_Up]: Button.UP, [SettingKeyboard.Alt_Button_Up]: Button.UP,
[SettingKeyboard.Alt_Button_Down]: Button.DOWN, [SettingKeyboard.Alt_Button_Down]: Button.DOWN,
[SettingKeyboard.Alt_Button_Left]: Button.LEFT, [SettingKeyboard.Alt_Button_Left]: Button.LEFT,
@ -201,7 +200,6 @@ const cfg_keyboard_qwerty = {
[SettingKeyboard.Alt_Button_Cycle_Variant]: Button.V, [SettingKeyboard.Alt_Button_Cycle_Variant]: Button.V,
[SettingKeyboard.Alt_Button_Speed_Up]: Button.SPEED_UP, [SettingKeyboard.Alt_Button_Speed_Up]: Button.SPEED_UP,
[SettingKeyboard.Alt_Button_Slow_Down]: Button.SLOW_DOWN, [SettingKeyboard.Alt_Button_Slow_Down]: Button.SLOW_DOWN,
[SettingKeyboard.Alt_Button_Randomize]: Button.RANDOMIZE
}, },
default: { default: {
KEY_ARROW_UP: SettingKeyboard.Button_Up, KEY_ARROW_UP: SettingKeyboard.Button_Up,
@ -232,7 +230,7 @@ const cfg_keyboard_qwerty = {
KEY_M: SettingKeyboard.Alt_Button_Menu, KEY_M: SettingKeyboard.Alt_Button_Menu,
KEY_O: -1, KEY_O: -1,
KEY_P: -1, KEY_P: -1,
KEY_Q: SettingKeyboard.Button_Randomize, KEY_Q: -1,
KEY_S: SettingKeyboard.Alt_Button_Down, KEY_S: SettingKeyboard.Alt_Button_Down,
KEY_T: SettingKeyboard.Alt_Button_Cycle_Form, KEY_T: SettingKeyboard.Alt_Button_Cycle_Form,
KEY_U: -1, KEY_U: -1,

View File

@ -15,6 +15,5 @@ export enum Button {
CYCLE_NATURE, CYCLE_NATURE,
V, V,
SPEED_UP, SPEED_UP,
SLOW_DOWN, SLOW_DOWN
RANDOMIZE,
} }

View File

@ -34,8 +34,6 @@ export enum SettingKeyboard {
Alt_Button_Cycle_Nature = "ALT_BUTTON_CYCLE_NATURE", Alt_Button_Cycle_Nature = "ALT_BUTTON_CYCLE_NATURE",
Button_Cycle_Variant = "BUTTON_CYCLE_VARIANT", Button_Cycle_Variant = "BUTTON_CYCLE_VARIANT",
Alt_Button_Cycle_Variant = "ALT_BUTTON_CYCLE_VARIANT", Alt_Button_Cycle_Variant = "ALT_BUTTON_CYCLE_VARIANT",
Button_Randomize = "BUTTON_RANDOMIZE",
Alt_Button_Randomize = "ALT_BUTTON_RANDOMIZE",
Button_Speed_Up = "BUTTON_SPEED_UP", Button_Speed_Up = "BUTTON_SPEED_UP",
Alt_Button_Speed_Up = "ALT_BUTTON_SPEED_UP", Alt_Button_Speed_Up = "ALT_BUTTON_SPEED_UP",
Button_Slow_Down = "BUTTON_SLOW_DOWN", Button_Slow_Down = "BUTTON_SLOW_DOWN",
@ -77,8 +75,6 @@ export const settingKeyboardOptions = {
[SettingKeyboard.Alt_Button_Cycle_Nature]: [ `KEY ${Button.CYCLE_NATURE.toString()}`, pressAction ], [SettingKeyboard.Alt_Button_Cycle_Nature]: [ `KEY ${Button.CYCLE_NATURE.toString()}`, pressAction ],
[SettingKeyboard.Button_Cycle_Variant]: [ `KEY ${Button.V.toString()}`, pressAction ], [SettingKeyboard.Button_Cycle_Variant]: [ `KEY ${Button.V.toString()}`, pressAction ],
[SettingKeyboard.Alt_Button_Cycle_Variant]: [ `KEY ${Button.V.toString()}`, pressAction ], [SettingKeyboard.Alt_Button_Cycle_Variant]: [ `KEY ${Button.V.toString()}`, pressAction ],
[SettingKeyboard.Button_Randomize]: [ `KEY ${Button.RANDOMIZE.toString()}`, pressAction ],
[SettingKeyboard.Alt_Button_Randomize]: [ `KEY ${Button.RANDOMIZE.toString()}`, pressAction ],
[SettingKeyboard.Button_Speed_Up]: [ `KEY ${Button.SPEED_UP.toString()}`, pressAction ], [SettingKeyboard.Button_Speed_Up]: [ `KEY ${Button.SPEED_UP.toString()}`, pressAction ],
[SettingKeyboard.Alt_Button_Speed_Up]: [ `KEY ${Button.SPEED_UP.toString()}`, pressAction ], [SettingKeyboard.Alt_Button_Speed_Up]: [ `KEY ${Button.SPEED_UP.toString()}`, pressAction ],
[SettingKeyboard.Button_Slow_Down]: [ `KEY ${Button.SLOW_DOWN.toString()}`, pressAction ], [SettingKeyboard.Button_Slow_Down]: [ `KEY ${Button.SLOW_DOWN.toString()}`, pressAction ],
@ -118,8 +114,6 @@ export const settingKeyboardDefaults = {
[SettingKeyboard.Alt_Button_Cycle_Nature]: 0, [SettingKeyboard.Alt_Button_Cycle_Nature]: 0,
[SettingKeyboard.Button_Cycle_Variant]: 0, [SettingKeyboard.Button_Cycle_Variant]: 0,
[SettingKeyboard.Alt_Button_Cycle_Variant]: 0, [SettingKeyboard.Alt_Button_Cycle_Variant]: 0,
[SettingKeyboard.Button_Randomize]: 0,
[SettingKeyboard.Alt_Button_Randomize]: 0,
[SettingKeyboard.Button_Speed_Up]: 0, [SettingKeyboard.Button_Speed_Up]: 0,
[SettingKeyboard.Alt_Button_Speed_Up]: 0, [SettingKeyboard.Alt_Button_Speed_Up]: 0,
[SettingKeyboard.Button_Slow_Down]: 0, [SettingKeyboard.Button_Slow_Down]: 0,
@ -155,7 +149,6 @@ export function setSettingKeyboard(scene: BattleScene, setting: SettingKeyboard,
case SettingKeyboard.Button_Cycle_Ability: case SettingKeyboard.Button_Cycle_Ability:
case SettingKeyboard.Button_Cycle_Nature: case SettingKeyboard.Button_Cycle_Nature:
case SettingKeyboard.Button_Cycle_Variant: case SettingKeyboard.Button_Cycle_Variant:
case SettingKeyboard.Button_Randomize:
case SettingKeyboard.Button_Speed_Up: case SettingKeyboard.Button_Speed_Up:
case SettingKeyboard.Button_Slow_Down: case SettingKeyboard.Button_Slow_Down:
case SettingKeyboard.Alt_Button_Up: case SettingKeyboard.Alt_Button_Up:
@ -172,7 +165,6 @@ export function setSettingKeyboard(scene: BattleScene, setting: SettingKeyboard,
case SettingKeyboard.Alt_Button_Cycle_Ability: case SettingKeyboard.Alt_Button_Cycle_Ability:
case SettingKeyboard.Alt_Button_Cycle_Nature: case SettingKeyboard.Alt_Button_Cycle_Nature:
case SettingKeyboard.Alt_Button_Cycle_Variant: case SettingKeyboard.Alt_Button_Cycle_Variant:
case SettingKeyboard.Alt_Button_Randomize:
case SettingKeyboard.Alt_Button_Speed_Up: case SettingKeyboard.Alt_Button_Speed_Up:
case SettingKeyboard.Alt_Button_Slow_Down: case SettingKeyboard.Alt_Button_Slow_Down:
case SettingKeyboard.Alt_Button_Submit: case SettingKeyboard.Alt_Button_Submit:

View File

@ -79,7 +79,6 @@ export class UiInputs {
[Button.SUBMIT]: () => this.buttonTouch(), [Button.SUBMIT]: () => this.buttonTouch(),
[Button.ACTION]: () => this.buttonAb(Button.ACTION), [Button.ACTION]: () => this.buttonAb(Button.ACTION),
[Button.CANCEL]: () => this.buttonAb(Button.CANCEL), [Button.CANCEL]: () => this.buttonAb(Button.CANCEL),
[Button.RANDOMIZE]: () => this.buttonAb(Button.RANDOMIZE),
[Button.MENU]: () => this.buttonMenu(), [Button.MENU]: () => this.buttonMenu(),
[Button.STATS]: () => this.buttonGoToFilter(Button.STATS), [Button.STATS]: () => this.buttonGoToFilter(Button.STATS),
[Button.CYCLE_SHINY]: () => this.buttonCycleOption(Button.CYCLE_SHINY), [Button.CYCLE_SHINY]: () => this.buttonCycleOption(Button.CYCLE_SHINY),
@ -111,7 +110,6 @@ export class UiInputs {
[Button.CYCLE_ABILITY]: () => undefined, [Button.CYCLE_ABILITY]: () => undefined,
[Button.CYCLE_NATURE]: () => undefined, [Button.CYCLE_NATURE]: () => undefined,
[Button.V]: () => this.buttonInfo(false), [Button.V]: () => this.buttonInfo(false),
[Button.RANDOMIZE]: () => undefined,
[Button.SPEED_UP]: () => undefined, [Button.SPEED_UP]: () => undefined,
[Button.SLOW_DOWN]: () => undefined, [Button.SLOW_DOWN]: () => undefined,
}; };

View File

@ -130,9 +130,10 @@ const valueReductionMax = 2;
const filterBarHeight = 17; const filterBarHeight = 17;
const speciesContainerX = 109; // if team on the RIGHT: 109 / if on the LEFT: 143 const speciesContainerX = 109; // if team on the RIGHT: 109 / if on the LEFT: 143
const teamWindowX = 285; // if team on the RIGHT: 285 / if on the LEFT: 109 const teamWindowX = 285; // if team on the RIGHT: 285 / if on the LEFT: 109
const teamWindowY = 18; const teamWindowY = 38;
const teamWindowWidth = 34; const teamWindowWidth = 34;
const teamWindowHeight = 132; const teamWindowHeight = 107;
const randomSelectionWindowHeight = 20;
/** /**
* Calculates the starter position for a Pokemon of a given UI index * Calculates the starter position for a Pokemon of a given UI index
@ -267,7 +268,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private natureIconElement: Phaser.GameObjects.Sprite; private natureIconElement: Phaser.GameObjects.Sprite;
private variantIconElement: Phaser.GameObjects.Sprite; private variantIconElement: Phaser.GameObjects.Sprite;
private goFilterIconElement: Phaser.GameObjects.Sprite; private goFilterIconElement: Phaser.GameObjects.Sprite;
private randomSelectIconElement: Phaser.GameObjects.Sprite;
private shinyLabel: Phaser.GameObjects.Text; private shinyLabel: Phaser.GameObjects.Text;
private formLabel: Phaser.GameObjects.Text; private formLabel: Phaser.GameObjects.Text;
private genderLabel: Phaser.GameObjects.Text; private genderLabel: Phaser.GameObjects.Text;
@ -275,7 +275,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private natureLabel: Phaser.GameObjects.Text; private natureLabel: Phaser.GameObjects.Text;
private variantLabel: Phaser.GameObjects.Text; private variantLabel: Phaser.GameObjects.Text;
private goFilterLabel: Phaser.GameObjects.Text; private goFilterLabel: Phaser.GameObjects.Text;
private randomSelectLabel: Phaser.GameObjects.Text;
private starterSelectMessageBox: Phaser.GameObjects.NineSlice; private starterSelectMessageBox: Phaser.GameObjects.NineSlice;
private starterSelectMessageBoxContainer: Phaser.GameObjects.Container; private starterSelectMessageBoxContainer: Phaser.GameObjects.Container;
@ -320,6 +319,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private starterIconsCursorObj: Phaser.GameObjects.Image; private starterIconsCursorObj: Phaser.GameObjects.Image;
private valueLimitLabel: Phaser.GameObjects.Text; private valueLimitLabel: Phaser.GameObjects.Text;
private startCursorObj: Phaser.GameObjects.NineSlice; private startCursorObj: Phaser.GameObjects.NineSlice;
private randomCursorObj: Phaser.GameObjects.NineSlice;
private iconAnimHandler: PokemonIconAnimHandler; private iconAnimHandler: PokemonIconAnimHandler;
@ -368,8 +368,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
starterContainerBg.setOrigin(0, 0); starterContainerBg.setOrigin(0, 0);
this.starterSelectContainer.add(starterContainerBg); this.starterSelectContainer.add(starterContainerBg);
this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY, teamWindowWidth, teamWindowHeight)); this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY - randomSelectionWindowHeight, teamWindowWidth, randomSelectionWindowHeight, true));
this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY + teamWindowHeight - 5, teamWindowWidth, teamWindowWidth, true)); this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY, teamWindowWidth, teamWindowHeight ));
this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY + teamWindowHeight, teamWindowWidth, teamWindowWidth, true));
this.starterSelectContainer.add(starterContainerWindow); this.starterSelectContainer.add(starterContainerWindow);
// Create and initialise filter bar // Create and initialise filter bar
@ -607,6 +608,15 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.startCursorObj.setOrigin(0, 0); this.startCursorObj.setOrigin(0, 0);
this.starterSelectContainer.add(this.startCursorObj); this.starterSelectContainer.add(this.startCursorObj);
const randomSelectLabel = addTextObject(this.scene, teamWindowX + 17, 23, i18next.t("starterSelectUiHandler:randomize"), TextStyle.TOOLTIP_CONTENT);
randomSelectLabel.setOrigin(0.5, 0);
this.starterSelectContainer.add(randomSelectLabel);
this.randomCursorObj = this.scene.add.nineslice(teamWindowX + 4, 21, "select_cursor", undefined, 26, 15, 6, 6, 6, 6);
this.randomCursorObj.setVisible(false);
this.randomCursorObj.setOrigin(0, 0);
this.starterSelectContainer.add(this.randomCursorObj);
const starterSpecies: Species[] = []; const starterSpecies: Species[] = [];
const starterBoxContainer = this.scene.add.container(speciesContainerX + 6, 9); //115 const starterBoxContainer = this.scene.add.container(speciesContainerX + 6, 9); //115
@ -865,13 +875,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.goFilterLabel = addTextObject(this.scene, this.filterInstructionRowX + this.instructionRowTextOffset, this.filterInstructionRowY, i18next.t("starterSelectUiHandler:goFilter"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.goFilterLabel = addTextObject(this.scene, this.filterInstructionRowX + this.instructionRowTextOffset, this.filterInstructionRowY, i18next.t("starterSelectUiHandler:goFilter"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.goFilterLabel.setName("text-goFilter-label"); this.goFilterLabel.setName("text-goFilter-label");
this.randomSelectIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "Q.png");
this.randomSelectIconElement.setName("sprite-random-icon-element");
this.randomSelectIconElement.setScale(0.675);
this.randomSelectIconElement.setOrigin(0.0, 0.0);
this.randomSelectLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:randomize"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.randomSelectLabel.setName("text-random-label");
this.hideInstructions(); this.hideInstructions();
this.filterInstructionsContainer = this.scene.add.container(50, 5); this.filterInstructionsContainer = this.scene.add.container(50, 5);
@ -1346,9 +1349,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.starterIconsCursorIndex = this.starterSpecies.length - 1; this.starterIconsCursorIndex = this.starterSpecies.length - 1;
this.moveStarterIconsCursor(this.starterIconsCursorIndex); this.moveStarterIconsCursor(this.starterIconsCursorIndex);
} else { } else {
//TODO how can we get here if start button can't be selected? this is reduantant shoudld i renmove this?
this.startCursorObj.setVisible(false); this.startCursorObj.setVisible(false);
this.filterBarCursor = Math.max(1, this.filterBar.numFilters - 1); this.randomCursorObj.setVisible(true);
this.setFilterMode(true);
} }
success = true; success = true;
break; break;
@ -1395,14 +1398,20 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
case Button.UP: case Button.UP:
if (this.filterBar.openDropDown) { if (this.filterBar.openDropDown) {
success = this.filterBar.decDropDownCursor(); success = this.filterBar.decDropDownCursor();
} else if (this.filterBarCursor === this.filterBar.numFilters - 1 && this.starterSpecies.length > 0) { } else if (this.filterBarCursor === this.filterBar.numFilters - 1 ) {
// UP from the last filter, move to start button // UP from the last filter, move to start button
this.setFilterMode(false); if (this.starterSpecies.length > 0) {
this.cursorObj.setVisible(false); this.setFilterMode(false);
this.startCursorObj.setVisible(true); this.cursorObj.setVisible(false);
this.startCursorObj.setVisible(true);
} else {
this.setFilterMode(false);
this.cursorObj.setVisible(false);
this.randomCursorObj.setVisible(true);
}
success = true; success = true;
} else if (numberOfStarters > 0) { } else if (numberOfStarters > 0) {
// UP from filter bar to bottom of Pokemon list // UP from filter bar to bottom of Pokemon list
this.setFilterMode(false); this.setFilterMode(false);
this.scrollCursor = Math.max(0, numOfRows - 9); this.scrollCursor = Math.max(0, numOfRows - 9);
this.updateScroll(); this.updateScroll();
@ -1419,12 +1428,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
case Button.DOWN: case Button.DOWN:
if (this.filterBar.openDropDown) { if (this.filterBar.openDropDown) {
success = this.filterBar.incDropDownCursor(); success = this.filterBar.incDropDownCursor();
} else if (this.filterBarCursor === this.filterBar.numFilters - 1 && this.starterSpecies.length > 0) { } else if (this.filterBarCursor === this.filterBar.numFilters - 1) {
// DOWN from the last filter, move to Pokemon in party if any // DOWN from the last filter, move to random selection label
this.setFilterMode(false); this.setFilterMode(false);
this.cursorObj.setVisible(false); this.cursorObj.setVisible(false);
this.starterIconsCursorIndex = 0; this.randomCursorObj.setVisible(true);
this.moveStarterIconsCursor(this.starterIconsCursorIndex);
success = true; success = true;
} else if (numberOfStarters > 0) { } else if (numberOfStarters > 0) {
// DOWN from filter bar to top of Pokemon list // DOWN from filter bar to top of Pokemon list
@ -1446,77 +1454,98 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
success = true; success = true;
break; break;
} }
} else if (button === Button.RANDOMIZE) { } else if (this.randomCursorObj.visible) {
console.log("Attempting random selection from visible starters"); switch (button) {
if (this.starterSpecies.length < 6) { case Button.ACTION:
// Get current party value if (this.starterSpecies.length >= 6) {
const currentPartyValue = this.starterSpecies error = true;
.map(s => s.generation) break;
.reduce((total: number, gen: number, i: number) => }
total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); const currentPartyValue = this.starterSpecies.map(s => s.generation).reduce((total: number, _gen : number, i : number ) => total + this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0);
// Filter valid starters first // Filter valid starters
const validStarters = this.filteredStarterContainers.filter(starter => { const validStarters = this.filteredStarterContainers.filter(starter => {
const species = starter.species; const species = starter.species;
const [ isDupe ] = this.isInParty(species); const [ isDupe ] = this.isInParty(species);
const starterCost = this.scene.gameData.getSpeciesStarterValue(species.speciesId); const starterCost = this.scene.gameData.getSpeciesStarterValue(species.speciesId);
const isValidForChallenge = new BooleanHolder(true); const isValidForChallenge = new BooleanHolder(true);
Challenge.applyChallenges( Challenge.applyChallenges(
this.scene.gameMode, this.scene.gameMode,
Challenge.ChallengeType.STARTER_CHOICE, Challenge.ChallengeType.STARTER_CHOICE,
species,
isValidForChallenge,
this.scene.gameData.getSpeciesDexAttrProps(
species, species,
this.getCurrentDexProps(species.speciesId) isValidForChallenge,
), this.scene.gameData.getSpeciesDexAttrProps(
this.isPartyValid() species,
); this.getCurrentDexProps(species.speciesId)
const isCaught = this.scene.gameData.dexData[species.speciesId].caughtAttr; ),
return !isDupe && this.isPartyValid()
isValidForChallenge.value && );
(currentPartyValue + starterCost <= this.getValueLimit()) && const isCaught = this.scene.gameData.dexData[species.speciesId].caughtAttr;
isCaught; return (
}); !isDupe &&
isValidForChallenge.value &&
if (validStarters.length > 0) { currentPartyValue + starterCost <= this.getValueLimit() &&
// Select random starter from valid options isCaught
const randomIndex = Math.floor(Math.random() * validStarters.length); );
const randomStarter = validStarters[randomIndex]; });
if (validStarters.length === 0) {
error = true; // No valid starters available
break;
}
// Select random starter
const randomStarter = validStarters[Math.floor(Math.random() * validStarters.length)];
const randomSpecies = randomStarter.species; const randomSpecies = randomStarter.species;
// Set species and prepare attributes
// First set the species to load saved preferences and initialize default values
// This triggers the same flow as if the player had moved their cursor to this Pokemon
this.setSpecies(randomSpecies); this.setSpecies(randomSpecies);
// Get the dex attributes after setSpecies has potentially loaded saved preferences
const dexAttr = this.getCurrentDexProps(randomSpecies.speciesId); const dexAttr = this.getCurrentDexProps(randomSpecies.speciesId);
const props = this.scene.gameData.getSpeciesDexAttrProps(randomSpecies, dexAttr); const props = this.scene.gameData.getSpeciesDexAttrProps(randomSpecies, dexAttr);
// Use the current cursor values which now reflect any saved preferences
// these are the same values the player would see in the UI
const abilityIndex = this.abilityCursor; const abilityIndex = this.abilityCursor;
const nature = this.natureCursor as unknown as Nature; const nature = this.natureCursor as unknown as Nature;
const moveset = this.starterMoveset?.slice(0) as StarterMoveset; const moveset = this.starterMoveset?.slice(0) as StarterMoveset;
const starterCost = this.scene.gameData.getSpeciesStarterValue(randomSpecies.speciesId); const starterCost = this.scene.gameData.getSpeciesStarterValue(randomSpecies.speciesId);
const speciesForm = getPokemonSpeciesForm(randomSpecies.speciesId, props.formIndex); const speciesForm = getPokemonSpeciesForm(randomSpecies.speciesId, props.formIndex);
speciesForm.loadAssets(this.scene, props.female, props.formIndex, props.shiny, props.variant, true) // Load assets and add to party
speciesForm
.loadAssets(this.scene, props.female, props.formIndex, props.shiny, props.variant, true)
.then(() => { .then(() => {
if (this.tryUpdateValue(starterCost, true)) { if (this.tryUpdateValue(starterCost, true)) {
// Use addToParty with the same parameters that would be used in manual selection
this.addToParty(randomSpecies, dexAttr, abilityIndex, nature, moveset, true); this.addToParty(randomSpecies, dexAttr, abilityIndex, nature, moveset, true);
console.log("Random starter added to party:", randomSpecies.name, "with cost:", starterCost); ui.playSelect();
success = true;
} }
}); });
} else { break;
// No valid starters available case Button.UP:
error = true; this.randomCursorObj.setVisible(false);
} this.filterBarCursor = this.filterBar.numFilters - 1;
} else { this.setFilterMode(true);
// Party is full success = true;
error = true; break;
case Button.DOWN:
this.randomCursorObj.setVisible(false);
if (this.starterSpecies.length > 0) {
this.starterIconsCursorIndex = 0;
this.moveStarterIconsCursor(this.starterIconsCursorIndex);
} else {
this.filterBarCursor = this.filterBar.numFilters - 1;
this.setFilterMode(true);
}
success = true;
break;
case Button.LEFT:
if (numberOfStarters > 0) {
this.randomCursorObj.setVisible(false);
this.cursorObj.setVisible(true);
this.setCursor(onScreenFirstIndex + 8); // set last column
success = true;
}
break;
case Button.RIGHT:
if (numberOfStarters > 0) {
this.randomCursorObj.setVisible(false);
this.cursorObj.setVisible(true);
this.setCursor(onScreenFirstIndex); // set first column
success = true;
}
break;
} }
} else { } else {
let starterContainer; let starterContainer;
@ -1546,7 +1575,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.lastSpecies, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)), isPartyValid); Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.lastSpecies, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)), isPartyValid);
const currentPartyValue = this.starterSpecies.map(s => s.generation).reduce((total: number, gen: number, i: number) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); const currentPartyValue = this.starterSpecies.map(s => s.generation).reduce((total: number, _gen: number, i: number) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0);
const newCost = this.scene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId); const newCost = this.scene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId);
if (!isDupe && isValidForChallenge.value && currentPartyValue + newCost <= this.getValueLimit() && this.starterSpecies.length < PLAYER_PARTY_MAX_SIZE) { // this checks to make sure the pokemon doesn't exist in your party, it's valid for the challenge and that it won't go over the cost limit; if it meets all these criteria it will add it to your party if (!isDupe && isValidForChallenge.value && currentPartyValue + newCost <= this.getValueLimit() && this.starterSpecies.length < PLAYER_PARTY_MAX_SIZE) { // this checks to make sure the pokemon doesn't exist in your party, it's valid for the challenge and that it won't go over the cost limit; if it meets all these criteria it will add it to your party
options = [ options = [
@ -1685,7 +1714,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
ui.showText(i18next.t("starterSelectUiHandler:selectNature"), null, () => { ui.showText(i18next.t("starterSelectUiHandler:selectNature"), null, () => {
const natures = this.scene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); const natures = this.scene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr);
ui.setModeWithoutClear(Mode.OPTION_SELECT, { ui.setModeWithoutClear(Mode.OPTION_SELECT, {
options: natures.map((n: Nature, i: number) => { options: natures.map((n: Nature, _i: number) => {
const option: OptionSelectItem = { const option: OptionSelectItem = {
label: getNatureName(n, true, true, true, this.scene.uiTheme), label: getNatureName(n, true, true, true, this.scene.uiTheme),
handler: () => { handler: () => {
@ -2096,11 +2125,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
} }
} else { } else {
if (this.starterIconsCursorIndex === 0) { if (this.starterIconsCursorIndex === 0) {
// Up from first Pokemon in the team > go to filter // Up from first Pokemon in the team > go to Random selection
this.starterIconsCursorObj.setVisible(false); this.starterIconsCursorObj.setVisible(false);
this.setSpecies(null); this.setSpecies(null);
this.filterBarCursor = Math.max(1, this.filterBar.numFilters - 1); this.randomCursorObj.setVisible(true);
this.setFilterMode(true);
} else { } else {
this.starterIconsCursorIndex--; this.starterIconsCursorIndex--;
this.moveStarterIconsCursor(this.starterIconsCursorIndex); this.moveStarterIconsCursor(this.starterIconsCursorIndex);
@ -2145,9 +2173,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
success = this.setCursor(this.cursor - 1); success = this.setCursor(this.cursor - 1);
} else { } else {
// LEFT from filtered Pokemon, on the left edge // LEFT from filtered Pokemon, on the left edge
if ( onScreenCurrentRow === 0 ) {
if (this.starterSpecies.length === 0) { // from the first row of starters we go to the random selection
// no starter in team > wrap around to the last column this.cursorObj.setVisible(false);
this.randomCursorObj.setVisible(true);
} else if (this.starterSpecies.length === 0) {
// no starter in team and not on first row > wrap around to the last column
success = this.setCursor(this.cursor + Math.min(8, numberOfStarters - this.cursor)); success = this.setCursor(this.cursor + Math.min(8, numberOfStarters - this.cursor));
} else if (onScreenCurrentRow < 7) { } else if (onScreenCurrentRow < 7) {
@ -2183,7 +2214,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
success = this.setCursor(this.cursor + 1); success = this.setCursor(this.cursor + 1);
} else { } else {
// RIGHT from filtered Pokemon, on the right edge // RIGHT from filtered Pokemon, on the right edge
if (this.starterSpecies.length === 0) { if ( onScreenCurrentRow === 0 ) {
// from the first row of starters we go to the random selection
this.cursorObj.setVisible(false);
this.randomCursorObj.setVisible(true);
} else if (this.starterSpecies.length === 0) {
// no selected starter in team > wrap around to the first column // no selected starter in team > wrap around to the first column
success = this.setCursor(this.cursor - Math.min(8, this.cursor % 9)); success = this.setCursor(this.cursor - Math.min(8, this.cursor % 9));
@ -2335,9 +2370,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
case SettingKeyboard.Button_Stats: case SettingKeyboard.Button_Stats:
iconPath = "C.png"; iconPath = "C.png";
break; break;
case SettingKeyboard.Button_Randomize:
iconPath = "Q.png";
break;
default: default:
break; break;
} }
@ -2423,10 +2455,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
// if filter mode is inactivated and gamepadType is not undefined, update the button icons // if filter mode is inactivated and gamepadType is not undefined, update the button icons
if (!this.filterMode) { if (!this.filterMode) {
this.updateFilterButtonIcon(SettingKeyboard.Button_Stats, gamepadType, this.goFilterIconElement, this.goFilterLabel); this.updateFilterButtonIcon(SettingKeyboard.Button_Stats, gamepadType, this.goFilterIconElement, this.goFilterLabel);
this.updateButtonIcon(SettingKeyboard.Button_Randomize, gamepadType, this.randomSelectIconElement, this.randomSelectLabel); // random icon only appears not in filter mode
} }
} }
getValueLimit(): number { getValueLimit(): number {
@ -3086,7 +3116,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.dexAttrCursor = 0n; this.dexAttrCursor = 0n;
this.abilityCursor = -1; this.abilityCursor = -1;
this.natureCursor = -1; this.natureCursor = -1;
// We will only update the sprite if there is a change to form, shiny/variant // We will only update the sprite if there is a change to form, shiny/variant
// or gender for species with gender sprite differences // or gender for species with gender sprite differences
const shouldUpdateSprite = (species?.genderDiffs && !isNullOrUndefined(female)) const shouldUpdateSprite = (species?.genderDiffs && !isNullOrUndefined(female))
@ -3516,7 +3545,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
} }
tryUpdateValue(add?: integer, addingToParty?: boolean): boolean { tryUpdateValue(add?: integer, addingToParty?: boolean): boolean {
const value = this.starterSpecies.map(s => s.generation).reduce((total: integer, gen: integer, i: integer) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); const value = this.starterSpecies.map(s => s.generation).reduce((total: integer, _gen: integer, i: integer) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0);
const newValue = value + (add || 0); const newValue = value + (add || 0);
const valueLimit = this.getValueLimit(); const valueLimit = this.getValueLimit();
const overLimit = newValue > valueLimit; const overLimit = newValue > valueLimit;
@ -3619,6 +3648,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (!this.starterSpecies.length) { if (!this.starterSpecies.length) {
return false; return false;
} }
console.log("reached tryStart");
const ui = this.getUi(); const ui = this.getUi();
@ -3779,8 +3809,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.variantLabel.setVisible(false); this.variantLabel.setVisible(false);
this.goFilterIconElement.setVisible(false); this.goFilterIconElement.setVisible(false);
this.goFilterLabel.setVisible(false); this.goFilterLabel.setVisible(false);
this.randomSelectIconElement.setVisible(false);
this.randomSelectLabel.setVisible(false);
} }
clear(): void { clear(): void {