-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweapons.html
More file actions
418 lines (367 loc) · 18 KB
/
Copy pathweapons.html
File metadata and controls
418 lines (367 loc) · 18 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<!--
Copyright 2017 Uche Akotaobi.
This file is part of BOT.
BOT is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
BOT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with BOT. If not, see <http://www.gnu.org/licenses/>.
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="An interactive review of the weapons in the game of BOT."/>
<title>B O T :: List of Weapons</title>
<link rel="stylesheet" href="./styles/common.css" type="text/css"/>
<link rel="stylesheet" href="./styles/page.css" type="text/css"/>
<script type="application/javascript" src="./src/Utils.js"></script>
<script type="application/javascript" src="./src/Weapon.js"></script>
<script type="application/javascript" src="./src/Robot.js"></script>
<script type="application/javascript" src="./src/Sprite.js"></script>
<script type="application/javascript" src="./src/GameController.js"></script>
<script type="application/javascript" src="./src/PlainView.js"></script>
<script type="application/javascript" src="./lib/RGraph.common.core.js"></script>
<script type="application/javascript" src="./lib/RGraph.common.key.js"></script>
<script type="application/javascript" src="./lib/RGraph.common.dynamic.js"></script>
<script type="application/javascript" src="./lib/RGraph.bar.js"></script>
<script type="application/javascript" src="./lib/RGraph.line.js"></script>
<style type="text/css">
/* Page-specific styles. */
#weapon-row-template {
display: none;
}
.weapons {
font-family: sans-serif;
border-collapse: separate;
border-spacing: 5px;
}
.weapons td, .weapons th {
border: 1px outset white;
padding: 3px;
}
.weapons tr {
background: #eee;
color: black;
transition: background 0.5s ease-in;
}
.weapons tr:hover {
background: linear-gradient(to bottom, #224, #448) #eee;
color: white;
}
.weapons tr:hover td { border: 1px inset white; }
.weapons tr:hover a { color: lime; }
.weapons .shortName, .weapons .damageString {
font-family: monospace;
}
.weapons .unlimited { text-align: center; }
/* The canvas "pop-up." */
#wrapper {
background-color: white;
border: 1px solid black;
box-shadow: 5px 5px 10px 0px black;
display: none;
transition: opacity 0.3s ease-in;
}
/*******************************************************************
* In-article styles.
*******************************************************************/
article { padding-bottom: 1em; }
</style>
</head>
<body>
<div class="content">
<header>
<h1 class="title">
<a href="./index.html">
<span class="letter">B</span> <span class="star">★</span> <span class="letter">O</span> <span class="star">★</span> <span class="letter">T</span>
</a>
</h1>
<h2 class="subtitle">List of Weapons</h2>
</header>
<ul class="menu">
<li><a class="menuitem" href="./game.html">New Game</a></li>
<li><a class="menuitem" href="./howtoplay.html">How to Play</a></li>
<li><a class="menuitem" href="./weapons.html">List of Weapons</a></li>
<li><a class="menuitem" href="./about.html">About</a></li>
</ul>
<article>
<h2 id="section1">Weapons in the Game</h2>
<p>Knowledge of the damage characteristics of each weapon at
your disposable is crucial if you are to meet the challenges
that lie ahead.</p>
<table class="weapons">
<tr>
<th>Weapon</th>
<th>Class</th>
<th><abbr title="Each weapon is backed by an equation used to calculate the damage it deals. These equations contain Dungeons and Dragons-style dice notation— for instance, 2D6 means to roll two six-sided dice.">Damage Expression</abbr></th>
<th>Minimum Damage</th>
<th>Maximum Damage</th>
<th>Ammo per Round</th>
<th>Total Ammo</th>
<th><abbr title="A chart which lists all possible damage values the weapon can deal, sorted by their probability.">Distribution</abbr></th>
</tr>
<tr id="weapon-row-template">
<td class="name"></td>
<td class="class"></td>
<td class="damageString"></td>
<td class="min"></td>
<td class="max"></td>
<td class="ammoPerRound"></td>
<td class="ammo"></td>
<td class="dist"><a href="#">Show</a></td>
</tr>
</table>
<div id="wrapper">
<canvas id="cvs" width="900" height="300">[No canvas support]</canvas>
</div>
</article>
</div>
<script type="application/javascript">
const canvasId = "cvs";
// What are our weapons?
//
// Well, we could just go through the Weapon.dataTable. That's fine,
// and that would give us the response characteristics for firing a
// single shot of every weapon in the game. But the thing is that
// many Bots double, triple, or even quadruple these weapons, and
// since they are always fired together, a realistic assessment of
// the damage a weapon deals should combine these values.
//
// So that is where we're iterating through the Robot.dataTable
// instead.
let allRobotWeapons = { };
for (let robotInternalName in Robot.dataTable) {
let robot = Robot.dataTable[robotInternalName];
let buckets = { };
// Find out how many of each weapon this Bot has.
for (let j = 0; j < robot.arsenal.length; ++j) {
let weaponInternalName = robot.arsenal[j];
if (!(weaponInternalName in buckets)) {
buckets[weaponInternalName] = 0;
}
buckets[weaponInternalName]++;
}
// If the robot has one of foo, produce an entry for "Foo." If
// they have 12 of foo, then produce an entry for "Foo, 12x."
// The latter will add 12 copies of foo's damage string
// together.
for (let weaponInternalName in buckets) {
if (weaponInternalName === "invalid") {
// Skip the Ukulele Bot weaponry.
continue;
}
let weapon = new Weapon(weaponInternalName);
let count = buckets[weaponInternalName];
let key = weapon.longName + ": " + count;
let combinedDamageString = Weapon.getCombinedDamageString(weapon.damage, count);
allRobotWeapons[key] = {
key: key,
count: count,
weapon: weapon,
combinedDamageString: combinedDamageString
};
}
}
// The default order in the Weapon.dataTable is roughly weakest to
// strongest. Since we don't want to give that away, we sort the
// weapons by name instead.
let dataTable = [];
for (let key in allRobotWeapons) {
dataTable.push(allRobotWeapons[key]);
}
dataTable.sort(function(item1, item2) {
if (item1.key > item2.key) {
return 1;
} else if (item1.key < item2.key) {
return -1;
}
return 0;
});
// This is just a miniature version of the sort of thing I've been
// doing repeatedly in Select.js.
let weaponRowTemplate = document.querySelector("#weapon-row-template");
for (let i = 0; i < dataTable.length; ++i) {
let weaponData = dataTable[i];
let newRow = weaponRowTemplate.cloneNode(true);
newRow.removeAttribute("id");
newRow.setAttribute("class", weaponData.weapon.internalName); // This will make individual rows easier to find.
newRow.style.display = "";
let optionalComma = (weaponData.count > 1 ? ", " : "");
let weaponCountString = (weaponData.count > 1 ? String.format("{0}x ", weaponData.count) : "");
newRow.querySelector(".name").innerHTML = String.format("<span class='longName'>{0}</span>{1}{2}",
weaponData.weapon.longName,
optionalComma,
weaponCountString);
newRow.querySelector(".class").textContent = weaponData.weapon.class[0].toUpperCase() + weaponData.weapon.class.substr(1).toLowerCase();
newRow.querySelector(".damageString").textContent = weaponData.combinedDamageString;
newRow.querySelector(".min").textContent = Number(Weapon.calculateDamage(weaponData.combinedDamageString, Weapon.useMinimumValues).damage).toFixed(1);
newRow.querySelector(".max").textContent = Number(Weapon.calculateDamage(weaponData.combinedDamageString, Weapon.useMaximumValues).damage).toFixed(1);
if (weaponData.weapon.ammoPerRound === 0) {
newRow.querySelector(".ammoPerRound").remove();
newRow.querySelector(".ammo").setAttribute("colspan", "2");
newRow.querySelector(".ammo").setAttribute("class", "ammo unlimited");
newRow.querySelector(".ammo").textContent = "Unlimited";
} else {
newRow.querySelector(".ammo").textContent = weaponData.weapon.ammo * weaponData.count;
newRow.querySelector(".ammoPerRound").textContent = weaponData.weapon.ammoPerRound * weaponData.count;
}
// nth-of-type is 1-based.
// The first row is the header (no ".dist".)
// The second row is the template.
let anchor = newRow.querySelector(".dist a");
anchor.setAttribute("href",
String.format("javascript:showCanvas('{0}', '{1}', document.querySelector('.weapons tr:nth-of-type({2}) .dist a'), '{3}');",
weaponCountString + weaponData.weapon.longName,
Weapon.getCombinedDamageString(weaponData.weapon.damage, weaponData.count),
i + 3,
canvasId));
weaponRowTemplate.parentNode.appendChild(newRow);
}
// Install a passive onmousemove() handler to keep track of the mouse
// coordinates.
let mouse = { x: 0, y: 0 };
document.onmousemove = function(mouseEvent) {
mouse.x = mouseEvent.clientX;
mouse.y = mouseEvent.clientY;
}
// Renders a bar chart on the given canvas and then a line graph on top of that.
function renderGraphOnCanvas(title, damageString, canvasId) {
// Generate some data by evaluating this damageString.
let originalData = [];
const trials = 2000;
for (let i = 0; i < trials; ++i) {
let d = Weapon.calculateDamage(damageString, Weapon.useRandomValues).damage;
d = Math.round(d);
if (originalData[d] === null || originalData[d] === undefined) {
originalData[d] = 0;
}
originalData[d]++;
}
// Ignore the data which never came up. Normalize the graph.
let data = [];
let labels = [];
let ymax = 0;
for (let i = 0; i < originalData.length; ++i) {
if (originalData[i] === null || originalData[i] === undefined || originalData[i] === 0) {
continue;
}
let frequency = originalData[i];
// Normalize the frequencies into percentages.
let percentage = frequency / trials * 100;
if (percentage > ymax) {
ymax = percentage;
}
labels.push(i);
data.push(percentage);
}
var bar = new RGraph.Bar({
id: canvasId,
data: data,
// [
// [12,15,16],[16,13,12],[13,11,12],
// [15,35,41],[19,14,10],[16,15,13]
// ],
options: {
// colors: ['#7CB5EC','#434348','#90ED7D'],
colors: ['Gradient(white:red)'],
crosshairs: true,
textAccessible: false, // I am seriously sick and tired of .rgraph_domtext_wrapper.
textSize: 14,
// variant: '3d', gutterBottom: 150,
gutterLeft: 100,
gutterTop: 50,
gutterBottom: 60,
labels: labels,
labelsAboveUnitsPost: "%",
shadow: true,
unitsPost: '%',
backgroundGridVlines: true,
backgroundGridBorder: true,
//hmargin: 15,
//hmarginGrouped: 5,
noxaxis: false,
noyaxis: false,
title: String.format("Frequency Distribution for the {0}", title),
titleY: 20,
titleXaxis: "Damage",
titleXaxisPos: 0.3,
titleYaxis: "Frequency",
titleYaxisPos: 0.4,
// key: ['Fructon Road','Lewisham Avenue','Carnival Mar-de-Gras'],
// key: ['Distribution'],
// keyPosition: 'gutter',
// keyTextSize: 12,
labelsAbove: true,
ymax: ymax
}
}); // .wave();
// The bar chart doesn't have coords yet; drawing it the first
// time will create them.
//RGraph.clear(bar.canvas);
var line = new RGraph.Line({
id: canvasId,
data: data,
options: {
colors: ['#000'],
xaxispos: 'center',
ymax: ymax,
linewidth: 4,
tickmarks: null,
textAccessible: false
}
});
// https://www.rgraph.net/canvas/docs/api.html
// Samples for all canvas chart types: https://www.rgraph.net/demos/index.html#canvas
// Sample for the chart we're using: https://www.rgraph.net/demos/bar-line-combo.html
// Chart options: https://www.rgraph.net/canvas/docs/charts-index.html
// http://www.cmsws.com/examples/applications/rgraph/RGraph_20091010/docs/api.html
var combo = new RGraph.CombinedChart(bar, line);
combo.draw();
//RGraph.redraw();
// bar.draw();
}
// Creates the canvas and displays a damage curve on it.
//
// Debugging? Move the mouse to the right side of the viewport, then
// try showCanvas("Foo", "1d3^(1d4-1)", document.querySelector("body"), "cvs").
let showCanvas = function(title, damageString, parentElement, canvasId) {
hideCanvas(canvasId);
let canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 300;
canvas.textContent = "[No canvas support.]";
canvas.setAttribute("id", canvasId);
// Clicking on the graph (well, on the whole canvas, regardless
// of what's drawn beneath) dismisses it.
canvas.onclick = function() {
hideCanvas(canvasId);
//Event.stopPropagation(); // Don't let rgraph know.
};
let wrapper = document.getElementById("wrapper");
wrapper.appendChild(canvas);
// Create content.
renderGraphOnCanvas(title, damageString, canvasId);
// Make it appear on screen.
wrapper.style.left = String.format("{0}px", mouse.x - canvas.width);
wrapper.style.top = String.format("{0}px", mouse.y);
wrapper.style.position = "absolute";
wrapper.style.display = "block";
}
let hideCanvas = function(canvasId) {
let canvas = document.getElementById(canvasId);
if (canvas) {
let wrapper = canvas.parentNode;
RGraph.Reset(canvas);
canvas.remove();
wrapper.style.display = "none";
}
}
</script>
</body>
</html>