-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCastContinualLight.js
More file actions
151 lines (136 loc) · 5.57 KB
/
CastContinualLight.js
File metadata and controls
151 lines (136 loc) · 5.57 KB
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
// Usage: /:CastContinualLight
console.log(`---------------------- Start CastContinualLight ----------------------`);
function wait(x) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(x);
}, 20000);
});
}
// config
let Title = 'Continual Light';
let SpellName ='Continual*Light';
let Cost = 2;
let CastAnim = '!/anim EnergyStrandIN01_03_Regular_Yellow c *0.5 @self \\\\!/anim BorderInPulse_01_Circle_Normal_500 c *0.3 @self \\\\!/anim MarkerLightOrbComplete_01_Regular_White c *0.6';
let EffectMacroName = 'LightAreaEffect';
let durationType = 'days';
let durationDice = 2; // days
let animation = 'sunburst';
let glowColor = '#21170d'; // light orange #f9c56c, darkOrange #21170d,
// setup
let SpellCheck = `[Sp:${SpellName}]`; // alter the OtF type used for primary check
let EffectMacro = '';
let originalActor = await GURPS.LastActor;
let actorName = originalActor.name;
console.log(`actorName: ${actorName};`);
let targetID,targetToken,targetActor,targetName,followOnMsg,chatDescription;
let targets = Array.from(game.user.targets);
let target = targets[0];
targetID = target.id;;
targetToken = await canvas.tokens.get(targetID);
targetActor = targetToken.actor;
targetName = targetActor.name;
console.log(`targetID: ${targetID}: targetToken: ${targetToken}: targetActor: ${targetActor}: targetName: ${targetName}`);
// subract CostMod from spell cost, or calculate SpellcastSpell cost reduction with '+CostMod;
let SpellSkill = Number(GURPS.findSkillSpell(_token.actor,SpellName,0,1).level);
console.log(`SpellSkill: ${SpellSkill}`);
let CostMod = 0;
if (SpellSkill > 29) {
CostMod = -4;
} if (SpellSkill > 24) {
CostMod = -3;
} else if (SpellSkill > 19) {
CostMod = -2;
} else if (SpellSkill > 14) {
CostMod = -1;
}
let energy = 0;
let adjustedCost = 0;
let modTitle = '';
let glowLumin = 0.1;
console.log(`SpellSkill: ${SpellSkill}; CostMod: ${CostMod};`);
function castSpell(source, clType) {
console.log(`source:${source}; clType:${clType}; `);
if (clType === 'Moonlight') {
Title = 'Continual Light (Moonlight)';
modTitle = 'CL Moonlight';
Cost = 2;
rsize = 1;
glowLumin = 0.3;
} else if (clType === 'Torchlight') {
Title = 'Continual Light (Torchlight)';
modTitle = 'CL Torchlight';
Cost = 4;
rsize = 2;
glowLumin = 0.5;
} else if (clType === 'Daylight') {
Title = 'Continual Light (Daylight)';
modTitle = 'CL Daylight';
Cost = 6;
rsize = 4;
glowLumin = 0.75;
}
energy = Cost;// fixed cost for Continual Light
if (CostMod < 0) {
adjustedCost = energy+Number(CostMod);
}
console.log(`adjustedCost:${adjustedCost}; CostMod:${CostMod}; energy:${energy};`);
if (adjustedCost < 0) adjustedCost = 0;
console.log(`adjustedCost after zero check: ${adjustedCost};`);
let costSource = `/FP -${adjustedCost}`;
if (source === 'HP') costSource = `/HP -${adjustedCost}`;
if (source === 'EnergyReserve') costSource = `/tr(EnergyReserve) -${adjustedCost}`;
console.log(`costSource:${costSource};`);
// notify GM to apply effect on target
EffectMacro = `/w gm ${actorName} casts ${Title} on ${targetName}: GM target ${targetName} and click to apply it: ["Apply ${modTitle} spell on target"/:${EffectMacroName} rsize=${rsize} lumin=${glowLumin} anim=${animation} color="${glowColor}"]`; // dsize=0 is default for Glow since the spell creates a uniform area of brightness
let critDuration = durationDice*6;
let sformula = `${CastAnim} \\\\${costSource} \\\\${EffectMacro} \\\\/${durationDice}d ${durationType}.`;
let csformula = `${CastAnim} \\\\${EffectMacro} \\\\Critical Success! Duration: ${critDuration} ${durationType}`;
let fformula = `${SpellName} ${Title} failed!`;
let cfformula = `Your spell goes horribly wrong. You lose ${costSource} \\\\${costSource}`;
let OtF = `[/if ${SpellCheck} s:{${sformula}} cs:{${csformula}} f:{${fformula}} cf:{${cfformula}} ]`;
console.log(OtF);
let chatDescription = `<b>Light Effect</b> for <b>${Title}</b> has a <b>${rsize}-hex radius</b>. </p>`;
chatDescription += `<p><b>${Title}</b> has fixed cost of ${energy} energy.</p>`;
if (CostMod < 0) {
chatDescription += `High skill ${SpellSkill} reduces the ${energy} energy cost by ${CostMod}`;
} else {
chatDescription += `Normal skill ${SpellSkill} does not reduce energy cost`;
}
chatDescription += `, giving a total of ${adjustedCost} energy cost using ${source} as the energy source.</p>`;
console.log(chatDescription);
ChatMessage.create({
content: chatDescription, speaker: ChatMessage.getSpeaker(_token.actor)},
{ chatBubble: false });
GURPS.executeOTF(OtF);
}
new Dialog({
title: Title,
content: `
<div style='padding: 4px;'>
<label for="source">Energy Source</label>
<select id="source">
<option value='FP'>FP</option>
<option value='EnergyReserve'>Energy Reserve</option>
<option value='HP' style='color: darkred;'>HP</option>
</select>
</div>
<div style='padding: 4px;'>
<label for="clType">Spell Area Size</label>
<select id="clType">
<option value='Moonlight'>1-hex radius Moonlight *Cost 2</option>
<option value='Torchlight'>2-hex radius Torchlight *Cost 4</option>
<option value='Daylight'>4-hex radius Daylight *Cost 6</option>
</select>
</div>
`,
buttons: {
confirm: {
label: "Confirm",
callback: async (html) => castSpell(
html.find('#source').val(),
html.find('#clType').val())
}
}
}).render(true)
console.log(`---------------------- End CastContinualLight ----------------------`);