Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item quantity is getting doubled with calling game.itempiles.API.transferItems( #677

Open
4 tasks done
matthewbstroud opened this issue Oct 31, 2024 · 18 comments
Open
4 tasks done
Labels
bug Something isn't working

Comments

@matthewbstroud
Copy link

matthewbstroud commented Oct 31, 2024

I confirm the following:

  • [x ] I am on the latest version of Item Piles
  • I have tried to clear my cache (Ctrl / Cmd + F5)
  • I have checked the console for errors (F12 to open, Console tab)
  • I have tried to reset Item Piles' system settings
  • I have reproduced this bug with only item piles & its dependency modules enabled

Describe the bug
If I have quantity 4 of an item and transfer to an item pile, the quantity ends up being 8 on the vault.

To Reproduce
Steps to reproduce the behavior:

        let result = await game.itempiles.API.createItemPile(pileOptions);
        let backpackToken = await fromUuid(result.tokenUuid);
        let items = actor.items.filter(i => i?.system?.container == backpack.id);
        items.unshift(backpack);
        let transferred = await game.itempiles.API.transferItems(controlledToken, backpackToken, items);

Expected behavior
I would expect the amounts to be retained.

Setup

  • Foundry Version: v12 331
  • System Version: DND5e 3.3.1
  • Item Piles Version: 3.1.6
  • Browser & version Edge 130.0.2849.56 (Official build) (64-bit)

Active modules

  • Item Piles
  • libwrapper
  • socketlib
  • CPR
  • Stroud's DnD Helpers
@matthewbstroud matthewbstroud added the bug Something isn't working label Oct 31, 2024
@matthewbstroud
Copy link
Author

image
image

@matthewbstroud
Copy link
Author

appears to be happening around here...
image

@matthewbstroud
Copy link
Author

going into line 300 the quantities look okay.

@matthewbstroud
Copy link
Author

image

@matthewbstroud
Copy link
Author

so, there was 1 tinderbox and 1 container, sourceTransaction.prepare() ends up with 2 items to delete and 2 itemDeltas, the delta for the tinderbox should be -1, but it is -2.

@matthewbstroud
Copy link
Author

the item id appears to be duplicated in the list
image

@matthewbstroud
Copy link
Author

The extra item appears to be added here...
image

@Haxxer
Copy link
Collaborator

Haxxer commented Oct 31, 2024

Can you confirm that the backpack is not in your items variable?

@matthewbstroud
Copy link
Author

Okay, I think I know what is going on here. In v11, when you dropped a backpack, it just dropped the backpack and left all it's contents in your inventory, I wrote code to handle that. So, it would appear that I no longer need my code.

@matthewbstroud
Copy link
Author

Yeah, you basically corrected an issue I had been coding around in v11.

@Haxxer
Copy link
Collaborator

Haxxer commented Oct 31, 2024

It is still an issue, it shouldn't duplicate ids.

@matthewbstroud
Copy link
Author

Okay, well, the issue is that I was transferring a container and all of its contents. You have added a handler for containers, that adds their contents. This caused the items to be duplicated.

@matthewbstroud
Copy link
Author

The reason is that you do a concat of items and newitems. It really needs to be a union.

@matthewbstroud
Copy link
Author

(if the item already exists, it wouldn't be added again.)

@matthewbstroud
Copy link
Author

I could fix it if you don't have time.

@matthewbstroud
Copy link
Author

Just let me know.

@Haxxer
Copy link
Collaborator

Haxxer commented Oct 31, 2024

Item Piles is open source, so feel free to create a pull request as you please

@matthewbstroud
Copy link
Author

#678

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants