Skip to content

Commit

Permalink
Use DexTypes#names() where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisXV committed Nov 11, 2024
1 parent 57b65e0 commit 63ca4e2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
18 changes: 9 additions & 9 deletions data/cg-teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions data/mods/gen8linked/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 3 additions & 6 deletions data/mods/gen9ssb/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' : '');
Expand Down
8 changes: 4 additions & 4 deletions data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions data/random-battles/gen8/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions data/random-battles/gen9/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 63ca4e2

Please sign in to comment.