@@ -2,8 +2,8 @@ import { AutocompleteInteraction, CommandInteraction, Message, MessageEmbed } fr
22import config from "../../data/config.json"
33import client from "../../main"
44import Command from "../../utils/Command"
5- import { CommandSource , Material , SendMessage } from "../../utils/Types"
6- import { Bookmarkable , Colors , findFuzzyBestCandidates , getLinkToGuide , paginator , sendMessage , simplePaginator , urlify } from "../../utils/Utils"
5+ import { Character , CommandSource , Material , SendMessage , Weapon } from "../../utils/Types"
6+ import { Bookmarkable , Colors , findFuzzyBestCandidates , getLinkToGuide , joinMulti , paginator , sendMessage , simplePaginator , urlify } from "../../utils/Utils"
77
88export default class MaterialCommand extends Command {
99 constructor ( name : string ) {
@@ -142,6 +142,55 @@ Note: this command supports fuzzy search.`,
142142 if ( material . sources )
143143 embed . addField ( "Sources" , material . sources . join ( "\n" ) )
144144
145+ const charAscension : Character [ ] = [ ]
146+ const charTalents : Character [ ] = [ ]
147+
148+ for ( const c of data . getCharacters ( ) ) {
149+ if ( c . ascensionCosts && data . isInCosts ( c . ascensionCosts , material . name ) )
150+ charAscension . push ( c )
151+
152+ if ( c . skills ) {
153+ const talents = c . skills . flatMap ( s => [ ...( s . talents ?? [ ] ) , s . ult ] )
154+
155+ if ( talents . some ( x => x ?. costs && data . isInCosts ( x . costs , material . name ) ) )
156+ charTalents . push ( c )
157+ }
158+ }
159+
160+ const weaponAscension : Weapon [ ] = [ ]
161+ for ( const w of Object . values ( data . weapons ) ) {
162+ if ( w . ascensionCosts && data . isInCosts ( w . ascensionCosts , material . name ) )
163+ weaponAscension . push ( w )
164+ }
165+
166+ const usedByDesc = [ ]
167+
168+ const overlap = charTalents . filter ( x => charAscension . some ( y => x . name == y . name ) )
169+ const uniqueTalents = charTalents . filter ( x => ! charAscension . some ( y => x . name == y . name ) )
170+ const uniqueAscension = charAscension . filter ( x => ! charTalents . some ( y => x . name == y . name ) )
171+
172+ if ( overlap . length > 0 )
173+ usedByDesc . push ( `Used by ${ joinMulti ( overlap . map ( x => data . emoji ( x . name ) ) . filter ( ( v , i , a ) => a . indexOf ( v ) == i ) ) } character talents and ascensions.` )
174+
175+ if ( uniqueTalents . length > 0 )
176+ usedByDesc . push ( `Used by ${ joinMulti ( uniqueTalents . map ( x => data . emoji ( x . name ) ) ) } character talents.` )
177+
178+ if ( uniqueAscension . length > 0 )
179+ usedByDesc . push ( `Used by ${ joinMulti ( uniqueAscension . map ( x => data . emoji ( x . name ) ) ) } character ascensions.` )
180+
181+ const sortedWeapon = weaponAscension
182+ . sort ( ( a , b ) => ( a . stars && b . stars && b . stars - a . stars ) || ( a . weaponType && b . weaponType && a . weaponType . localeCompare ( b . weaponType ) ) || a . name . localeCompare ( b . name ) )
183+ if ( sortedWeapon . length > 0 && sortedWeapon . length < 7 )
184+ usedByDesc . push ( `Used by ${ joinMulti ( sortedWeapon . map ( x => data . emoji ( x . name ) ) ) } weapon ascensions.` )
185+ else if ( sortedWeapon . length > 0 && sortedWeapon . filter ( x => x . stars >= 4 ) . length < 7 )
186+ usedByDesc . push ( `Used by ${ joinMulti ( [ ...sortedWeapon . filter ( x => x . stars >= 4 ) . map ( x => data . emoji ( x . name ) ) , "more low star" ] ) } weapon ascensions.` )
187+ else if ( sortedWeapon . length > 0 )
188+ usedByDesc . push ( `Used by ${ joinMulti ( [ ...sortedWeapon . slice ( 0 , 7 ) . map ( x => data . emoji ( x . name ) ) , "more" ] ) } weapon ascensions.` )
189+
190+
191+ if ( usedByDesc . length > 0 )
192+ embed . addField ( "Used by" , usedByDesc . join ( "\n" ) )
193+
145194 if ( material . icon )
146195 embed . setThumbnail ( `${ data . baseURL } ${ material . icon } ` )
147196
0 commit comments