From 715a1fa4d07e31ba353183c65dee92f4e832e225 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Fri, 8 May 2020 05:30:56 -0400 Subject: [PATCH] Show species-specific items in teambuilder --- src/battle-dex-data.ts | 4 +++- src/battle-dex-search.ts | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/battle-dex-data.ts b/src/battle-dex-data.ts index f2c09220d..7cc3a722d 100644 --- a/src/battle-dex-data.ts +++ b/src/battle-dex-data.ts @@ -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) { diff --git a/src/battle-dex-search.ts b/src/battle-dex-search.ts index a90e3c848..b6da22040 100644 --- a/src/battle-dex-search.ts +++ b/src/battle-dex-search.ts @@ -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;