Open whelan opened 2 years ago
Ok, so I think the best bet would be for us to look into our drag and drop code. Currently, a player (or GM), can drag and drop an Item to transfer it. It isn't perfect, but it does do all of the work to ensure the equipment lists are set up correctly.
Looking....
Ok, given that you have an Item object, you should be able to call:
actor.addNewItemData(item)
Where "item" is an instance of GurpsItem (which is our subclass of Foundry's Item). It will add the item to the actor and update the equipment lists (and embedded documents) correctly. You "shouldn't" need to do anything else.
Let me know how it goes.
As for the money aspect... I don't know how it is currently set up, but as I mentioned before... GURPS is so configurable, we don't have a standard definition for money.
What you could do, and this is just a wild suggestion, is provide a setting for a string (or multiple strings) that can be searched for in the equipment list (using the findEquipmentByName() that you found).
The resultant equipment objects will have a count and a cost. Dungeon Fantasy RPG (GURPS specifically for fantasy) uses the conversion 1 gold = 20 silver = 400 copper (and copper is the base currency, denoted with "$"). So an equipment entry for "gold" would have a count of 1, but a cost of 400. This is the hardest currency to work with, because you would need to remove from Gold first, then silver, then copper... which you could tell by sorting on the cost.
By making this a setting, the GM could define the equipment name(s) as "wallet" or "galactic credits"), with cost 1.
NOTE: It is allowed to have equipment with count == 0. Especially for something like "wallet" or "galactic credits". The user can delete the "zero" qty equipment line if they want... but more likely, they will be getting some in the future, so there is no need to remove the line.
Ok, just musing on some ideas.
For the money I think I will keep it like a free for all string, but only one currency. If I was to support the fantasy, I need to also have the conversion rates defined as well. So you add a currency and the rate to the next one.
I have now got it to insert the item, but now I'm working on the update item. What is the best way to update the count on the item?
We currently don't have a single API call to update the count. You have to find the equipment (and the key into the data structure), and then call updateEqtCount(). To subtract 1 from the current count, you could execute:
[eqt, key] = actor.findEquipmentByName("some item name")
actor.updateEqtCount(key, eqt.count - 1)
If this "equipment" is provided by a Foundry Item, it will update the item's data.eqt.count as well.
Found the error.
Another problem. After updating the currency, the count stays the same in the sheet, but the count with updateEqtCount is changed. And is stored on the actor. Could this be a missing link between equipment and the item?
Any idea why the sheet information about item count is not updated, but the updateEqtCount updates the count and is correct. Should I export the actor for you to have a look? @crnormand
Sorry... I haven't had the time to check... but yes. I can fork your build (just let me know which branch has the new code on it).
Is your process creating a Foundry Item (in GURPS), then added it to the NPC merchant, and then transferring from the merchant to the PC?
Oh fudge.... I have no idea how to build your module. Sorry, I am not a JS developer (or I wasn't, before I started the GURPS Game Aid), so I don't know a lot of things.
If I have my fork downloaded, I assume I need to rename it to "/merchantsheetnpc'? And then how do I build it to create the "scripts/merchant.js"?
Hehe. Yes, I also started by building it in js, but then I wanted to try out typescript so I was closer to the Java I normally develop in.
To build the project you can run npm install
npm run build
and if you want to have it watched as I do. So I have the dist directory soft-linked into foundry modules. This way every time I change the code I can just reload and see if the change works.
This is done by npm run build:watch
And the branch I work on is gurps-integration.
I also found out why the count was not updated on the actor. I actually was watching the non linked token to the actor. I missed that the character was not linked to the token.
Now I'm missing the item lookup on the merchant for the sell to merchant. But I hope I will soon get that fixed also.
The last lines of the log after executing npm install:
56 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\crnor\Documents\FoundryVTT\data\modules\merchantsheetnpc\package.json' 57 verbose cwd C:\Users\crnor\Documents\FoundryVTT\data\modules\merchantsheetnpc 58 verbose Windows_NT 10.0.19044 59 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\crnor\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install" 60 verbose node v16.13.2 61 verbose npm v8.5.2 62 error code ENOENT 63 error syscall open 64 error path C:\Users\crnor\Documents\FoundryVTT\data\modules\merchantsheetnpc/package.json 65 error errno -4058 66 error enoent ENOENT: no such file or directory, open 'C:\Users\crnor\Documents\FoundryVTT\data\modules\merchantsheetnpc\package.json' 67 error enoent This is related to npm not being able to find a file. 67 error enoent 68 verbose exit -4058 69 timing npm Completed in 5182ms
Ahh I think you have not got the full project checkout. I normally have the project not directly in the foundry modules. And checkout the project there. there should be a package.json in the root of the merchantsheetnpc folder. Be in the folder and run npm install. I must admit that I have not tried to build it on a windows. :)
merchantsheetnpc.zip I have here the newest compiled version, I have nearly fixed it, but the problem is the items found with the findEquipment is not a type that is compatible with the foundry item.
Hi I'm the developer of the https://github.com/whelan/fvtt-merchant-sheet-npc and have been asked by more than one GURPS GM if I could add support for GURPS.
I started out finding how the money and item cost and weight.
So now I have the basic view and calculations in order. But I'm struggling with how to transfer the items from merchant to player and the other way.
Normally I use createEmbeddedDocuments
The class I'm working on for fixing this is: https://github.com/whelan/fvtt-merchant-sheet-npc/blob/gurps-integration/Source/merchant/systems/GurpsCurrencyCalculator.ts
Many methods have not been ported yet, so it has a lot of the stuff from dnd5e which is the most complete system integration I have.
Another thing when you drop the item from a compendium to the actor what happens which methods are called? Because that item I can not find either in the equipment or items?