-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
454 lines (371 loc) · 18 KB
/
index.html
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<style type="text/css">
body {
background-color: #83848A;
background-image: url('https://lh3.googleusercontent.com/9QBBE2t-c7ec5_cRCDpL4GDJTHfpBExGsFCMgmFv-fZ81LUWJmOg5GL0zmRGTgr2sjZmMlh_eP3EiYnWUPyzLQ=s1200');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-blend-mode: luminosity;
background-attachment: fixed;
}
#ex1Slider .slider-selection {
background: #BABABA;
}
.card {
width: 800px;
margin: 15 auto;
background-color: rgba(191, 163, 114, 0.8);
border-radius: 15px;
}
</style>
</head>
<body>
<div class="card">
<div class="card-body">
<h2>Settings</h2>
<hr>
<div class="container">
<div class="row">
<div class="col-6">
<div class="row">
<div class="col-12 font-weight-bold">REPORT PERIOD<hr></div>
</div>
<div class="row">
<div class="col-5 font-weight-bold">Start Day</div>
<div class="col-7"><input id="start" type="number" style="width: 65px;" min="0" max="999" value="0"></div>
</div>
<div class="row">
<div class="col-5 font-weight-bold">End Day</div>
<div class="col-7"><input id="end" type="number" style="width: 65px;" min="1" max="1000" value="1"></div>
</div>
<div class="row">
<div class="col-5 font-weight-bold">Duration Roll</div>
<div class="col-7"><input id="duration" type="number" style="width: 65px;" min="1" max="20" value="1"></div>
</div>
<div class="row profits" id="profits-0">
<div class="col-5 font-weight-bold">Profits Roll</div>
<div class="col-7"><input type="number" style="width: 65px;" min="1" max="20" value="1"></div>
</div>
</div>
<div class="col-6">
<textarea id="results-box" cols=40 rows=10></textarea>
</div>
</div>
</div>
<br />
<button id="calc">Calculate!</button>
<hr>
<h2>Results</h2>
<hr>
<p id="output"></p>
<hr>
</div>
</div>
<script type="text/javascript">
var starting_funds, expenses, sales, end_date, salary, upkeep, players_share;
var mining_totals = {iron: 0, gold: 0, coal: 0, platinum: 0, mithril: 0}
var time_adjustment = Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8);
var profit_adjustment = Array(0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1, 1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.2);
var saved_record = Array();
var i = 0;
var starting_funds, expenses, players_share, sales, time_to_live_seed, report_start_date, report_end_date, duration_adj, bi_wkly_revenue, salary, upkeep, end_date;
bi_weekly_revenue_tracker = {iron: 0, gold: 0, coal: 0, platinum: 0, mithril: 0};
profit_rolls = [];
//Iterate through all of the days
$("#end").on("change", function() {
$(".profits").hide(); //Clear profits
$(".profits").first().show(); //Show first
for (i = 0; i < Math.floor($("#end").val() / 30) + 1; i++) {
//If the element doesn't exist, create it
if (!$("#profits-" + i).length) {
var div = $("<div>").addClass("row profits").attr("id", "profits-" + i);
var header = $("<div>").addClass("col-5 font-weight-bold").text("Profits Roll");
var input_div = $("<div>").addClass("col-7");
var input = $("<input>").attr("type", "number").attr("min", "1").attr("max", "20").attr("value", "1").css("width", "65px");
$(div).append(header).append(input_div);
$(input_div).append(input);
elem = $(".profits:last-child");
$(".profits").last().after($(div));
//If it does exist, show it
} else {
$("#profits-" + i).show(); //Show them
}
}
})
$("#calc").on("click", function() {
$("#output").text("");
saved_record = Array();
//Iterate through all of the days
starting_funds = 1000 * 10 * 10; // 1000g
expenses = 0;
players_share = 0;
sales = 0;
time_to_live_seed = 200; //Days until players start getting screwed
report_start_date = parseInt($("#start").val());
report_end_date = parseInt($("#end").val());
duration_adj = parseInt($("#duration").val());
bi_wkly_revenue = 0;
salary = 0;
upkeep = 0;
bi_weekly_revenue_tracker = {iron: 0, gold: 0, coal: 0, platinum: 0, mithril: 0}
end_date = 365 * time_adjustment[duration_adj];
if (end_date < 72)
end_date = 72;
profit_rolls = [];
$(".profits").each(function() {
profit_rolls.push(parseInt($(this).find("input").val()))
});
i = 0;
calculate();
});
$("#results-box").on("paste", function(e) {
data_array = $.parseJSON(e.originalEvent.clipboardData.getData('text'));
settings = data_array.slice(-1)[0].settings;
transaction_log = data_array.slice(0, -1);
saved_record = Array();
$("#start").val(settings.report_start_date);
$("#end").val(settings.report_end_date);
$("#duration").val(settings.duration_adj);
$(".profits").each(function(index) {
$(this).val(settings.profit_rolls[index]);
});
//Iterate through all of the days
starting_funds = settings.starting_funds;
expenses = settings.expenses;
players_share = settings.players_share;
sales = settings.sales;
time_to_live_seed = settings.time_to_live_seed;
report_start_date = settings.report_start_date;
report_end_date = settings.report_end_date;
duration_adj = settings.duration_adj;
salary = settings.salary;
upkeep = settings.upkeep;
mining_totals = settings.mining_totals;
end_date = settings.end_date;
$.each(transaction_log, function(index, value) {
tally = "Funds: " + convertCP(value.funds) + ", "
tally += "Sale: " + convertCP(value.profit) + ", "
tally += "Expense: " + convertCP(value.expense) + ", "
tally += "Profit: " + convertCP(value.net) + "<br />"
$("#output").append("Day " + value.day + ": " + value.comment + "<br />| " + tally + "<br />");
i = value.day;
});
calculate();
});
function calculate() {
//The loop starts at 0 because even if we don't report on days 0 - start_date,
//we still need them to calculate the early earnings
for (; i <= Math.ceil(end_date) && i <= report_end_date; i++) {
profits_adj = parseInt($("#profits-" + Math.floor(((duration_adj / end_date) * i) / 30) + " > div > input").first().val());
//First, we need to build up the mine
if (i === 0) output("The mine opens for business. It\'s first order of operations is to order the equipment neccessary to operate a mine. He has 1000g starting funds.</br>", 0, 0, 0);
if (i === 2) output("Gundren Rockseeker begins by ordering four cranes at 25g each for a total cost of 100g.", 2, 0, 10000);
if (i === 4) output("He then hires labor, materials, and fuel to power the mine's massive forge.", 4, 0, 50000);
if (i === 8) output("Then, Gundren orders crates, tables, and a safe", 8, 0, 15000);
if (i === 12) output("Finally, Gundren hires laborers, craftsmen, supervisors, and a foreman.", 12, 0, 0)
//Upkeep is every 2 weks
if (i % 14 === 0 && i !== 0) {
output("Gundren pays upkeep on the mine", i, 0, 1154);
upkeep += 1154;
}
//Then, we start making profit
if (i === 30) output("After 30 days, Gundren begins to excavate his first shipment of product", i, 0, 0)
if (i > 30 && i < (end_date * 0.9)) {
profit = mining(profits_adj);
bi_wkly_revenue += profit[1];
bi_weekly_revenue_tracker[profit[0]] += profit[1];
r_event = randomEvent(i, profits_adj);
}
if ((i - 30) % 7 === 0 && i > 30 && bi_wkly_revenue) {
output("After a week\'s worth of work, Gundren estimates he earned: " + convertCP(bi_wkly_revenue) + "<br /> \
| Coal: " + convertCP(bi_weekly_revenue_tracker.coal) + "<br /> \
| Iron: " + convertCP(bi_weekly_revenue_tracker.iron) + "<br /> \
| Gold: " + convertCP(bi_weekly_revenue_tracker.gold) + "<br /> \
| Mithril: " + convertCP(bi_weekly_revenue_tracker.mithril) + "<br /> \
| Platnum: " + convertCP(bi_weekly_revenue_tracker.platinum), i, bi_wkly_revenue, 0);
output("Gundren pays " + convertCP(bi_wkly_revenue / 10) + " in materials, tools, and operating expenses.", i, 0, bi_wkly_revenue / 10);
output("Gundren pays " + convertCP(bi_wkly_revenue / 10) + " in taxes, shipment costs, and guard fees.", i, 0, bi_wkly_revenue / 10);
randomDelivery(i, profits_adj, bi_wkly_revenue);
bi_wkly_revenue = 0;
bi_weekly_revenue_tracker = {iron: 0, gold: 0, coal: 0, platinum: 0, mithril: 0}
}
if ((i - 30) % 14 === 0 && i > 30) {
wages = (18 * 250) + (2 * 1000) + (1 * 1000) + (1 * 1000);
output("Gundren pays wages", i, 0, wages * 14);
salary += wages * 14;
}
//Pay players
if (i % 14 === 0 && i > 30) {
screwment_amount = 1;
if (i > (end_date * 0.9) || players_share > 4500000) {
screwment_amount = Math.floor(((end_date - i) / end_date) * 50) / 100;
}
players_cut = (((sales - expenses) * 0.1) - players_share) * screwment_amount;
if (players_cut > 0) {
output("Gundren makes a deposit of " + convertCP(players_cut) + " into a bank account set aside for your group.", i, 0, 0);
players_share += players_cut; //For final tally
}
}
if (i === Math.ceil(end_date) || players_share > 6000000) {
if (sales - expenses > 0 || players_share > 6000000) {
output("You havent received a deposit from Gundren\'s in over a month. The payments to your account have suddenly stopped. You write to Gundren for an explanation, but he doesn\'t respond. He won\'t receive you at his office and the dwarves that operate his mine refuse to speak with you. Several well armored and grislied guards suggest that you leave.", i + 30, 0, 0);
i = Math.ceil(end_date);
} else {
output("Gundren closes the mine. It made no profit. He was a fool to believe there was still value in an old legend.", i, 0, 0);
}
}
if (i === report_end_date || i === Math.ceil(end_date)) {
reportNetProfit();
}
}
}
function reportNetProfit() {
tally = "<div class=\"row\">";
tally += "<div class=\"col-12\">";
tally += "===============================RESULTS================================<br />";
tally += "</div>";
tally += "</div>";
tally += "<div class=\"row\">";
tally += "<div class=\"col-6\">";
tally += "==============PROFITS=============<br />";
tally += "Total Coal: " + convertCP(mining_totals.coal) + "<br />";
tally += "Total Iron: " + convertCP(mining_totals.iron) + "<br />";
tally += "Total Gold: " + convertCP(mining_totals.gold) + "<br />";
tally += "Total Mithril: " + convertCP(mining_totals.mithril) + "<br />";
tally += "Total Platinum: " + convertCP(mining_totals.platinum) + "<br />";
tally += "=============EXPENSES=============<br />";
tally += "Salaries: " + convertCP(salary) + "<br />";
tally += "Upkeep: " + convertCP(upkeep) + "<br />";
tally += "</div>";
tally += "<div class=\"col-6\">";
tally += "===============TOTALS=============<br />";
tally += "Total Funds: " + convertCP(funds) + "<br />";
tally += "Total Sales: " + convertCP(sales) + "<br />";
tally += "Total Expenses: " + convertCP(expenses) + "<br />";
profit = sales - expenses;
tally += "Profit: " + convertCP(profit) + "<br />";
tally += "Group Share: " + convertCP(players_share) + "<br />";
tally += "<strong>Indv Share: " + convertCP(players_share * 0.2) + "</strong><br />";
tally += "</div>";
tally += "</div>";
$("#output").append(tally);
settings = {starting_funds: starting_funds, expenses: expenses, players_share: players_share, sales: sales,
time_to_live_seed: time_to_live_seed, report_start_date: report_start_date,
report_end_date: report_end_date, duration_adj: duration_adj, profit_rolls: profit_rolls, end_date: end_date,
salary: salary, upkeep: upkeep,
mining_totals: mining_totals};
saved_record.push({settings: settings});
$("#results-box").val(JSON.stringify(saved_record));
}
function output(comment, day, profit, expense) {
if (day >= report_start_date && day <= report_end_date) {
expenses += expense;
sales += profit;
funds = starting_funds + sales - expenses;
if (profit > expense && funds > starting_funds) {
net = profit - expense;
} else {
net = 0;
}
tally = "Funds: " + convertCP(funds) + ", "
tally += "Sale: " + convertCP(profit) + ", "
tally += "Expense: " + convertCP(expense) + ", "
tally += "Profit: " + convertCP(net) + "<br />"
$("#output").append("Day " + day + ": " +comment + "<br />| " + tally + "<br />");
saved_record.push({day: day, net: net, comment: comment, funds: funds, profit: profit, expense: expense, bi_weekly_revenue_tracker: bi_weekly_revenue_tracker, sales: sales, expenses: expenses, salary: salary, upkeep: upkeep});
}
}
function convertCP(value) {
gp = Math.floor(value / 10 / 10)
sp = Math.floor((value % 10) / 10)
cp = Math.floor((value % 100))
return gp + "gp, " + sp + "sp, " + cp + "cp"
}
function mining(profits_adj) {
coal = 10 / 33.25;
iron = 100 / 3.5;
gold = 5000 / 1.5;
plat = 50000 / 6.25;
mith = 75000 / 10;
effort = Math.ceil(Math.random() * (20 - 1) + 1);
daily_efforts = 22 * effort * (profit_adjustment[profits_adj]);
rand = Math.ceil(Math.random() * (10 - 1) + 1 + (profits_adj));
if (rand < 10) {
mining_totals.coal += daily_efforts * coal * ((100 + profits_adj) / 500);
return ["coal", daily_efforts * coal * ((100 + profits_adj) / 500)];
}
if (rand >= 10 && rand <= 14) {
mining_totals.iron += daily_efforts * iron * ((100 + profits_adj) / 500);
return ["iron", daily_efforts * iron * ((100 + profits_adj) / 500)];
}
if (rand >= 15 && rand <= 18) {
mining_totals.gold += daily_efforts * gold * ((100 + profits_adj) / 500);
return ["gold", daily_efforts * gold * ((100 + profits_adj) / 500)];
}
if (rand >= 18 && rand <= 26) {
mining_totals.mithril += daily_efforts * mith * ((100 + profits_adj) / 500 / 2);
return ["mithril", daily_efforts * mith * ((100 + profits_adj) / 500 / 2)];
}
if (rand >= 27 && rand <= 29) {
mining_totals.mithril += daily_efforts * mith * ((100 + profits_adj) / 500);
return ["mithril", daily_efforts * mith * ((100 + profits_adj) / 500)];
}
if (rand >= 30) {
mining_totals.platinum += daily_efforts * plat * ((100 + profits_adj) / 500);
return ["platinum", daily_efforts * plat * ((100 + profits_adj) / 500)];
}
}
function randomEvent(day, profits_adj) {
rand = Math.ceil(Math.random() * (100 - 1) + 1) + profits_adj;
if (rand <= 1) {
output("The mine entrance collapses, no one ever hears from the miners again.", day, 0, 0);
end_date = day + 1;
}
if (rand == 18) {
output("Ogres raid the mine. Several miners are killed, some ore was stolen, and the equipment is in rumbles. Total damage costs: 750g", day, 0, 75000)
}
if (rand >= 115) {
output("A miner finds a large cache of mithril ore worth 10,000gp", day, 1000000, 0)
}
}
function randomDelivery(day, profits_adj, bi_wkly_revenue) {
rand = Math.ceil(Math.random() * (20 - 1 + profits_adj) + 1);
if (rand == 1) {
output("Wagon failed to pay taxes while crossing a major city. Goods seized by authories. Must pay 100gp fine.", i, 0, bi_wkly_revenue + 10000);
}
if (rand >= 2 && rand <= 3) {
output("Shipment lost due to bad weather. Revenue for the shipment is zero.", i, 0, bi_wkly_revenue);
}
if (rand >= 4 && rand <= 6) {
output("Some goods lost due to piracy or theft. Revenue for the shipment is equal to half of the value of the goods.", i, 0, bi_wkly_revenue / 2);
}
if (rand >= 7 && rand <= 12) {
output("Goods sold at market value, but merchants incur extra costs and demand an additional 100gp.", i, 0, 10000);
}
if (rand >= 13 && rand <= 16) {
output("Goods sold at market value. ", i, 0, 0);
}
if (rand >= 17 && rand <= 20) {
output("Merchants are able to exploit supply & demand fluctuations to sell the goods at higher prices. Revenue for the shipment is equal to the value of goods plus 10%.", i, bi_wkly_revenue * 0.1, 0);
}
if (rand >= 21 && rand <= 23) {
output("Merchants use their connections to find someone who is desperate for the shipment. Your revenue for the shipment is equal to the value of goods plus 50%. ", i, bi_wkly_revenue * 0.5, 0);
}
if (rand >= 24 && rand <= 25) {
output("Merchants break a blockade to supply a besieged city. Revenue for the shipment is equal to the value of goods plus 75%. ", i, bi_wkly_revenue * 0.75, 0);
}
if (rand >= 26 && rand <= 29) {
output("Seagoing merchants sell to isolated colony or island community. Revenue for the shipment is equal to double the normal value of your goods!", i, bi_wkly_revenue, 0);
}
if (rand == 30) {
output("Ship lost with owner on board. The insurance company pays you 5000gp!", i, 500000, 0);
}
}
</script>
</body>
</html>