-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelianaHarvesting.js
187 lines (149 loc) · 5.3 KB
/
HelianaHarvesting.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
function rollD(d)
{
return Math.floor(Math.random()*d)+1
}
function ButtonControls(id,totalID, ability,chatItem)
{
console.log("Hello World")
let roll=0
let actor
if(game.user.role == 4)
{
actor = canvas.tokens.controlled[0].actor
}
else
{
actor = game.user.character
}
skill = getSkill(creatureType).substring(0,3).toLowerCase();
prof = actor.data.data.skills[skill].prof.flat
abil = actor.data.data.abilities[ability].mod
roll = rollD(20)
console.log(`[DEBUG] roll: ${roll} ${ability}.mod: ${abil} prof: ${prof} Total: ${roll+prof+abil}`)
roll = roll+prof+abil
let contentXML = new DOMParser().parseFromString(chatItem.data.content, "text/html")
contentXML.getElementById(id).parentNode.innerHTML = roll
contentXML.getElementById(totalID).innerHTML = parseInt(contentXML.getElementById(totalID).innerHTML)+roll
game.messages.filter(t=>t.id===MessID)[0].update({content: contentXML.documentElement.innerHTML})
}
async function DisplayHarvest(token)
{
d20 = 'icons/svg/d20-grey.svg'
d20Hover = 'icons/svg/d20-highlight.svg'
creatureType = token.actor.labels.creatureType
if(creatureType == undefined)
{
return
}
let id1 = Math.floor(Math.random() * 100000000);
let id2 = id1+1;
let id3 = id2+1
const message = "<h2>"+token.name+"</h2>"+getSkill(creatureType)+`
<table>
<tr>
<th>Assessment Check</th>
<th><input id='`+id1+`' src='`+d20+`' type="image" width="30" height="30" /></th>
</tr>
<tr>
<th>Carving Check</th>
<th><input id='`+id2+`' src='`+d20+`' type="image" width="30" height="30" /></th>
</tr>
</table>
<table>
<tr>
<th>Total</th>
<th><a id="`+id3+`">0</th>
</tr>
</table>
`;
ChatMessage.create({speaker: ChatMessage.getSpeaker({alias: 'Harvest Check'}), content: message}).then(t => x=t);
Hooks.on('renderChatMessage', (chatItem, html) => {
html.find("#" + id1 + "").click(() => {
ButtonControls(id1,id3, "int",chatItem)
});
html.find("#" + id2 + "").click(() => {
ButtonControls(id2,id3, "dex",chatItem)
});
//hover on, assesment check
html.find("#" + id1 + "").mouseenter(()=>{
MessID = chatItem.data._id
let contentXML = new DOMParser().parseFromString(chatItem.data.content, "text/html")
if(contentXML.getElementById(id1).getAttribute('src') == d20)
{
contentXML.getElementById(id1).setAttribute("src", d20Hover)
game.messages.filter(t=>t.id===MessID)[0].update({content: contentXML.documentElement.innerHTML})
}
});
//hover off, assesment check
html.find("#" + id1 + "").mouseout(()=>{
MessID = chatItem.data._id
let contentXML = new DOMParser().parseFromString(chatItem.data.content, "text/html")
if(contentXML.getElementById(id1).getAttribute('src') == d20Hover)
{
contentXML.getElementById(id1).setAttribute("src", d20)
game.messages.filter(t=>t.id===MessID)[0].update({content: contentXML.documentElement.innerHTML})
}
});
//hover on, Carving check
html.find("#" + id2 + "").mouseenter(()=>{
MessID = chatItem.data._id
let contentXML = new DOMParser().parseFromString(chatItem.data.content, "text/html")
if(contentXML.getElementById(id2).getAttribute('src') == d20)
{
contentXML.getElementById(id2).setAttribute("src", d20Hover)
game.messages.filter(t=>t.id===MessID)[0].update({content: contentXML.documentElement.innerHTML})
}
});
//hover off, Carving check
html.find("#" + id2 + "").mouseout(()=>{
MessID = chatItem.data._id
let contentXML = new DOMParser().parseFromString(chatItem.data.content, "text/html")
if(contentXML.getElementById(id2).getAttribute('src') == d20Hover)
{
contentXML.getElementById(id2).setAttribute("src", d20)
game.messages.filter(t=>t.id===MessID)[0].update({content: contentXML.documentElement.innerHTML})
}
});
});
}
function getSkill(type)
{
type = type.split(" ",1)[0]
switch(type)
{
case "Aberration":
return "Arcana"
case "Beast":
return "Survival"
case "Celestial":
return "Religion"
case "Construction":
return "Investigation"
case "Dragon":
return "Survival"
case "Elemental":
return "Arcana"
case "Fey":
return "Arcana"
case "Fiend":
return "Religion"
case "Giant":
return "Medicine"
case "Humanoid":
return "Medicine"
case "Monstrosity":
return "Survival"
case "Ooze":
return "Nature"
case "Plant":
return "Nature"
case "Undead":
return "Medicine"
default:
console.log("[ERROR] "+type+ " Does not exist")
return "ERR"
}
}
canvas.tokens.controlled.forEach(token => DisplayHarvest(token));
//.indexOf([type])>1
// switch