Use DexTypes#names() where applicable

This commit is contained in:
Kris Johnson 2024-11-10 20:32:24 -07:00
parent 57b65e03a8
commit 63ca4e2c81
6 changed files with 24 additions and 27 deletions

View File

@ -297,7 +297,7 @@ export default class TeamGenerator {
let types = nonStatusMoves.map(move => TeamGenerator.moveType(this.dex.moves.get(move), species));
const noStellar = ability === 'Adaptability' || new Set(types).size < 3;
if (hasTeraBlast || hasRevelationDance || !nonStatusMoves.length) {
types = [...this.dex.types.all().map(t => t.name)];
types = [...this.dex.types.names()];
if (noStellar) types.splice(types.indexOf('Stellar'));
} else {
if (!noStellar) types.push('Stellar');
@ -327,23 +327,23 @@ export default class TeamGenerator {
*/
protected speciesIsGoodFit(species: Species, stats: TeamStats): boolean {
// type check
for (const type of this.dex.types.all()) {
const effectiveness = this.dex.getEffectiveness(type.name, species.types);
for (const typeName of this.dex.types.names()) {
const effectiveness = this.dex.getEffectiveness(typeName, species.types);
if (effectiveness === 1) { // WEAKNESS!
if (stats.typeWeaknesses[type.name] === undefined) {
stats.typeWeaknesses[type.name] = 0;
if (stats.typeWeaknesses[typeName] === undefined) {
stats.typeWeaknesses[typeName] = 0;
}
if (stats.typeWeaknesses[type.name] >= MAX_WEAK_TO_SAME_TYPE) {
if (stats.typeWeaknesses[typeName] >= MAX_WEAK_TO_SAME_TYPE) {
// too many weaknesses to this type
return false;
}
}
}
// species passes; increment counters
for (const type of this.dex.types.all()) {
const effectiveness = this.dex.getEffectiveness(type.name, species.types);
for (const typeName of this.dex.types.names()) {
const effectiveness = this.dex.getEffectiveness(typeName, species.types);
if (effectiveness === 1) {
stats.typeWeaknesses[type.name]++;
stats.typeWeaknesses[typeName]++;
}
}
return true;

View File

@ -384,11 +384,11 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
if (!lastMove) return false;
const possibleTypes = [];
const attackType = lastMove.type;
for (const type of this.dex.types.all()) {
if (source.hasType(type.name)) continue;
const typeCheck = type.damageTaken[attackType];
for (const typeName of this.dex.types.names()) {
if (source.hasType(typeName)) continue;
const typeCheck = this.dex.types.get(typeName).damageTaken[attackType];
if (typeCheck === 2 || typeCheck === 3) {
possibleTypes.push(type.name);
possibleTypes.push(typeName);
}
}
if (!possibleTypes.length) {

View File

@ -85,12 +85,9 @@ export function changeSet(context: Battle, pokemon: Pokemon, newSet: SSBSet, cha
if (newSet.species === 'Shedinja') percent = 1;
pokemon.formeChange(newSet.species, context.effect, true);
if (!pokemon.terastallized && newSet.teraType) {
const allTypes = context.dex.types.all().map(x => x.name);
pokemon.teraType = newSet.teraType === 'Any' ?
allTypes[Math.floor(Math.random() * allTypes.length)] :
Array.isArray(newSet.teraType) ?
newSet.teraType[Math.floor(Math.random() * newSet.teraType.length)] :
newSet.teraType;
const allTypes = context.dex.types.names();
pokemon.teraType = newSet.teraType === 'Any' ? context.sample(allTypes) :
Array.isArray(newSet.teraType) ? context.sample(newSet.teraType) : newSet.teraType;
}
const details = pokemon.species.name + (pokemon.level === 100 ? '' : ', L' + pokemon.level) +
(pokemon.gender === '' ? '' : ', ' + pokemon.gender) + (pokemon.set.shiny ? ', shiny' : '');

View File

@ -2908,11 +2908,11 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
}
const possibleTypes = [];
const attackType = target.lastMoveUsed.type;
for (const type of this.dex.types.all()) {
if (source.hasType(type.name)) continue;
const typeCheck = type.damageTaken[attackType];
for (const typeName of this.dex.types.names()) {
if (source.hasType(typeName)) continue;
const typeCheck = this.dex.types.get(typeName).damageTaken[attackType];
if (typeCheck === 2 || typeCheck === 3) {
possibleTypes.push(type.name);
possibleTypes.push(typeName);
}
}
if (!possibleTypes.length) {

View File

@ -526,7 +526,7 @@ export class RandomGen8Teams {
};
if (this.gen === 9) {
// Tera type
set.teraType = this.sample(this.dex.types.all()).name;
set.teraType = this.sample(this.dex.types.names());
}
team.push(set);
}
@ -893,7 +893,7 @@ export class RandomGen8Teams {
};
if (this.gen === 9) {
// Random Tera type
set.teraType = this.sample(this.dex.types.all()).name;
set.teraType = this.sample(this.dex.types.names());
}
team.push(set);
}

View File

@ -1971,7 +1971,7 @@ export class RandomTeams {
if (this.forceTeraType) {
set.teraType = this.forceTeraType;
} else {
set.teraType = this.sample(this.dex.types.all()).name;
set.teraType = this.sample(this.dex.types.names());
}
}
team.push(set);
@ -2345,7 +2345,7 @@ export class RandomTeams {
if (this.forceTeraType) {
set.teraType = this.forceTeraType;
} else {
set.teraType = this.sample(this.dex.types.all()).name;
set.teraType = this.sample(this.dex.types.names());
}
}
team.push(set);