-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddCoins
142 lines (128 loc) · 4.8 KB
/
AddCoins
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
131
132
133
134
135
136
137
138
139
140
141
142
async function addCurrency($html) {
const currencies = {
platinum: {
content: $html.find('[name="platinum"]')[0].value,
icon: "icons/commodities/currency/coins-plain-stack-gold-yellow.webp",
},
gold: {
content: $html.find('[name="gold"]')[0].value,
icon: "icons/commodities/currency/coins-plain-stack-gold-yellow.webp",
},
electrum: {
content: $html.find('[name="electrum"]')[0].value,
icon: "icons/commodities/currency/coin-engraved-oval-steel.webp",
},
silver: {
content: $html.find('[name="silver"]')[0].value,
icon: "icons/commodities/currency/coins-plain-stack-silver.webp",
},
copper: {
content: $html.find('[name="copper"]')[0].value,
icon: "icons/commodities/currency/coin-oval-rune-copper.webp",
}
};
function flavorCurrency() {
let currentIcon = currencies['platinum']['icon'];
return `
<div><strong style='color: #20854a;'>${rollPlatinum.total}</strong> Platinum ! </div>
<img src=${currentIcon} height="50" style="border:0px">
`;
}
var rollPlatinum = await new Roll(currencies.platinum.content).evaluate({ async: true });
const flavorPlatinum = flavorCurrency();
await rollPlatinum.toMessage({ rollMode: "privateroll", flavorPlatinum });
if (!currencies.platinum.content) {
var rollPlatinum = await new Roll(currencies.platinum.content).evaluate({ async: true });
const flavorPlatinum = await flavorCurrency("platinum", rollPlatinum);
console.log(flavorPlatinum);
await rollPlatinum.toMessage({ rollMode: "privateroll", flavorPlatinum });
const totalPlatinum = rollPlatinum.total;
}
if (currencies.gold.content) {
var rollGold = new Roll(currencies.gold.content).evaluate({ async: false });
const flavorGold = flavorCurrency("gold", rollGold);
await rollGold.toMessage({ rollMode: "privateroll", flavorGold });
const totalGold = rollGold.roll.total;
}
if (currencies.electrum.content) {
var rollElectrum = new Roll(currencies.electrum.content).evaluate({ async: false });
const flavorElectrum = flavorCurrency("electrum", rollElectrum);
await rollElectrum.toMessage({ rollMode: "privateroll", flavorElectrum });
const totalElectrum = rollElectrum.roll.total;
}
if (currencies.silver.content) {
var rollSilver = new Roll(currencies.silver.content).evaluate({ async: false });
const flavorSilver = flavorCurrency("silver", rollSilver);
await rollSilver.toMessage({ rollMode: "privateroll", flavorSilver });
const totalSilver = rollSilver.roll.total;
}
if (currencies.copper.content) {
var rollCopper = new Roll(currencies.copper.content).evaluate({ async: false });
const flavorCopper = flavorCurrency("copper", rollCopper);
await rollCopper.toMessage({ rollMode: "privateroll", flavorCopper });
const totalCopper = rollCopper.roll.total;
}
const target = canvas.tokens.controlled[0].actor;
await ItemPiles.API.addAttributes(target, {
'data.currency.pp': rollPlatinum?.total || '',
'data.currency.gp': rollGold?.total || '',
'data.currency.ep': rollElectrum?.total || '',
'data.currency.sp': rollSilver?.total || '',
'data.currency.cp': rollCopper?.total || ''
});
}
// style="display: flex;"
const dialog = new Dialog({
title: 'Add coins to ItemPile',
content: `
<p>How many of each currency do you want to add to the selected Token ?</p>
<form>
<div class="form-group">
<label>Platinum :</label>
<input type="text" id="platinum" name="platinum" width="10" ></textarea>
</div>
<div>
<hr>
</div>
<div class="form-group">
<label>Gold :</label>
<input type="text" id="gold" name="gold" width="10" ></textarea>
</div>
<div>
<hr>
</div>
<div class="form-group">
<label>Electrum :</label>
<input type="text" id="electrum" name="electrum" width="10"></textarea>
</div>
<div>
<hr>
</div>
<div class="form-group">
<label>Silver :</label>
<input type="text" id="silver" name="silver" width="10" ></textarea>
</div>
<div>
<hr>
</div>
<div class="form-group">
<label>Copper :</label>
<input type="text" id="copper" name="copper" width="10" ></textarea>
</div>
<div>
<hr>
</div>
</form>
`,
buttons: {
no: {
label: 'Cancel',
},
yes: {
label: 'OK',
callback: addCurrency,
},
},
default: 'yes',
});
dialog.render(true);