So currently if you meet someone with a title it only shows there nam… (#1055)

* So currently if you meet someone with a title it only shows there name and only then the title (not like trainer classes). So i wanted to change that

* The title is not set again to its own value. It is just got differenlty for the nametag (includeTitle true)

* Added the ; as well as some comments that are hopefully helpful for others (i am terrible at writing comments)

* Forgot getTitle for comments
This commit is contained in:
Jannik Tappert 2024-05-19 13:23:24 +02:00 committed by GitHub
parent 6dc10f549f
commit e3b25a9fab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 133 additions and 25 deletions

View File

@ -235,11 +235,10 @@ export class TrainerConfig {
if (!getIsInitialized()) { if (!getIsInitialized()) {
initI18n(); initI18n();
} }
// This is only the male name, because the female name is handled in a different function (setHasGenders)
if (name === 'Finn') { if (name === 'Finn') {
name = i18next.t('trainerNames:rival'); name = i18next.t('trainerNames:rival');
} }
} }
this.name = name; this.name = name;
return this; return this;
@ -254,6 +253,7 @@ export class TrainerConfig {
// Make the title lowercase and replace spaces with underscores // Make the title lowercase and replace spaces with underscores
title = title.toLowerCase().replace(/\s/g, '_'); title = title.toLowerCase().replace(/\s/g, '_');
// Get the title from the i18n file
this.title = i18next.t(`titles:${title}`); this.title = i18next.t(`titles:${title}`);
@ -281,21 +281,40 @@ export class TrainerConfig {
return trainerType; return trainerType;
} }
/**
* Sets the configuration for trainers with genders, including the female name and encounter background music (BGM).
* @param {string} [nameFemale] - The name of the female trainer. If 'Ivy', a localized name will be assigned.
* @param {TrainerType | string} [femaleEncounterBgm] - The encounter BGM for the female trainer, which can be a TrainerType or a string.
* @returns {TrainerConfig} - The updated TrainerConfig instance.
**/
setHasGenders(nameFemale?: string, femaleEncounterBgm?: TrainerType | string): TrainerConfig { setHasGenders(nameFemale?: string, femaleEncounterBgm?: TrainerType | string): TrainerConfig {
// If the female name is 'Ivy' (the rival), assign a localized name.
if (nameFemale === 'Ivy') { if (nameFemale === 'Ivy') {
// Give the rival a localized name // Check if the internationalization (i18n) system is initialized.
// First check if i18n is initialized
if (!getIsInitialized()) { if (!getIsInitialized()) {
// Initialize the i18n system if it is not already initialized.
initI18n(); initI18n();
} }
this.nameFemale = i18next.t('trainerNames:rival_female'); // Set the localized name for the female rival.
} else { this.nameFemale = i18next.t('trainerNames:rival_female');
} else {
// Otherwise, assign the provided female name.
this.nameFemale = nameFemale; this.nameFemale = nameFemale;
} }
// Indicate that this trainer configuration includes genders.
this.hasGenders = true; this.hasGenders = true;
if (femaleEncounterBgm)
this.femaleEncounterBgm = typeof femaleEncounterBgm === 'number' ? TrainerType[femaleEncounterBgm].toString().replace(/\_/g, ' ').toLowerCase() : femaleEncounterBgm; // If a female encounter BGM is provided.
if (femaleEncounterBgm) {
// If the BGM is a TrainerType (number), convert it to a string, replace underscores with spaces, and convert to lowercase.
// Otherwise, assign the provided string as the BGM.
this.femaleEncounterBgm = typeof femaleEncounterBgm === 'number'
? TrainerType[femaleEncounterBgm].toString().replace(/_/g, ' ').toLowerCase()
: femaleEncounterBgm;
}
// Return the updated TrainerConfig instance.
return this; return this;
} }
@ -398,29 +417,44 @@ export class TrainerConfig {
return this; return this;
} }
/**
* Initializes the trainer configuration for a Gym Leader.
* @param {Species | Species[]} signatureSpecies - The signature species for the Gym Leader.
* @param {Type[]} specialtyTypes - The specialty types for the Gym Leader.
* @returns {TrainerConfig} - The updated TrainerConfig instance.
* **/
initForGymLeader(signatureSpecies: (Species | Species[])[], ...specialtyTypes: Type[]): TrainerConfig { initForGymLeader(signatureSpecies: (Species | Species[])[], ...specialtyTypes: Type[]): TrainerConfig {
// Check if the internationalization (i18n) system is initialized.
if (!getIsInitialized()) { if (!getIsInitialized()) {
initI18n(); initI18n();
} }
// Set the function to generate the Gym Leader's party template.
this.setPartyTemplateFunc(getGymLeaderPartyTemplate); this.setPartyTemplateFunc(getGymLeaderPartyTemplate);
// Set up party members with their corresponding species.
signatureSpecies.forEach((speciesPool, s) => { signatureSpecies.forEach((speciesPool, s) => {
// Ensure speciesPool is an array.
if (!Array.isArray(speciesPool)) if (!Array.isArray(speciesPool))
speciesPool = [speciesPool]; speciesPool = [speciesPool];
// Set a function to get a random party member from the species pool.
this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool)); this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool));
}); });
// If specialty types are provided, set species filter and specialty types.
if (specialtyTypes.length) { if (specialtyTypes.length) {
this.setSpeciesFilter(p => specialtyTypes.find(t => p.isOfType(t)) !== undefined); this.setSpeciesFilter(p => specialtyTypes.find(t => p.isOfType(t)) !== undefined);
this.setSpecialtyTypes(...specialtyTypes); this.setSpecialtyTypes(...specialtyTypes);
} }
// Handle name by checking this.name - making it lowercase and replacing spaces with underscores and then calling i18next.t with the name // Localize the trainer's name by converting it to lowercase and replacing spaces with underscores.
const nameForCall = this.name.toLowerCase().replace(/\s/g, '_'); const nameForCall = this.name.toLowerCase().replace(/\s/g, '_');
this.name = i18next.t(`trainerNames:${nameForCall}`); this.name = i18next.t(`trainerNames:${nameForCall}`);
// Set the title to "gym_leader". (this is the key in the i18n file)
this.setTitle('gym_leader');
// Configure various properties for the Gym Leader.
this.setTitle("gym_leader");
this.setMoneyMultiplier(2.5); this.setMoneyMultiplier(2.5);
this.setBoss(); this.setBoss();
this.setStaticParty(); this.setStaticParty();
@ -430,75 +464,125 @@ export class TrainerConfig {
const waveIndex = party[0].scene.currentBattle.waveIndex; const waveIndex = party[0].scene.currentBattle.waveIndex;
return getRandomTeraModifiers(party, waveIndex >= 100 ? 1 : 0, specialtyTypes.length ? specialtyTypes : null); return getRandomTeraModifiers(party, waveIndex >= 100 ? 1 : 0, specialtyTypes.length ? specialtyTypes : null);
}); });
return this; return this;
} }
/**
* Initializes the trainer configuration for an Elite Four member.
* @param {Species | Species[]} signatureSpecies - The signature species for the Elite Four member.
* @param {Type[]} specialtyTypes - The specialty types for the Elite Four member.
* @returns {TrainerConfig} - The updated TrainerConfig instance.
**/
initForEliteFour(signatureSpecies: (Species | Species[])[], ...specialtyTypes: Type[]): TrainerConfig { initForEliteFour(signatureSpecies: (Species | Species[])[], ...specialtyTypes: Type[]): TrainerConfig {
// Check if the internationalization (i18n) system is initialized.
if (!getIsInitialized()) { if (!getIsInitialized()) {
initI18n(); initI18n();
} }
// Set the party templates for the Elite Four.
this.setPartyTemplates(trainerPartyTemplates.ELITE_FOUR); this.setPartyTemplates(trainerPartyTemplates.ELITE_FOUR);
// Set up party members with their corresponding species.
signatureSpecies.forEach((speciesPool, s) => { signatureSpecies.forEach((speciesPool, s) => {
// Ensure speciesPool is an array.
if (!Array.isArray(speciesPool)) if (!Array.isArray(speciesPool))
speciesPool = [speciesPool]; speciesPool = [speciesPool];
// Set a function to get a random party member from the species pool.
this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool)); this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool));
}); });
// Set species filter and specialty types if provided, otherwise filter by base total.
if (specialtyTypes.length) { if (specialtyTypes.length) {
this.setSpeciesFilter(p => specialtyTypes.find(t => p.isOfType(t)) && p.baseTotal >= 450); this.setSpeciesFilter(p => specialtyTypes.find(t => p.isOfType(t)) && p.baseTotal >= 450);
this.setSpecialtyTypes(...specialtyTypes); this.setSpecialtyTypes(...specialtyTypes);
} else } else {
this.setSpeciesFilter(p => p.baseTotal >= 450); this.setSpeciesFilter(p => p.baseTotal >= 450);
// Handle name by checking this.name - making it lowercase and replacing spaces with underscores and then calling i18next.t with the name }
// Localize the trainer's name by converting it to lowercase and replacing spaces with underscores.
const nameForCall = this.name.toLowerCase().replace(/\s/g, '_'); const nameForCall = this.name.toLowerCase().replace(/\s/g, '_');
this.name = i18next.t(`trainerNames:${nameForCall}`); this.name = i18next.t(`trainerNames:${nameForCall}`);
this.setTitle("elite_four"); // Set the title to "elite_four". (this is the key in the i18n file)
this.setTitle('elite_four');
// Configure various properties for the Elite Four member.
this.setMoneyMultiplier(3.25); this.setMoneyMultiplier(3.25);
this.setBoss(); this.setBoss();
this.setStaticParty(); this.setStaticParty();
this.setBattleBgm('battle_elite'); this.setBattleBgm('battle_elite');
this.setVictoryBgm('victory_gym'); this.setVictoryBgm('victory_gym');
this.setGenModifiersFunc(party => getRandomTeraModifiers(party, 2, specialtyTypes.length ? specialtyTypes : null)); this.setGenModifiersFunc(party => getRandomTeraModifiers(party, 2, specialtyTypes.length ? specialtyTypes : null));
return this; return this;
} }
/**
* Initializes the trainer configuration for a Champion.
* @param {Species | Species[]} signatureSpecies - The signature species for the Champion.
* @returns {TrainerConfig} - The updated TrainerConfig instance.
**/
initForChampion(signatureSpecies: (Species | Species[])[]): TrainerConfig { initForChampion(signatureSpecies: (Species | Species[])[]): TrainerConfig {
// Check if the internationalization (i18n) system is initialized.
if (!getIsInitialized()) { if (!getIsInitialized()) {
initI18n(); initI18n();
} }
// Set the party templates for the Champion.
this.setPartyTemplates(trainerPartyTemplates.CHAMPION); this.setPartyTemplates(trainerPartyTemplates.CHAMPION);
// Set up party members with their corresponding species.
signatureSpecies.forEach((speciesPool, s) => { signatureSpecies.forEach((speciesPool, s) => {
// Ensure speciesPool is an array.
if (!Array.isArray(speciesPool)) if (!Array.isArray(speciesPool))
speciesPool = [speciesPool]; speciesPool = [speciesPool];
// Set a function to get a random party member from the species pool.
this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool)); this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool));
}); });
// Set species filter to only include species with a base total of 470 or higher.
this.setSpeciesFilter(p => p.baseTotal >= 470); this.setSpeciesFilter(p => p.baseTotal >= 470);
// Handle name by checking this.name - making it lowercase and replacing spaces with underscores and then calling i18next.t with the name
// Localize the trainer's name by converting it to lowercase and replacing spaces with underscores.
const nameForCall = this.name.toLowerCase().replace(/\s/g, '_'); const nameForCall = this.name.toLowerCase().replace(/\s/g, '_');
this.name = i18next.t(`trainerNames:${nameForCall}`); this.name = i18next.t(`trainerNames:${nameForCall}`);
this.setTitle("champion");
// Set the title to "champion". (this is the key in the i18n file)
this.setTitle('champion');
// Configure various properties for the Champion.
this.setMoneyMultiplier(10); this.setMoneyMultiplier(10);
this.setBoss(); this.setBoss();
this.setStaticParty(); this.setStaticParty();
this.setBattleBgm('battle_champion_alder'); this.setBattleBgm('battle_champion_alder');
this.setVictoryBgm('victory_champion'); this.setVictoryBgm('victory_champion');
this.setGenModifiersFunc(party => getRandomTeraModifiers(party, 3)); this.setGenModifiersFunc(party => getRandomTeraModifiers(party, 3));
return this; return this;
} }
/**
* Retrieves the title for the trainer based on the provided trainer slot and variant.
* @param {TrainerSlot} trainerSlot - The slot to determine which title to use. Defaults to TrainerSlot.NONE.
* @param {TrainerVariant} variant - The variant of the trainer to determine the specific title.
* @returns {string} - The title of the trainer.
**/
getTitle(trainerSlot: TrainerSlot = TrainerSlot.NONE, variant: TrainerVariant): string { getTitle(trainerSlot: TrainerSlot = TrainerSlot.NONE, variant: TrainerVariant): string {
let ret = this.name; let ret = this.name;
// Check if the variant is double and the name for double exists
if (!trainerSlot && variant === TrainerVariant.DOUBLE && this.nameDouble) if (!trainerSlot && variant === TrainerVariant.DOUBLE && this.nameDouble)
return this.nameDouble; return this.nameDouble;
// Female variant
if (this.hasGenders) { if (this.hasGenders) {
// If the name is already set
if (this.nameFemale) { if (this.nameFemale) {
// Check if the variant is either female or this is for the partner in a double battle
if (variant === TrainerVariant.FEMALE || (variant === TrainerVariant.DOUBLE && trainerSlot === TrainerSlot.TRAINER_PARTNER)) if (variant === TrainerVariant.FEMALE || (variant === TrainerVariant.DOUBLE && trainerSlot === TrainerSlot.TRAINER_PARTNER))
return this.nameFemale; return this.nameFemale;
} else } else
// Check if !variant is true, if so return the name, else return the name with _female appended // Check if !variant is true, if so return the name, else return the name with _female appended
if (variant) { if (variant) {
if (!getIsInitialized()) { if (!getIsInitialized()) {

View File

@ -96,30 +96,54 @@ export default class Trainer extends Phaser.GameObjects.Container {
return this.config.getSpriteKey(this.variant === TrainerVariant.FEMALE || forceFemale); return this.config.getSpriteKey(this.variant === TrainerVariant.FEMALE || forceFemale);
} }
/**
* Returns the name of the trainer based on the provided trainer slot and the option to include a title.
* @param {TrainerSlot} trainerSlot - The slot to determine which name to use. Defaults to TrainerSlot.NONE.
* @param {boolean} includeTitle - Whether to include the title in the returned name. Defaults to false.
* @returns {string} - The formatted name of the trainer.
**/
getName(trainerSlot: TrainerSlot = TrainerSlot.NONE, includeTitle: boolean = false): string { getName(trainerSlot: TrainerSlot = TrainerSlot.NONE, includeTitle: boolean = false): string {
// Get the base title based on the trainer slot and variant.
let name = this.config.getTitle(trainerSlot, this.variant); let name = this.config.getTitle(trainerSlot, this.variant);
// Determine the title to include based on the configuration and includeTitle flag.
let title = includeTitle && this.config.title ? this.config.title : null; let title = includeTitle && this.config.title ? this.config.title : null;
// If the trainer has a name (not null or undefined).
if (this.name) { if (this.name) {
if (includeTitle) // If the title should be included.
if (includeTitle) {
// Check if i18n is initialized // Check if the internationalization (i18n) system is initialized.
if (!getIsInitialized()) { if (!getIsInitialized()) {
initI18n() // Initialize the i18n system if it is not already initialized.
initI18n();
} }
// Get the localized trainer class name from the i18n file and set it as the title.
// This is used for trainer class names, not titles like "Elite Four, Champion, etc."
title = i18next.t(`trainerClasses:${name.toLowerCase().replace(/\s/g, '_')}`); title = i18next.t(`trainerClasses:${name.toLowerCase().replace(/\s/g, '_')}`);
}
// If no specific trainer slot is set.
if (!trainerSlot) { if (!trainerSlot) {
// Use the trainer's name.
name = this.name; name = this.name;
if (this.partnerName) // If there is a partner name, concatenate it with the trainer's name using "&".
if (this.partnerName) {
name = `${name} & ${this.partnerName}`; name = `${name} & ${this.partnerName}`;
} else }
} else {
// Assign the name based on the trainer slot:
// Use 'this.name' if 'trainerSlot' is TRAINER.
// Otherwise, use 'this.partnerName' if it exists, or 'this.name' if it doesn't.
name = trainerSlot === TrainerSlot.TRAINER ? this.name : this.partnerName || this.name; name = trainerSlot === TrainerSlot.TRAINER ? this.name : this.partnerName || this.name;
}
} }
// Return the formatted name, including the title if it is set.
return title ? `${title} ${name}` : name; return title ? `${title} ${name}` : name;
} }
isDouble(): boolean { isDouble(): boolean {
return this.config.doubleOnly || this.variant === TrainerVariant.DOUBLE; return this.config.doubleOnly || this.variant === TrainerVariant.DOUBLE;
} }

View File

@ -906,7 +906,7 @@ export class EncounterPhase extends BattlePhase {
const showDialogueAndSummon = () => { const showDialogueAndSummon = () => {
let message: string; let message: string;
this.scene.executeWithSeedOffset(() => message = Utils.randSeedItem(encounterMessages), this.scene.currentBattle.waveIndex); this.scene.executeWithSeedOffset(() => message = Utils.randSeedItem(encounterMessages), this.scene.currentBattle.waveIndex);
this.scene.ui.showDialogue(message, trainer.getName(), null, () => { this.scene.ui.showDialogue(message, trainer.getName(TrainerSlot.NONE,true), null, () => {
this.scene.charSprite.hide().then(() => this.scene.hideFieldOverlay(250).then(() => doSummon())); this.scene.charSprite.hide().then(() => this.scene.hideFieldOverlay(250).then(() => doSummon()));
}); });
}; };