Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pet Mod Support (Alternatium [PMOTS]) #1936

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
142 changes: 133 additions & 9 deletions build-tools/build-indexes
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ function requireNoCache(pathSpec) {
index.push('moves article');

// generate aliases
const usedIDs = [];
function generateAlias(id, name, type) {
usedIDs.push(id);
let i = name.lastIndexOf(' ');
if (i < 0) i = name.lastIndexOf('-');
if (name.endsWith('-Mega-X') || name.endsWith('-Mega-Y')) {
Expand Down Expand Up @@ -224,6 +226,29 @@ function requireNoCache(pathSpec) {
const name = Dex.data.Abilities[id].name;
generateAlias(id, name, 'ability');
}
const infoTable = {Pokedex: 'pokemon', Moves: 'move', Items: 'item', Abilities: 'ability', TypeChart: 'type'};
for (const key in infoTable) {
const pmots = Dex.mod('alternatium');
const leadersChoice = Dex.mod('randomdex');
for (let id in pmots.data[key]) {
if (!pmots.data[key][id]) continue;
if (!usedIDs.includes(toID(id)) && id in Dex.data.TypeChart === false) {
index.push(toID(id) + ' ' + infoTable[key]);
usedIDs.push(toID(id));
const name = pmots.data[key][id].name;
if (name) generateAlias(id, name, infoTable[key]);
}
}
for (let id in leadersChoice.data[key]) {
if (!leadersChoice.data[key][id]) continue;
if (!usedIDs.includes(toID(id)) && id in Dex.data.TypeChart === false) {
index.push(toID(id) + ' ' + infoTable[key]);
usedIDs.push(toID(id));
const name = leadersChoice.data[key][id].name;
if (name) generateAlias(id, name, infoTable[key]);
}
}
}

index.sort();

Expand Down Expand Up @@ -321,12 +346,14 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
const VGC = GENS.filter(x => x > 3).map(num => -num - 0.5);
const NFE = GENS.map(num => num + 0.3);
const STADIUM = [2.04, 1.04];
const OTHER = [8.6, 8.4, 8.2, 8.1, -8.4, -8.6, 7.1];
const OTHER = [8.6, 8.4, 8.2, 8.1, -8.4, -8.6, 7.1, 8.7, 8.8];

// process.stdout.write("\n ");
for (const genIdent of [...GENS, ...DOUBLES, ...VGC, ...NFE, ...STADIUM, ...OTHER]) {
const isLetsGo = (genIdent === 7.1);
const isBDSP = (genIdent === 8.6 || genIdent === -8.6);
const isPMOTS = (genIdent === 8.7);
const isLC = (genIdent === 8.8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LC means little cup in most context, use isPetModLC here please

const isMetBattle = (genIdent === 8.2);
const isNFE = ('' + genIdent).endsWith('.3');
const isDLC1 = (genIdent === 8.4 || genIdent === -8.4);
Expand All @@ -340,6 +367,8 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
if (isDLC1) genStr += 'dlc1';
if (isLetsGo) genStr += 'letsgo';
if (isBDSP) genStr += 'bdsp';
if (isPMOTS) genStr = 'alternatium';
if (isLC) genStr = 'randomdex';
if (isStadium) genStr += 'stadium' + (genNum > 1 ? genNum : '');
return genStr;
})();
Expand Down Expand Up @@ -516,6 +545,22 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
BattleTeambuilderTable['gen8bdsp'].overrideTier = overrideTier;
BattleTeambuilderTable['gen8bdsp'].monotypeBans = monotypeBans;
BattleTeambuilderTable['gen8bdsp'].formatSlices = formatSlices;
} else if (isPMOTS) {
BattleTeambuilderTable['alternatium'] = {};
BattleTeambuilderTable['alternatium'].learnsets = {};
BattleTeambuilderTable['alternatium'].tiers = tiers;
BattleTeambuilderTable['alternatium'].items = items;
BattleTeambuilderTable['alternatium'].overrideTier = overrideTier;
BattleTeambuilderTable['alternatium'].monotypeBans = monotypeBans;
BattleTeambuilderTable['alternatium'].formatSlices = formatSlices;
} else if (isLC) {
BattleTeambuilderTable['randomdex'] = {};
BattleTeambuilderTable['randomdex'].learnsets = {};
BattleTeambuilderTable['randomdex'].tiers = tiers;
BattleTeambuilderTable['randomdex'].items = items;
BattleTeambuilderTable['randomdex'].overrideTier = overrideTier;
BattleTeambuilderTable['randomdex'].monotypeBans = monotypeBans;
BattleTeambuilderTable['randomdex'].formatSlices = formatSlices;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make these tables just say 'pmots' and 'petmodlc'

} else if (isVGC) {
BattleTeambuilderTable[gen + 'vgc'] = {};
BattleTeambuilderTable[gen + 'vgc'].tiers = tiers;
Expand Down Expand Up @@ -555,6 +600,9 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
if (isLetsGo) {
return ["Uber", "OU", "UU", "NFE", "LC"];
}
if (isPMOTS) {
return ["OU"];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt necessary, it uses the default gen 8 table (which includes OU)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Alternatium's case, it only contains OU mons, so this is necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it’s not, look at how nfe does it

if (isBDSP && !isDoubles) {
return ["CAP", "CAP NFE", "CAP LC", "Uber", "(Uber)", "OU", "UUBL", "UU", "RUBL", "RU", "NUBL", "NU", "NFE", "LC", "Unreleased"];
}
Expand Down Expand Up @@ -906,14 +954,22 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
BattleTeambuilderTable['gen7letsgo'].learnsets[id][moveid] = '7';
}
}
const BDSPLearnsets = Dex.mod('gen8bdsp').data.Learnsets;
for (const id in BDSPLearnsets) {
const species = Dex.mod('gen8bdsp').species.get(id);
if (species.isNonstandard && !['Unobtainable', 'CAP'].includes(species.isNonstandard)) continue;
const learnset = BDSPLearnsets[id].learnset;
BattleTeambuilderTable['gen8bdsp'].learnsets[id] = {};
const PMOTSLearnsets = Dex.mod('alternatium').data.Learnsets;
for (const id in PMOTSLearnsets) {
const species = Dex.mod('alternatium').species.get(id);
const learnset = PMOTSLearnsets[id].learnset;
BattleTeambuilderTable['alternatium'].learnsets[id] = {};
for (const moveid in learnset) {
BattleTeambuilderTable['alternatium'].learnsets[id][moveid] = '8';
}
}
const LCLearnsets = Dex.mod('randomdex').data.Learnsets;
for (const id in LCLearnsets) {
const species = Dex.mod('randomdex').species.get(id);
const learnset = LCLearnsets[id].learnset;
BattleTeambuilderTable['randomdex'].learnsets[id] = {};
for (const moveid in learnset) {
BattleTeambuilderTable['gen8bdsp'].learnsets[id][moveid] = '8g';
BattleTeambuilderTable['randomdex'].learnsets[id][moveid] = '8';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

._. why are you removing bdsp support

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I overlooked that

}
}
const DLC1Learnsets = Dex.mod('gen8dlc1').data.Learnsets;
Expand Down Expand Up @@ -1046,7 +1102,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
// Mods
//

for (const mod of ['gen7letsgo', 'gen8bdsp']) {
for (const mod of ['gen7letsgo', 'gen8bdsp', 'alternatium', 'randomdex']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more server-side, but we should probably make these mod files pmots and pmlc to make support consistent in future cases

const modDex = Dex.mod(mod);
const modData = modDex.data;
const parentDex = Dex.forGen(modDex.gen);
Expand All @@ -1057,13 +1113,41 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
for (const id in modData.Pokedex) {
const modEntry = modData.Pokedex[id];
const parentEntry = parentData.Pokedex[id];
if (typeof parentEntry === 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof parentEntry === 'undefined') {
if (!parentEntry) {

overrideSpeciesData[id] = {};
overrideSpeciesData[id] = modEntry;
overrideSpeciesData[id].exists = true;
continue;
}
for (const key of overrideSpeciesKeys) {
if (JSON.stringify(modEntry[key]) !== JSON.stringify(parentEntry[key])) {
if (!overrideSpeciesData[id]) overrideSpeciesData[id] = {};
overrideSpeciesData[id][key] = modEntry[key];
}
}
}

const overrideDexInfo = {};
BattleTeambuilderTable[mod].overrideDexInfo = overrideDexInfo;
for (const id in modData.Pokedex) {
const modEntry = modData.Pokedex[id];
const parentEntry = parentData.Pokedex[id];
if (typeof parentEntry === 'undefined') {
overrideDexInfo[id] = {};
overrideDexInfo[id] = modEntry;
overrideDexInfo[id].exists = true;
continue;
}
for (const key in modEntry) {
const modString = JSON.stringify(modEntry[key]);
const parentString = JSON.stringify(parentEntry[key]);
if (modString !== parentString) {
if (!overrideDexInfo[id]) overrideDexInfo[id] = {};
if (typeof modString === 'undefined') continue;
overrideDexInfo[id][key] = JSON.parse(modString);
}
}
}

const overrideMoveData = {};
BattleTeambuilderTable[mod].overrideMoveData = overrideMoveData;
Expand Down Expand Up @@ -1091,6 +1175,46 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
}
}
}

const overrideAbilityDesc = {};
BattleTeambuilderTable[mod].overrideAbilityDesc = overrideAbilityDesc;
const fullAbilityName = {};
BattleTeambuilderTable[mod].fullAbilityName = fullAbilityName;
for (const id in modData.Abilities) {
const modEntry = modData.Abilities[id];
const parentEntry = parentData.Abilities[id];
const fakeAbility = (typeof parentEntry === 'undefined');
if (fakeAbility) fullAbilityName[id] = modData.Abilities[id].name;
if (fakeAbility || (modEntry.shortDesc || modEntry.desc) !== (parentEntry.shortDesc || parentEntry.desc)) {
overrideAbilityDesc[id] = (modEntry.shortDesc || modEntry.desc);
}
}

const overrideItemDesc = {};
BattleTeambuilderTable[mod].overrideItemDesc = overrideItemDesc;
for (const id in modData.Items) {
const modEntry = modDex.items.get(id);
const parentEntry = parentDex.items.get(id);
if ((modEntry.shortDesc || modEntry.desc) !== (parentEntry.shortDesc || parentEntry.desc)) {
overrideItemDesc[id] = (modEntry.shortDesc || modEntry.desc);
}
}

const overrideTypeChart = {};
BattleTeambuilderTable[mod].overrideTypeChart = overrideTypeChart;
const removeType = {};
BattleTeambuilderTable[mod].removeType = removeType;
for (const id in modData.TypeChart) {
const modEntry = modData.TypeChart[id];
const parentEntry = parentData.TypeChart[id];
if (modEntry.isNonstandard) {
removeType[id] = true;
continue;
}
if (JSON.stringify(parentEntry) !== JSON.stringify(modEntry)) {
overrideTypeChart[id] = modEntry;
}
}
}

buf += `exports.BattleTeambuilderTable = JSON.parse('${JSON.stringify(BattleTeambuilderTable).replace(/['\\]/g, "\\$&")}');\n\n`;
Expand Down
2 changes: 1 addition & 1 deletion js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@

// abilities
if (gen >= 3) {
var abilities = Dex.forGen(gen).species.get(id).abilities;
var abilities = this.engine.dex.species.get(id).abilities;
if (gen >= 5) {
if (abilities['1']) {
buf += '<span class="col twoabilitycol">' + abilities['0'] + '<br />' +
Expand Down
13 changes: 12 additions & 1 deletion src/battle-dex-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
set: PokemonSet | null = null;

protected formatType: 'doubles' | 'bdsp' | 'bdspdoubles' | 'letsgo' | 'metronome' | 'natdex' | 'nfe' |
'dlc1' | 'dlc1doubles' | 'stadium' | null = null;
'dlc1' | 'dlc1doubles' | 'stadium' | 'alternatium' | 'randomdex' | null = null;

/**
* Cached copy of what the results list would be with only base filters
Expand Down Expand Up @@ -612,13 +612,18 @@ abstract class BattleTypedSearch<T extends SearchType> {
this.formatType = 'letsgo';
this.dex = Dex.mod('gen7letsgo' as ID);
}
if (format.includes('alternatium')) {
this.formatType = 'alternatium';
this.dex = Dex.mod('alternatium' as ID);
}
if (format.includes('nationaldex') || format.startsWith('nd') || format.includes('natdex')) {
format = (format.startsWith('nd') ? format.slice(2) :
format.includes('natdex') ? format.slice(6) : format.slice(11)) as ID;
this.formatType = 'natdex';
if (!format) format = 'ou' as ID;
}
if (this.formatType === 'letsgo') format = format.slice(6) as ID;
if (this.formatType === 'alternatium') format = 'alternatium' as ID;
if (format.includes('metronome')) {
this.formatType = 'metronome';
}
Expand Down Expand Up @@ -717,6 +722,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
let table = BattleTeambuilderTable;
if (this.formatType?.startsWith('bdsp')) table = table['gen8bdsp'];
if (this.formatType === 'letsgo') table = table['gen7letsgo'];
if (this.formatType === 'alternatium') table = table['alternatium'];
if (speciesid in table.learnsets) return speciesid;
const species = this.dex.species.get(speciesid);
if (!species.exists) return '' as ID;
Expand Down Expand Up @@ -769,6 +775,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
let table = BattleTeambuilderTable;
if (this.formatType?.startsWith('bdsp')) table = table['gen8bdsp'];
if (this.formatType === 'letsgo') table = table['gen7letsgo'];
if (this.formatType === 'alternatium') table = table['alternatium'];
let learnset = table.learnsets[learnsetid];
if (learnset && (moveid in learnset) && (!this.format.startsWith('tradebacks') ? learnset[moveid].includes(genChar) :
learnset[moveid].includes(genChar) ||
Expand All @@ -787,6 +794,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
const gen = this.dex.gen;
const tableKey = this.formatType === 'doubles' ? `gen${gen}doubles` :
this.formatType === 'letsgo' ? 'gen7letsgo' :
this.formatType === 'alternatium' ? 'alternatium' :
this.formatType === 'bdsp' ? 'gen8bdsp' :
this.formatType === 'bdspdoubles' ? 'gen8bdspdoubles' :
this.formatType === 'nfe' ? `gen${gen}nfe` :
Expand Down Expand Up @@ -894,6 +902,8 @@ class BattlePokemonSearch extends BattleTypedSearch<'pokemon'> {
table = table['gen8' + this.formatType];
} else if (this.formatType === 'letsgo') {
table = table['gen7letsgo'];
} else if (this.formatType === 'alternatium') {
table = table['alternatium'];
} else if (this.formatType === 'natdex') {
table = table['natdex'];
} else if (this.formatType === 'metronome') {
Expand Down Expand Up @@ -1427,6 +1437,7 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
let lsetTable = BattleTeambuilderTable;
if (this.formatType?.startsWith('bdsp')) lsetTable = lsetTable['gen8bdsp'];
if (this.formatType === 'letsgo') lsetTable = lsetTable['gen7letsgo'];
if (this.formatType === 'alternatium') lsetTable = lsetTable['alternatium'];
if (this.formatType?.startsWith('dlc1')) lsetTable = lsetTable['gen8dlc1'];
while (learnsetid) {
let learnset = lsetTable.learnsets[learnsetid];
Expand Down
23 changes: 18 additions & 5 deletions src/battle-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,9 @@ class ModdedDex {
constructor(modid: ID) {
this.modid = modid;
const gen = parseInt(modid.substr(3, 1), 10);
if (!modid.startsWith('gen') || !gen) throw new Error("Unsupported modid");
if (modid !== 'alternatium' && (!modid.startsWith('gen') || !gen)) throw new Error("Unsupported modid");
this.gen = gen;
if (modid === 'alternatium') this.gen = 8;
}
moves = {
get: (name: string): Move => {
Expand All @@ -856,7 +857,10 @@ class ModdedDex {
}
}
if (this.modid !== `gen${this.gen}`) {
const table = window.BattleTeambuilderTable[this.modid];
var mod = this.modid;
if (this.modid === 'gen8alternatium') mod = 'alternatium';
if (this.modid === 'gen8randomdex') mod = 'randomdex';
const table = window.BattleTeambuilderTable[mod];
if (id in table.overrideMoveData) {
Object.assign(data, table.overrideMoveData[id]);
}
Expand Down Expand Up @@ -914,7 +918,10 @@ class ModdedDex {
}
}
if (this.modid !== `gen${this.gen}`) {
const table = window.BattleTeambuilderTable[this.modid];
var mod = this.modid;
if (this.modid === 'gen8alternatium') mod = 'alternatium';
if (this.modid === 'gen8randomdex') mod = 'randomdex';
const table = window.BattleTeambuilderTable[mod];
if (id in table.overrideAbilityData) {
Object.assign(data, table.overrideAbilityData[id]);
}
Expand Down Expand Up @@ -944,7 +951,10 @@ class ModdedDex {
}
}
if (this.modid !== `gen${this.gen}`) {
const table = window.BattleTeambuilderTable[this.modid];
var mod = this.modid;
if (this.modid === 'gen8alternatium') mod = 'alternatium';
if (this.modid === 'gen8randomdex') mod = 'randomdex';
const table = window.BattleTeambuilderTable[mod];
if (id in table.overrideSpeciesData) {
Object.assign(data, table.overrideSpeciesData[id]);
}
Expand All @@ -953,7 +963,10 @@ class ModdedDex {
data.abilities = {0: "No Ability"};
}

const table = window.BattleTeambuilderTable[this.modid];
var mod = this.modid;
if (this.modid === 'gen8alternatium') mod = 'alternatium';
if (this.modid === 'gen8randomdex') mod = 'randomdex';
const table = window.BattleTeambuilderTable[mod];
if (id in table.overrideTier) data.tier = table.overrideTier[id];
if (!data.tier && id.slice(-5) === 'totem') {
data.tier = this.species.get(id.slice(0, -5)).tier;
Expand Down