-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
232 lines (216 loc) · 9.1 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
<!DOCTYPE html>
<html>
<head>
<title>Torn Work Stat Training Calculator</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
</head>
<body class="bg-dark text-white">
<!-- Use Bootstrap container class to wrap form -->
<div class="container">
<h1>Trains Calculator</h1>
<br/>
<form onsubmit="calculate(); return false;">
<!-- Use Bootstrap form-group class for form elements -->
<div class="form-group">
<h2>Current Stats</h2>
<div class="row container-fluid">
<div class="col-sm-6 col-md-4">
<!-- Use Bootstrap form-control class for input elements -->
<label for="current-man">Current Man:</label>
<input type="tel" class="form-control bg-dark text-white" id="current-man" name="current-man" tabindex="1">
<label for="current-int">Current Int:</label>
<input type="tel" class="form-control bg-dark text-white" id="current-int" name="current-int" tabindex="3">
<label for="current-end">Current End:</label>
<input type="tel" class="form-control bg-dark text-white" id="current-end" name="current-end" tabindex="5">
</div>
<div class="col-sm-6 col-md-4">
<label for="target-man">Target Man:</label>
<input type="tel" class="form-control bg-dark text-white" id="target-man" name="target-man" tabindex="2">
<label for="target-int">Target Int:</label>
<input type="tel" class="form-control bg-dark text-white" id="target-int" name="target-int" tabindex="4">
<label for="target-end">Target End:</label>
<input type="tel" class="form-control bg-dark text-white" id="target-end" name="target-end" tabindex="6">
</div>
</div>
</div>
<br/>
<h2>Daily Stat Gains</h2>
<div class="row container-fluid">
<div class="form-group col-sm-4 col-md-2">
<label for="man-gain">Man:</label>
<input type="tel" class="form-control bg-dark text-white" id="man-gain" name="man-gain" tabindex="7">
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="int-gain">Int:</label>
<input type="tel" class="form-control bg-dark text-white" id="int-gain" name="int-gain" tabindex="8">
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="end-gain">End:</label>
<input type="tel" class="form-control bg-dark text-white" id="end-gain" name="end-gain" tabindex="9">
</div>
</div>
<br/>
<h2>Trains per Day</h2>
<div class="row container-fluid">
<div class="form-group col-sm-4 col-md-2">
<label for="trains-per-day">Trains per day:</label>
<input type="tel" class="form-control bg-dark text-white" id="trains-per-day" name="trains-per-day" tabindex="10">
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="cost-per-train">Cost per train:</label>
<input type="tel" class="form-control bg-dark text-white" id="cost-per-train" name="trains-per-day" tabindex="11">
</div>
</div>
<br/>
<input type="submit" class="btn border btn-lg text-white" value="Submit" tabindex="12">
</form>
<br/>
<h2>Output</h2>
<p id="total-trains">Total Trains: 0 - Total Cost: $0 ($0 per train)</p>
<table class="table text-white">
<tr>
<th>Stats</th>
<th>Primary Trains</th>
<th>Secondary Trains</th>
<th>Total Stats</th>
</tr>
<tr>
<th>Man</th>
<td id="man-primary"></td>
<td id="man-secondary"></td>
<td id="man-total"></td>
</tr>
<tr>
<th>Int</th>
<td id="int-primary"></td>
<td id="int-secondary"></td>
<td id="int-total"></td>
</tr>
<tr>
<th>End</th>
<td id="end-primary"></td>
<td id="end-secondary"></td>
<td id="end-total"></td>
</tr>
</table>
</body>
<script>
var inputElements = document.querySelectorAll('input[type="tel"]');
inputElements.forEach(function(inputElement) {
new AutoNumeric(inputElement, {decimalPlaces: 0});
});
function calculate() {
// Take values from the form
let man = Number(document.getElementById("current-man").value.replace(/\D/g, ''));
let end = Number(document.getElementById("current-end").value.replace(/\D/g, ''));
let intel = Number(document.getElementById("current-int").value.replace(/\D/g, ''));
let targetMan = Number(document.getElementById("target-man").value.replace(/\D/g, ''));
let targetEnd = Number(document.getElementById("target-end").value.replace(/\D/g, ''));
let targetInt = Number(document.getElementById("target-int").value.replace(/\D/g, ''));
// Check if current stats are already greater than or equal to target stats
if (man >= targetMan && end >= targetEnd && intel >= targetInt) {
return;
}
console.log('here');
// Take growth values dependant on job
let manGrowth = Number(document.getElementById("man-gain").value.replace(/\D/g, ''));
let endGrowth = Number(document.getElementById("end-gain").value.replace(/\D/g, ''));
let intGrowth = Number(document.getElementById("int-gain").value.replace(/\D/g, ''));
let trainsPerDay = Number(document.getElementById("trains-per-day").value.replace(/\D/g, ''));
// Take cost per train
let costPerTrain = Number(document.getElementById("cost-per-train").value.replace(/\D/g, ''));
// Initialize variables to store the current values of Man, End, and Intel
let iterations = 0;
let currentMan = man;
let currentEnd = end;
let currentIntel = intel;
let manPrimary = 0;
let endPrimary = 0;
let intelPrimary = 0;
let manSecondary = 0;
let endSecondary = 0;
let intelSecondary = 0;
let days = 0;
// Keep looping until all three variables have reached their target values
while (currentMan < targetMan || currentEnd < targetEnd || currentIntel < targetInt) {
// Calculate the difference between the current value and the target value for each variable
let manDiff = targetMan - currentMan;
let endDiff = targetEnd - currentEnd;
let intelDiff = targetInt - currentIntel;
if(manDiff >= endDiff && manDiff >= intelDiff) {
// Set Man as the primary input
currentMan += 50;
manPrimary++;
// Determine which variable to set as the secondary input
if (endDiff >= intelDiff) {
currentEnd += 25;
endSecondary++;
} else {
currentIntel += 25;
intelSecondary++;
}
} else if(endDiff >= manDiff && endDiff >= intelDiff) {
// Set End as the primary input
currentEnd += 50;
endPrimary++;
// Determine which variable to set as the secondary input
if (manDiff >= intelDiff) {
currentMan += 25;
manSecondary++;
} else {
currentIntel += 25;
intelSecondary++;
}
} else {
// Set Int as the primary input
currentIntel += 50;
intelPrimary++;
// Determine which variable to set as the secondary input
if (manDiff >= endDiff) {
currentMan += 25;
manSecondary++;
} else {
currentEnd += 25;
endSecondary++;
}
}
// Increase the days counter and reset the number of trains for the day
iterations++;
days++;
if(days == trainsPerDay) {
currentMan += manGrowth;
currentEnd += endGrowth;
currentIntel += intGrowth;
days = 0;
}
}
// Calculate the total number of primary and secondary trains
let totalManPrimary = manPrimary;
let totalEndPrimary = endPrimary;
let totalIntelPrimary = intelPrimary;
let totalManSecondary = manSecondary;
let totalEndSecondary = endSecondary;
let totalIntelSecondary = intelSecondary;
let totalTrains = manPrimary + endPrimary + intelPrimary;
let totalCost = costPerTrain * totalTrains;
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Print the results to the form
document.getElementById("man-primary").innerHTML = numberWithCommas(totalManPrimary);
document.getElementById("end-primary").innerHTML = numberWithCommas(totalEndPrimary);
document.getElementById("int-primary").innerHTML = numberWithCommas(totalIntelPrimary);
document.getElementById("man-secondary").innerHTML = numberWithCommas(totalManSecondary);
document.getElementById("end-secondary").innerHTML = numberWithCommas(totalEndSecondary);
document.getElementById("int-secondary").innerHTML = numberWithCommas(totalIntelSecondary);
document.getElementById("man-total").innerHTML = numberWithCommas(currentMan);
document.getElementById("end-total").innerHTML = numberWithCommas(currentEnd);
document.getElementById("int-total").innerHTML = numberWithCommas(currentIntel);
document.getElementById("total-trains").innerHTML = "Total Trains: " + numberWithCommas(totalTrains) + " - Total Cost: $" + numberWithCommas(totalCost) + " ($" + numberWithCommas(costPerTrain) + " per train)"
}
</script>
</div>
</body>
</html>