-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCastSunlight.js
More file actions
141 lines (124 loc) · 5.34 KB
/
CastSunlight.js
File metadata and controls
141 lines (124 loc) · 5.34 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
// Usage: /:CastSunlight
console.log(`---------------------- Start CastSunlight ----------------------`);
function wait(x) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(x);
}, 20000);
});
}
let Title = 'Sunlight';
let SpellName ='Sunlight';
let Cost = 2;
let animation = 'sunburst';
let glowColor = '#21170d'; // light orange #f9c56c, darkOrange #21170d,
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.2';
let EffectMacroName = `LightAreaEffect`;
// 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,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 = 1.0;
async function castSpell(source, rsize) {
console.log(`source:${source}; rsize:${rsize};`);
energy = Number(rsize)*Number(Cost);// calc cost for rsize
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};`);
let formula = `/r [+0 ${Title} *Costs ${costSource}]`;
console.log(formula);
//GURPS.executeOTF(formula);
// notify GM to apply effect on target
EffectMacro = `/w gm ${actorName} casts ${Title} on ${targetName}: GM target ${targetName} and click to apply it: ["Apply ${Title} 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 sformula = `${CastAnim} \\\\${costSource} \\\\${EffectMacro}`;
let csformula = `${CastAnim} \\\\${EffectMacro} \\\\Critical Success! Spell consumes no energy.`;
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>Area Effect</b> for <b>${Title}</b> with a <b>${rsize}-hex radius</b>. </p>`;
chatDescription += `<p><b>${Title}</b> costs ${Cost} per hex of radius.</p>`;
if (Number(rsize) === 1) {
chatDescription += `<p>Spell Area Radius ${rsize} does not increase base spell cost.</p>`;
} else if (Number(rsize) > 1) {
chatDescription += `<p>Spell Area Radius ${rsize} multiplies the base spell cost to ${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>`;
chatDescription += `<p>The final calculated formula is ${formula}.</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="rsize">Spell Area Size</label>
<select id="rsize">
<option value='1'>1-hex radius *Cost 2</option>
<option value='2'>2-hex radius *Cost 4</option>
<option value='3'>3-hex radius *Cost 6</option>
<option value='4'>4-hex radius *Cost 8</option>
<option value='5'>5-hex radius *Cost 10</option>
<option value='6'>6-hex radius *Cost 12</option>
</select>
</div>
`,
buttons: {
confirm: {
label: "Confirm",
callback: async (html) => castSpell(
html.find('#source').val(),
parseInt(html.find('#rsize').val()))
}
}
}).render(true)
console.log(`---------------------- End CastSunlight ----------------------`);