Minor improvements to card typography, still hacky.
[heroik.git] / scenarios.js
1 /* The person who associated a work with this deed has dedicated the
2 work to the public domain by waiving all of his or her rights to
3 the work worldwide under copyright law, including all related and
4 neighboring rights, to the extent allowed by law.
5
6 You can copy, modify, distribute and perform the work, even for
7 commercial purposes, all without asking permission.
8
9 See https://creativecommons.org/publicdomain/zero/1.0/ for details.
10 */
11
12 "use strict";
13
14 var EVENTS = [
15 { name: "The Greenskins are mobilized.",
16 effect: "Greenskins gain a bonus of +1 Strength." },
17 { name: "Big eye is watching you.",
18 effect: "Bubbleyes gain a bonus of +1 Strength.",
19 requires: ["bubbleyes"] },
20 { name: "General invocation.",
21 effect: "Demons gain a bonus of +1 Strength.",
22 requires: ["demons"] },
23 { name: "Stronger than ever.",
24 effect: "Undead gain a bonus of +1 Strength.",
25 requires: ["undead"] },
26 { name: "Meeting with Abunakkashi.",
27 effect: "Abunakkashii and his Offspring gain a bonus of +2 Strength.",
28 requires: ["abunakkashii"],
29 unique: true },
30 { name: "The start of a legend.",
31 effect: "Abunakkashii and his Offspring gain a bonus of +1 Strength.",
32 requires: ["abunakkashii"],
33 unique: true },
34 { name: "Technological prowess.",
35 effect: "Traps gain a bonus of +1 Strength.",
36 requires: ["traps"] },
37
38 { name: "Mental combat.",
39 effect: "Psi monsters gain a bonus of +1 Strength.", },
40 { name: "A cry in the night.",
41 action: "An adventurer of your choice loses 1 Mana." },
42 { name: "Vague psi.",
43 action: "Lose all your Mana tokens." },
44 { name: "It's an ambush!",
45 action: "Place a Tenacity token on each monster that does not have one." },
46 { name: "The alarm is sounded.",
47 action: "Place a Tenacity token on the weakest monster or monsters that do not already have one." },
48 { name: "Flank attack.",
49 effect: "Cards on either side corridor gain a bonus of +1 Strength.",
50 unique: true },
51 { name: "Battle formation.",
52 effect: "Cards in the central corridor(s) gain a bonus of +1 Strength.",
53 unique: true },
54 { name: "Last bastion.",
55 effect: "All cards gain a bonus of +1 Strength.",
56 unique: true },
57
58 { name: "Destruction.",
59 action: "All equipment and items are destroyed.",
60 unique: true },
61 { name: "Epic combat.",
62 effect: "The Final Monster gains a bonus of +3 Strength.",
63 unique: true },
64 { name: "Red herring.",
65 action: "Shuffle the remaining corridors together and redistribute the cards as if you were setting up the game." },
66 { name: "The torch has gone out.",
67 action: "The next dungeon card is placed face-down.", },
68
69 { name: "Anti-psi zone.",
70 effect: "You do not gain Mana tokens for the next three creatures you defeat, even if they have a Mana icon.",
71 unique: true },
72
73 { name: "Necromancy.",
74 action: "Return a random defeated dungeon card to the lowest corridor and shuffle it." },
75 { name: "Reanimation.",
76 action: "Return a random defeated dungeon card to the highest corridor and shuffle it." },
77
78 { name: "Malediction.",
79 action: "Discard a quest or a magic item." },
80
81 { name: "False brethren.",
82 effect: "All Demons gain Immunity 5 and Immunity 7.",
83 requires: ["demons"],
84 unique: true },
85
86 { name: "Psi assault.",
87 effect: "You cannot use ultimate powers.",
88 unique: true },
89 /* TODO: Figure out how to implement this well.
90 { name: "Entering an anti-magic zone.",
91 effect: "You cannot use ultimate powers.",
92 unique: true,
93 duration: 3,
94 later: { name: "Leaving the anti-magic zone.",
95 effect: "You may use ultimate powers again." }
96 },
97 */
98 // Events from Sean Allen's random scenario generator.
99 // http://boardgamegeek.com/filepage/57107/random-scenario-generator
100 { name: "Fire from above.",
101 effect: "Dragons gain a bonus of +1 Strength.",
102 requires: ["dragons", "noncanonical"],
103 unique: true },
104 { name: "Overwhelming fear.",
105 action: "Lose 1 extra Courage token. (The dungeon does not gain another Fear token.)",
106 requires: ["noncanonical"],
107 unique: true },
108 { name: "Backs against the wall.",
109 effect: "Any monster with a Tenacity token is also <strong>Fierce</strong>.",
110 requires: ["noncanonical"],
111 unique: true },
112 { name: "The tide has turned.",
113 effect: "All monsters have <strong>Supremacy</strong>.",
114 requires: ["noncanonical"],
115 unique: true },
116 { name: "Lost.",
117 action: "Shuffle the remaining corridors together and redistribute the cards as if you were setting up the game.",
118 requires: ["noncanonical"] },
119 { name: "Into the darkness.",
120 effect: "Choose one corridor. Its cards are now always placed face-down.",
121 requires: ["noncanonical"] },
122
123 // Events of my own devising.
124 { name: "Unwanted attention.",
125 effect: "Unique monsters gain a bonus of +1 Strength.",
126 requires: ["noncanonical"],
127 unique: true },
128 { name: "Spiked the punch.",
129 effect: "Greenskins have 1d8 Strength.",
130 requires: ["noncanonical"],
131 unique: true },
132 { name: "Twisty passages.",
133 effect: "After defeating a card, roll a die. On an odd number its replacement is placed face-down.",
134 requires: ["noncanonical"],
135 unique: true },
136 { name: "Closer than you think.",
137 action: "The dungeon gains another Fear token, and a new event occurs.",
138 requires: ["noncanonical"],
139 another: true, unique: true },
140 { name: "I thought you had it.",
141 action: "Randomly discard four of your defeated dungeon cards.",
142 requires: ["noncanonical"] },
143 { name: "Adamantine armor.",
144 effect: "All monsters gain <strong>Immunity&nbsp;1</strong>.",
145 requires: ["noncanonical"],
146 unique: true },
147 { name: "Normative assumptions.",
148 effect: "Effects concerning ♂ instead concern ♀, and vice versa.",
149 requires: ["noncanonical"],
150 unique: true },
151 { name: "Infighting.",
152 effect: "Greenskins have <strong>Undead&nbsp;+1</strong>, <strong>Demons&nbsp;-1</strong>. Demons have <strong>Greenskins&nbsp;+1</strong>, <strong>Undead&nbsp;-1</strong>. Undead have <strong>Demons&nbsp;+1</strong>, <strong>Greenskins&nbsp;-1</strong>.",
153 requires: ["noncanonical"],
154 unique: true },
155 { name: "New moon.",
156 effect: "Demons have <strong>Veil of Shadow</strong>.",
157 requires: ["noncanonical", "demons"],
158 unique: true },
159 { name: "Camouflage.",
160 effect: "Greenskins have <strong>Veil of Shadow</strong>.",
161 requires: ["noncanonical"],
162 unique: true },
163 { name: "Cryptic shades.",
164 effect: "Undead have <strong>Veil of Shadow</strong>.",
165 requires: ["noncanonical", "undead"],
166 unique: true },
167 { name: "Lingering smoke.",
168 effect: "Dragons have <strong>Veil of Shadow</strong>.",
169 requires: ["noncanonical", "dragons"],
170 unique: true },
171 { name: "Hypnotizing gaze.",
172 effect: "Bubbleyes have <strong>Veil of Shadow</strong>.",
173 requires: ["noncanonical", "bubbleyes"],
174 unique: true },
175 { name: "Leeched power.",
176 action: "A random adventurer loses a Mana token.",
177 requires: ["noncanonical"] },
178
179 ];
180
181 var NOP = [
182 { name: "Nothing happens." },
183 { name: "A draft blows down the hallway.",
184 requires: ["noncanonical"] },
185 { name: "You sneeze.",
186 requires: ["noncanonical"] },
187 { name: "There's a skittering in the distance.",
188 requires: ["noncanonical"] },
189 ];
190
191 var HELPFUL = [
192 { name: "It cuts both ways.",
193 action: "Next time you roll a 1, put a Tenacity token on all face-up monsters and roll again.",
194 requires: ["helpful"] },
195 { name: "Breached their defense.",
196 action: "Gain 2 Courage tokens and the dungeon gains 1 Fear token and the Fate Chart advances; <em>or</em> gain 1 Mana token.",
197 requires: ["helpful"], unique: true },
198 { name: "Mana ritual.",
199 action: "Discard up to 2 Mana tokens. For each one discarded, gain 1 Courage token.",
200 requires: ["helpful"] }
201 ];
202
203 var LOSE = { name: "Your adventuring party is defeated!" };
204
205 function randrange (a, b) {
206 return a + (Math.random() * (b - a)) | 0;
207 }
208
209 function generate (flags, events, nop) {
210 var chosen = [];
211 var i;
212
213 function canStillHappen (event) {
214 return issubset(event.requires || [], flags)
215 && !(event.unique && contains.call(chosen, event));
216 }
217
218 for (i = 0; i < events; ++i)
219 chosen.push(choice(EVENTS.filter(canStillHappen)));
220
221
222 for (i = 0; i < nop / 2; ++i) {
223 var helpful = HELPFUL.filter(canStillHappen);
224 var neutral = NOP.filter(canStillHappen);
225 chosen.splice(
226 randrange(0, chosen.length), 0,
227 choice(helpful.length ? helpful : neutral));
228
229 }
230 for (;i < nop; ++i) {
231 var neutral = NOP.filter(canStillHappen);
232 chosen.splice(randrange(0, chosen.length), 0, choice(neutral));
233
234 }
235
236 chosen.push(LOSE);
237 return chosen;
238 }
239
240 function toHTML (event) {
241 return ["<span class=fate-name>" + event.name + "</span>",
242 event.action
243 ? "<span class=fate-action>" + event.action + "</span>"
244 : "",
245 event.effect
246 ? "<span class=fate-effect>" + event.effect + "</span>"
247 : "",
248 ].join(" ");
249 }
250
251 var THEME = ("h1 { color: hsl(XXX, 25%, 75%); }\n\
252 h2, .button, select { border-color: hsl(XXX, 30%, 85%); }\n\
253 \n\
254 a:link, a:visited, a:active {\n\
255 color: hsl(XXX, 25%, 50%);\n\
256 }\n\
257 \n\
258 select, .button, tbody tr:nth-last-child(odd) {\n\
259 background-color: hsl(XXX, 30%, 85%);\n\
260 }\n\
261 \n\
262 h1,\n\
263 select:hover, select:focus,\n\
264 .button:hover, .button:focus {\n\
265 border-color: hsl(XXX, 25%, 50%);\n\
266 }");
267
268 function randomizeName () {
269 var name = generateName();
270 document.getElementById("name").textContent = name;
271 document.title = document.title.replace(/[^-]*-/, name + " -");
272 document.head.lastChild.textContent = THEME.replace(
273 /XXX/g, (Math.random() * 256) | 0);
274 }
275
276 var events = [];
277 var style;
278
279 function generateScenario () {
280 var parts = location.hash.slice(1).split(',');
281 events = generate(parts, parts.shift() | 0, parts.shift() | 0);
282 style = document.createElement("style");
283 document.head.appendChild(style);
284 randomizeName();
285 }
286
287 function getEvents (matcher) {
288 return EVENTS.filter(matcher);
289 }
290
291 function wrapRow (row) {
292 return "<tr><td>" + row + "</td></tr>";
293 }
294
295 function iscanonical (event) {
296 return !isnoncanonical(event);
297 }
298 function isnoncanonical (event) {
299 return ~(event.requires || []).indexOf('noncanonical');
300 }
301
302 function canonicalToHTML (sender) {
303 sender.innerHTML = EVENTS.filter(iscanonical)
304 .map(toHTML).sort().map(wrapRow).join('');
305 }
306
307 function noncanonicalToHTML (sender) {
308 sender.innerHTML = EVENTS.filter(isnoncanonical)
309 .map(toHTML).sort().map(wrapRow).join('');
310 }
311
312 function nextEvent (sender) {
313 if (!events.length) {
314 location.reload();
315 return;
316 }
317
318 var event = events.shift();
319 var body = document.querySelector("#fate tbody");
320 var fate = body.children.length + 1;
321 var tr = document.createElement('tr');
322 tr.innerHTML = "<td><div>" + fate + "</div></td>"
323 + "<td><div>" + toHTML(event) + "</div></td>";
324 body.insertBefore(tr, body.firstChild);
325
326 if (events.length === 0) {
327 sender.textContent = "Try Again ▲";
328 }
329
330 if (event.another)
331 setTimeout(function () { nextEvent(sender); }, 333);
332 }