d2tools/TCEX.php
2023-09-10 20:02:58 -06:00

218 lines
7.5 KiB
PHP

<?php
session_start();
ob_start();
require_once './config.php';
require_once './_pdo.php';
require_once './src/D2Functions.php';
require_once './src/D2ByteReader.php';
require_once './src/D2BitReader.php';
set_time_limit(-1);
ini_set('max_input_time', '-1');
ini_set('max_execution_time', '0');
define('DB_FILE', $_SESSION['modname'] . ".db");
try {
PDO_Connect("sqlite:" . DB_FILE);
} catch (Exception $e) {
echo "Connection error: " . $e->getMessage();
}
$query = "SELECT * FROM treasureclassex WHERE `Treasure Class` != ''";
$res = array_filter(PDO_FetchAll($query));
$dropChances = [];
foreach ($res as $r) {
$total = (int) $r['NoDrop'];
for ($i = 1; $i <= 10; $i++) {
if (!empty($r["Item$i"])) {
$total += (int) $r["Prob$i"];
$ic = $r["Item$i"];
$prob = (int) $r["Prob$i"];
$dropChances[$r['Treasure Class']]["nd"] = $r['NoDrop'];
$dropChances[$r['Treasure Class']]["nodrop"] = round(((int) $r['NoDrop'] / $total) * 100, 2);
$dropChances[$r['Treasure Class']]["items"]["Item$i"]["code"] = $ic;
$dropChances[$r['Treasure Class']]["items"]["Item$i"]["prob"] = $prob;
$dropChances[$r['Treasure Class']]["items"]["Item$i"]["chance"] = round(($prob / $total) * 100, 2);
}
}
}
header("Content-Type: text/html");
?>
<!DOCTYPE html>
<html>
<head>
<title>Drop Chances Table</title>
<link rel="stylesheet" href="/res/bootstrap.min.css">
<script src="/res/jquery-3.5.1.min.js"></script>
<script src="/res/popper.min.js"></script>
<script src="/res/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('input.no-drop, input.prob').on('input', function () {
var row = $(this).closest('.first-table-row');
var noDrop = +row.find('input.no-drop').val();
var total = noDrop;
row.find('input.prob').each(function () {
total += +$(this).val();
});
row.find('span.no-drop-chance').text((noDrop / total * 100).toFixed(2));
row.find('td').each(function () {
var probInput = $(this).find('input.prob');
if (probInput.length) {
var prob = +probInput.val();
$(this).find('span.chance').text((prob / total * 100).toFixed(2));
}
});
// Update the database
var treasureClass = row.find('.tc').text();
var data = {
'treasureClass': treasureClass,
'noDrop': row.find('input.no-drop').val(),
};
row.find('input.prob').each(function (index) {
data[`prob${index + 1}`] = $(this).val();
});
$.post("TCEX_Process.php", data, function (response) {
console.log(response); // Log the response from the server
});
});
});
</script>
<style>
@font-face {
font-family: 'ExocetHeavy';
src: url('/fonts/ExocetHeavy.eot'),
url('/fonts/ExocetHeavy.eot?#iefix') format('embedded-opentype'),
url('/fonts/ExocetHeavy.woff2') format('woff2'),
url('/fonts/ExocetHeavy.woff') format('woff'),
url('/fonts/ExocetHeavy.ttf') format('truetype'),
url('/fonts/ExocetHeavy.svg#ExocetHeavy') format('svg');
font-weight: 900;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'ExocetLight';
src: url('/fonts/ExocetLight.ttf') format('truetype');
font-weight: 900;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Lato';
src: url('/fonts/Lato-Regular.ttf') format('truetype');
font-weight: 900;
font-style: normal;
font-display: swap;
}
body {
font-family: Lato;
font-size: 12px;
}
table {
border-collapse: separate;
border-spacing: 0 15px;
width: 100%;
}
#second-table th {
border: 1px solid #ccc;
padding: 2px;
}
#second-table tr {
text-align: center;
}
td {
border-right: 1px solid #ccc;
}
/* Color even rows in the first table */
#first-table .first-table-row:nth-child(even) {
background-color: #f9f9f9;
}
/* Color odd rows in the first table (if you want a different color than even rows) */
#first-table .first-table-row:nth-child(odd) {
background-color: #e5e5e5;
}
#second-table td {
border: none;
}
#first-table-row {
margin-bottom: 10px;
}
input {
padding: 2px;
height: 24px;
width: 64px;
margin-bottom: 5px;
border: none;
}
.chance, .no-drop-chance {
color: red;
font-weight: bold;
font-size: 22px;
font-family: ExocetHeavy;
}
.tc {
color: blue;
}
tr:nth-child(even) td:nth-child(odd),
tr:nth-child(odd) td:nth-child(even) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<h1>Drop Chances Calculator by HCB (Hash Borgir)</h1>
<form id="dropChancesForm">
<table id="first-table">
<!-- Existing Table Content -->
<!-- ... -->
<tbody>
<?php
foreach ($dropChances as $treasureClass => $row) {
$nodrop = $row['nodrop'];
echo "<tr class='first-table-row'>";
echo "<td class='tc'>$treasureClass</td>";
echo "<td><input class='no-drop' type='number' value='{$row["nd"]}'><span class='no-drop-chance'>$nodrop</span>%</td>";
foreach ($row['items'] as $item => $values) {
echo "<td>
<table id='second-table'>
<thead>
<tr>
<th>code</th>
<th>prob</th>
<th>chance</th>
</tr>
</thead>
<tr>
<td>{$values["code"]}</td>
<td><input class='prob' type='number' value='{$values["prob"]}'></td>
<td><span class='chance'>{$values["chance"]}</span>%</td>
</tr>
</table>
</td>";
}
echo "</tr>";
}
?>
</tbody>
</table>
</form>
</body>
</html>