levels parser started

This commit is contained in:
Hash Borgir 2023-09-10 02:04:02 -06:00
parent 9bc9868b29
commit 7b3869530f

199
test.php
View File

@ -22,129 +22,122 @@ try {
echo "Connection error: " . $e->getMessage();
}
$query = "SELECT * FROM treasureclassex WHERE `Treasure Class` != ''";
$res = array_filter(PDO_FetchAll($query));
$query = "SELECT Id,LevelName FROM levels";
$levels = PDO_FetchAssoc($query);
$dropChances = [];
$query = "SELECT * FROM levels";
$levelsAll = PDO_FetchAll($query);
foreach ($res as $r) {
$total = (int) $r['NoDrop'];
$query = "SELECT monstats.Id, strings.String AS Name
FROM monstats
LEFT JOIN strings ON monstats.NameStr = strings.Key;";
$monstats = PDO_FetchAssoc($query);
for ($i = 1; $i <= 10; $i++) {
if (!empty($r["Item$i"])) {
$total += (int) $r["Prob$i"]; // total will be denominator
//ddump($monstats);
$ic = $r["Item$i"]; // get item code
$prob = (int) $r["Prob$i"];
// now every item divided by denominator = dropchance
$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);
$query = "SELECT LevelName,Vis0,Vis1,Vis2,Vis3,Vis4,Vis5,Vis6,Vis7 FROM levels";
$res = PDO_FetchAll($query);
$output = [];
foreach ($res as $key => $item) {
$newItem = [];
$newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item
foreach ($levelsAll[$key] as $levelsKey => $levelsValue) {
//$newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue;
}
$foundLevels = []; // Store found level names to avoid duplicates
foreach ($item as $subKey => $subItem) {
// Check if the key starts with 'Vis', has a corresponding level, is non-empty, and is not a duplicate
if (strpos($subKey, 'Vis') === 0 && isset($levels[$subItem]) && $levels[$subItem] !== '' && !in_array($levels[$subItem], $foundLevels)) {
$newItem[$subKey] = "(" . $subItem . ") " . $levels[$subItem];
$foundLevels[] = $levels[$subItem]; // Add to found levels
}
}
$output[] = array_filter($newItem); // Add the modified item to the output array
}
unset($output[0]);
ddump($output);
?>
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Drop Chances Table</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Levels Table</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
font-family: Input;
}
table {
border-collapse: separate;
border-spacing: 0 15px;
width: 100%;
/* Colorize alternate rows */
.table-striped tbody tr:nth-child(odd) {
background-color: #f2f2f2; /* Alternate row color */
}
#second-table th {
border: 1px solid #ccc;
padding: 2px;
/* Colorize alternate columns */
.table-striped tbody tr td:nth-child(odd) {
background-color: #e6e6e6; /* Alternate column color */
}
#second-table tr {
text-align: center;
.sticky-top th {
position: sticky;
top: 0;
background-color: #ffffff; /* Header background color */
}
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;
}
</style>
</style>
</head>
<body>
<h1>Drop Chances Table</h1>
<table id="first-table">
<thead>
<tr class="first-table-row">
<th>Treasure Class</th>
<th>NoDrop %</th>
<th>Item1</th>
<th>Item2</th>
<th>Item3</th>
<th>Item4</th>
<th>Item5</th>
<th>Item6</th>
<th>Item7</th>
<th>Item8</th>
<th>Item9</th>
<th>Item10</th>
</tr>
</thead>
<tbody>
<?
foreach ($dropChances as $treasureClass => $row) {
$nodrop = $row['nodrop']; // no drop chance
echo "<tr class='first-table-row'>";
echo "<td>$treasureClass</td>";
echo "<td>NoDrop : {$row["nd"]}<br>Chance: $nodrop</td>";
foreach ($row['items'] as $item => $values) {
<?php
// Start the HTML table with Bootstrap classes
echo "<table id='myTable' class='table table-bordered table-striped'>";
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>{$values["prob"]}</td>
<td>{$values["chance"]}%</td>
</tr>
</table>
</td>";
}
echo "</tr>";
}
?>
</tbody>
</table>
// Display table headers with Bootstrap styling
$headers = ['Id', 'Name', 'LevelName', "", "", "", ""];
for ($i = 0; $i < 8; $i++) {
$headers[] = "Vis" . $i;
}
for ($i = 1; $i <= 25; $i++) {
$headers[] = "mon" . $i;
}
$headers[] = 'MonDen';
echo "<thead class='thead-dark'>"; // Add thead and use Bootstrap dark theme
echo "<tr class='sticky-top'>";
foreach ($headers as $header) {
echo "<th>" . $header . "</th>";
}
echo '</tr>';
echo "</thead>";
// Display table data with Bootstrap styling
echo "<tbody>";
foreach ($output as $level) {
echo "<tr>";
foreach ($headers as $header) {
if (isset($level[$header])) {
echo "<td>" . $level[$header] . "</td>";
} else {
echo "<td></td>";
}
}
echo "</tr>";
}
echo "</tbody>";
// End the HTML table
echo "</table>";
?>
<!-- Include Bootstrap JS and jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>