import L2Object from "./L2Object" ; export default class L2ObjectCollection < T extends L2Object > extends Set < T > { public closest ( ) { const mobs = Array . from ( this ) ; return mobs . reduce ( ( m , p ) => ( p . Distance < m . Distance ? p : m ) , mobs [ 0 ] ) ; } public containsObjectId ( objId ) { for ( const item of this ) { if ( item . ObjectId === objId ) { return true ; } } return false ; } public containsId ( id ) { for ( const item of this ) { if ( item . Id === id ) { return true ; } } return false ; } public containsName ( name ) { for ( const item of this ) { if ( item . Name === name ) { return true ; } } return false ; } public getEntryByObjectId ( objId ) { for ( const item of this ) { if ( item . ObjectId === objId ) { return item ; } } } public getEntryById ( id ) { for ( const item of this ) { if ( item . Id === id ) { return item ; } } } public getEntryByName ( name ) { for ( const item of this ) { if ( item . Name === name ) { return item ; } } } public removeById ( id ) { for ( const item of this ) { if ( item . Id === id ) { this . delete ( item ) ; } } } public removeByObjectId ( objId ) { for ( const item of this ) { if ( item . ObjectId === objId ) { this . delete ( item ) ; } } } public delete ( value ) { value . offAll ( ) ; return super . delete ( value ) ; } public clear ( ) { this . forEach ( item => item . offAll ( ) ) ; return super . clear ( ) ; } }