import { isCharacter , isPlugyStash , ItemsOwner , } from "../../save-file/ownership" ; import { addPage } from "../../plugy-stash/addPage" ; import { transferItem } from "./transferItem" ; import { ItemStorageType } from "../types/ItemLocation" ; import { Item } from "../types/Item" ; export function bulkTransfer ( target , items , storageType = ItemStorageType . STASH ) { if ( isPlugyStash ( target ) ) { let pageIndex = target . pages . length ; addPage ( target , "Transferred" ) ; for ( const item of items ) { if ( ! transferItem ( item , target , ItemStorageType . STASH , pageIndex ) ) { addPage ( target , "Transferred" ) ; pageIndex ++ ; transferItem ( item , target , ItemStorageType . STASH , pageIndex ) ; } } } else if ( isCharacter ( target ) ) { for ( const item of items ) { if ( ! transferItem ( item , target , storageType ) ) { throw new Error ( "Not enough space to transfer all the selected items." ) ; } } } else { itemsLoop : for ( const item of items ) { let pageIndex = 0 ; while ( pageIndex < target . pages . length ) { if ( transferItem ( item , target , ItemStorageType . STASH , pageIndex ) ) { continue itemsLoop ; } pageIndex ++ ; } throw new Error ( "Not enough space to transfer all the selected items." ) ; } } }