Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let matRarities = [
- 'Common',
- 'Uncommon',
- 'Rare',
- 'Very Rare',
- 'Legendary',
- 'Artifact'
- ];
- let matTypes = {
- 'Metal': {tool: "Smith's Tools", uses: ['Weapons', 'Armors', 'Accessories']},
- 'Precious Metal': {tool: "Smith's Tools", uses: ['Weapons', 'Armors', 'Accessories']},
- 'Wood': {tool: "Carpenter's Tools", uses: ['Weapons', 'Armors', 'Accessories']},
- 'Herb': {tool: "Herbalism Kit", uses: ['Potions', 'Accessories']},
- 'Component': {tool: "Cook's Utensils", uses: ['Potions', 'Accessories']},
- 'Hide': {tool: "Leatherworker's Tools", uses: ['Weapons', 'Armors', 'Potions', 'Accessories']},
- 'Bone': {tool: "Cook's Utensils", uses: ['Weapons', 'Armors', 'Potions', 'Accessories']},
- 'Fluid': {tool: "Brewer's Supplies", uses: ['Potions', 'Accessories']},
- 'Mineral': {tool: "Jeweler's Tools", uses: ['Accessories']},
- 'Gem': {tool: "Jeweler's Tools", uses: ['Accessories']},
- 'Essence': {tool: "Alchemist's Supplies", uses: ['Weapons', 'Armors', 'Potions', 'Accessories']}
- };
- let matQualities = [
- '~~ None ~~',
- 'Acidic',
- 'Chaotic',
- 'Cold',
- 'Dimensional',
- 'Fiendish',
- 'Fiery',
- 'Forceful',
- 'Inert',
- 'Lightning',
- 'Mercurial',
- 'Necrotic',
- 'Phantasmal',
- 'Poisonous',
- 'Pyschic',
- 'Radiant',
- 'Theurgic',
- 'Thundering',
- 'Vital',
- 'Void',
- 'Zephyrous'
- ];
- let rarityOptions = matRarities.map(name => {
- return '<option value="'+name+'">'+name+'</option>';
- }).join('');
- let typeOptions = Object.entries(matTypes).map(([name, data]) => {
- return '<option value="'+name+'">'+name+'</option>';
- }).join('');
- let qualityOptions = matQualities.map(name => {
- return '<option value="'+name+'">'+name+'</option>';
- }).join('');
- let folderOptions = game.folders.filter(f => f.data.type == "Item").map(f => {
- return '<option value="'+f._id+'">'+(f.parent ? f.parent.name+'/':'')+f.name+'</option>';
- }).join('');
- new Dialog({
- title: "Create Crafting Material",
- content: `<form class="editable flexcol" autocomplete="off">
- <header class="sheet-header">
- <h1><input name="matName" type="text" value="" placeholder="New Material Name"/></h1>
- </header>
- <div class="form-group"><label>Save to Folder: </label><select name="matFolder"><option value="">~~ None ~~</option>${folderOptions}</select></div>
- <div class="form-group"><label>Print to Chat: </label><input type="checkbox" name="toChat" checked="checked"/></div>
- <hr>
- <div class="form-group"><label>Rarity: </label><select name="matRarity">${rarityOptions}</select></div>
- <div class="form-group"><label>Type: </label><select name="matType">${typeOptions}</select></div>
- <div class="form-group"><label>Quality: </label><select name="matQuality">${qualityOptions}</select></div>
- <div class="form-group"><label>Value: </label><input name="matValue" type="number" value="0"/></div>
- <div class="form-group"><label>Weight: </label><input name="matWeight" type="number" value="0"/></div>
- <div class="form-group"><label>Description: </label><textarea name="matDesc"/></textarea></div>
- </form>`,
- buttons: {
- ok: {
- label: "Ok",
- callback: (html) => {
- createMaterial(
- html.find('[name=matFolder]').val(),
- html.find('[name=matName]').val(),
- html.find('[name=matRarity]').val(),
- html.find('[name=matType]').val(),
- html.find('[name=matQuality]').val(),
- html.find('[name=matValue]').val(),
- html.find('[name=matWeight]').val(),
- html.find('[name=matDesc]').val(),
- html.find('[name=toChat]').is(':checked'),
- matRarities,
- matTypes,
- matQualities
- );
- }
- },
- cancel: {
- label: 'Cancel',
- callback: (html) => {
- dialogCancel();
- }
- }
- },
- default: "ok"
- }).render(true);
- async function dialogCancel() { return; }
- async function createMaterial(matFolder, matName, matRarity, matType, matQuality, matValue, matWeight, matDesc, toChat, matRarities, matTypes, matQualities) {
- let newMaterialItem = {
- "name": (matName || 'Unidentified Item'),
- "type": "loot",
- "folder": matFolder ? game.folders.get(matFolder) : '',
- "data": {
- "description": {
- "value": "<i>Material, "+matRarity+", "+matType+(matQuality ? ', '+matQuality : '')+"</i><br><b>Tool:</b> "+matTypes[matType].tool+"<br><b>Useful in: </b>"+matTypes[matType].uses.join(',')+"<hr><b>Description:</b> "+matDesc,
- "chat": "",
- "unidentified": ""
- },
- "source": "Homebrew",
- "quantity": 1,
- "weight": matWeight,
- "price": matValue,
- "attuned": false,
- "equipped": false,
- "rarity": matRarity,
- "identified": true,
- // not necessary, but could be useful
- "material": {
- "rarity": matRarity,
- "type": matType,
- "quality": matQuality,
- "tool": matTypes[matType].tool,
- "uses": matTypes[matType].uses
- }
- //
- },
- "img": '/Repository/Icons/Materials/'+matType+'.jpg'
- };
- let newLoot = await Item.create(newMaterialItem, newMaterialItem);
- //console.log('newMaterialItem', newMaterialItem);
- //console.log('newLoot', newLoot);
- if (toChat) {
- ChatMessage.create({
- content:"<h1>Loot get!</h1>@Item["+newLoot.id+"]{"+newLoot.name+"}"
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement