-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMonsterLootHarvesting.js
130 lines (117 loc) · 4.77 KB
/
MonsterLootHarvesting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/// This macro is supposed to be used with Anne Gregersen's Monster Loot supplements
/// It will send a public chat card for the Targeted Creature, the Creature Type, the associated skill to harvest it, and the DC of the check
/// It provides a drop down for the player to select which type of Harvest check they will be doing
/// And roll according to the Adv/Normal/Disadv buttons selected
/// It will then send a chat on how well the player succeeds or fails
/// It will also send the targeted creature's "[Monster name] Harvest" item to chat
if(game.user.targets.size < 1) return ui.notifications.warn(`Please target one token to harvest.`) /// Gotta target a token to harvest it
if(!actor) return ui.notifications.warn(`You need a selected actor to perform the harvesting.`);
const [target] = game.user.targets;
const pack = game.packs.get("monster-loot-vol-1-mm.harvest-items"); /// Point to the Monster Harvest Items Compendium
const harvestId = pack.index.getName(`${target.actor.name} Harvest`)?._id; ///Look for the [Creature] Harvest Item's id
if(!harvestId) return ui.notifications.info(`The ${target.actor.name} has nothing to harvest.`); ///if no id found, show warning
const item = await pack.getDocument(harvestId);
const harvestDescription = item.system.description.value;
const traits = {
name: target.name,
cr: target.actor.system.details.cr,
type: target.actor.system.details.type.value,
size: target.actor.system.traits.size,
};
const targetValue = Math.min(30, Math.floor(10+traits.cr));
let adv = 0; // modifier for disadv (-1), normal (0), adv (1)
const harvestStr = {
success: `${actor.name} succeeds, harvesting all items! `,
fail: `${actor.name} fails, harvesting no items.`,
partial: `${actor.name} suffers a mishap during harvesting, only harvesting half of the items shown.`
}
/// Define check type based on creature type
const checkTypes = {
beast: 'Nature',
dragon: 'Nature',
giant: 'Nature',
monstrosity: 'Nature',
plant: 'Nature',
humanoid: 'Survival',
celestial: 'Religion',
fiend: 'Religion',
undead: 'Religion',
aberration: 'Arcana',
construct: 'Arcana',
elemental: 'Arcana',
fey: 'Arcana',
ooze: 'Arcana'
};
let checkSkill = checkTypes[traits.type]
/// Define harvest time based on creature size
const harvestSize = {
tiny: 'Less than ½ hour',
sm: '½ hour',
med: '1 hour',
lg: '2 hours',
huge: '4 hours',
grg: '8+ hours'
};
let harvestTime = harvestSize[traits.size]
/// Send the GM a whisper for the Target information, Check Type, and DC once the player uses the macro
ChatMessage.create({
content: `
<b>${actor.name} is harvesting:</b> ${traits.name} <br>
<b>Type:</b> ${traits.type} <b>Harvest Skill:</b> ${checkSkill} <br>
<b>DC:</b> ${targetValue} <b>Harvest Time:</b> ${harvestTime}`, // DC between 10-30
})
/* Request skill check and create ChatMessages */
async function skillRoll(skillCheck) {
let harvestRoll = (await actor.rollSkill(skillCheck, {
targetValue,
fastForward: true,
advantage: adv > 0,
disadvantage: adv < 0,
flavor: `
<em>${actor.name} attempts to harvest the ${traits.name}.</em> <br>
<b>${CONFIG.DND5E.skills[skillCheck].label}</b> Skill Check: ${actor.name}`
})).total;
let messageContent = (harvestRoll > 9 + traits.cr) ? harvestStr.success : (harvestRoll <= 4 + traits.cr) ? harvestStr.fail : harvestStr.partial;
const chatData = {
user: game.data.userId,
content: `${messageContent}<hr>${harvestDescription}`,
blind: true, ///this will hide the roll from the player if Actually Private Rolls is enabled
whisper: ChatMessage.getWhisperRecipients('GM'),
}
await ChatMessage.create(chatData, {});
};
/// This will create the dialog for the player to select the check type and add it to the roll with Dis/Adv/Normal as appropriate.
let d = new Dialog({
title: `Harvest Check: ${traits.name} (${traits.type})`,
content: `
<form class="flexcol">
<div class="form-group">
<label for="exampleSelect">Select Harvest Type</label>
<select id="exampleSelect">
<option value="arc">Arcana - Aberration, Construct, Elemental, Fey, Ooze</option>
<option value="rel">Religion - Celestial, Fiend, Undead</option>
<option value="sur">Survival - Humanoid</option>
<option value="nat">Nature - Beast, Dragon, Giant, Monstrosity, Plant</option>
</select>
</div>
</form>
`,
buttons: {
advantage:{
label: 'Advantage',
callback: () => { adv = 1 }
},
normal: {
label: 'Normal',
callback: () => { adv = 0 }
},
disadvantage: {
label: 'Disadvantage',
callback: () => { adv = -1 }
},
},
default: 'yes',
close: async (html) => {
await skillRoll(`${html.find("#exampleSelect")[0].value}`);
}
}).render(true)