Show species-specific items in teambuilder

This commit is contained in:
Guangcong Luo
2020-05-08 05:30:56 -04:00
parent 43be8925b3
commit 715a1fa4d0
2 changed files with 22 additions and 3 deletions

View File

@@ -970,13 +970,14 @@ class Item implements Effect {
readonly zMove: string | true | null;
readonly zMoveType: TypeName | '';
readonly zMoveFrom: string;
readonly zMoveUser: string[] | null;
readonly zMoveUser: readonly string[] | null;
readonly onPlate: TypeName;
readonly onMemory: TypeName;
readonly onDrive: TypeName;
readonly fling: any;
readonly naturalGift: any;
readonly isPokeball: boolean;
readonly itemUser?: readonly string[];
constructor(id: ID, name: string, data: any) {
if (!data || typeof data !== 'object') data = {};
@@ -1003,6 +1004,7 @@ class Item implements Effect {
this.fling = data.fling || null;
this.naturalGift = data.naturalGift || null;
this.isPokeball = !!data.isPokeball;
this.itemUser = data.itemUser;
if (!this.gen) {
if (this.num >= 577) {

View File

@@ -1052,8 +1052,25 @@ class BattleItemSearch extends BattleTypedSearch<'item'> {
}
return table.itemSet;
}
getBaseResults() {
return this.getDefaultResults();
getBaseResults(): SearchRow[] {
if (!this.species) return this.getDefaultResults();
const speciesName = this.dex.getSpecies(this.species).name;
const results = this.getDefaultResults();
const speciesSpecific: SearchRow[] = [];
for (const row of results) {
if (row[0] !== 'item') continue;
if (this.dex.getItem(row[1]).itemUser?.includes(speciesName)) {
speciesSpecific.push(row);
}
}
if (speciesSpecific.length) {
return [
['header', "Specific to " + speciesName],
...speciesSpecific,
...results,
];
}
return results;
}
filter(row: SearchRow, filters: string[][]) {
if (!filters) return true;