need to debug d2s skills

This commit is contained in:
Hash Borgir 2023-08-06 10:18:00 -06:00
parent 2cfdca65b5
commit 9dc93cbcbd
12 changed files with 525 additions and 23 deletions

214
TCEX.php Normal file
View File

@ -0,0 +1,214 @@
<?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>
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></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>

77
TCEX_Process.php Normal file
View File

@ -0,0 +1,77 @@
<?php
session_start();
error_reporting(E_ALL);error_reporting(E_ALL);
require_once './config.php';
require_once './_pdo.php';
require_once './src/D2Functions.php';
// Define the database file path
define('DB_FILE', $_SESSION['modname'] . ".db");
// Connect to the SQLite database
$db = new SQLite3(DB_FILE);
// Retrieve the POST data
$treasureClass = $db->escapeString($_POST['treasureClass']);
$noDrop = $db->escapeString($_POST['noDrop']);
$prob = [];
for ($i = 1; $i <= 10; $i++) {
$prob[$i] = isset($_POST["prob$i"]) ? $db->escapeString($_POST["prob$i"]) : 0;
}
// Prepare the SQL UPDATE statement
$query = "
UPDATE treasureclassex
SET NoDrop = $noDrop,
Prob1 = {$prob[1]}, Prob2 = {$prob[2]}, Prob3 = {$prob[3]}, Prob4 = {$prob[4]},
Prob5 = {$prob[5]}, Prob6 = {$prob[6]}, Prob7 = {$prob[7]}, Prob8 = {$prob[8]},
Prob9 = {$prob[9]}, Prob10 = {$prob[10]}
WHERE `Treasure Class` = '$treasureClass'
";
// Execute the update statement
$result = $db->exec($query);
if ($result) {
echo "Successfully updated!";
} else {
echo "Failed to update! Error: " . $db->lastErrorMsg();
}
// Define the path to the TSV file
$tsvFilePath = $_SESSION['path'] . "/treasureclassex.txt";
// Open the file for writing
$fileHandle = fopen($tsvFilePath, 'w');
// Query to select all rows from the treasureclassex table
$query = "SELECT * FROM treasureclassex";
// Execute the query
$result = $db->query($query);
// Write the column headers to the file
$columnNames = $result->numColumns();
$headers = [];
for ($i = 0; $i < $columnNames; $i++) {
$headers[] = $result->columnName($i);
}
fputcsv($fileHandle, $headers, "\t");
// Write the rows to the file
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
fputcsv($fileHandle, $row, "\t");
}
// Close the file
fclose($fileHandle);
echo "Successfully updated and written to TSV file!";
// Close the database connection
$db->close();

View File

@ -155,19 +155,19 @@ foreach (glob($tbl . "*.tbl") as $filename) {
// Initialize DataTables on the table
$('.table').DataTable();
// Resize textareas on page load
$('textarea').each(resizeTextarea);
// Resize textareas on input
$('textarea').on('input', resizeTextarea);
// Resize textareas on custom select change
$('.custom-select').change(function () {
$('textarea').each(resizeTextarea);
});
$('.page-link').click(function () {
$('textarea').each(resizeTextarea);
});
// // Resize textareas on page load
// $('textarea').each(resizeTextarea);
//
// // Resize textareas on input
// $('textarea').on('input', resizeTextarea);
//
// // Resize textareas on custom select change
// $('.custom-select').change(function () {
// $('textarea').each(resizeTextarea);
// });
// $('.page-link').click(function () {
// $('textarea').each(resizeTextarea);
// });
});
});
}

View File

@ -278,9 +278,9 @@ foreach (glob($tbl . "*.tbl") as $filename) {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
setInterval(function () {
$('textarea').each(resizeTextarea);
}, 4000);
// setInterval(function () {
// $('textarea').each(resizeTextarea);
// }, 4000);
});
@ -297,10 +297,11 @@ foreach (glob($tbl . "*.tbl") as $filename) {
width: 75px !important;
}
textarea {
overflow: hidden;
resize: none;
scrollbar-width: none; /* For Firefox */
-ms-overflow-style: none; /* For Internet Explorer and Edge */
min-height: 240px;
overflow: ;
resize: vertical;
/* scrollbar-width: none; For Firefox
-ms-overflow-style: none; For Internet Explorer and Edge */
}
#loading-spinner {
}

View File

@ -45,7 +45,7 @@ ini_set('max_execution_time', '0');
*/
$title = '<span class="h1" style="font-size: 100%; ;font-family: ExocetHeavy ; font-weight: bold; color: #880000">D2 Modder</span>';
$author = " HashCasper";
$version = '<span style="font-size: 13px;font-family: monospace; color: #aaa">v6.1 Alpha ';
$version = '<span style="font-size: 13px;font-family: monospace; color: #aaa">v7.0 Alpha ';
define('APP_DB', "D2Modder.db");

BIN
img/chest.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
img/chest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -67,7 +67,7 @@ class D2Files {
"cubemain.txt", // cubemain is processed manually in sqlite cli tool
"misc.txt", // grew too large, process manually in processmanually function
"treasureclass.txt",
"treasureclassex.txt"
//"treasureclassex.txt"
];
$glob = glob($_SESSION['path'] . '*.txt'); // Get a list of all ".txt" files in the specified path.

View File

@ -71,7 +71,7 @@
<script src="/res/app.js"></script>
<!-- Include the necessary jQuery UI and CSS files -->
<script src="/res/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/res/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/res/jquery-ui.css">
<title>D2Modder</title>
</head>

View File

@ -31,6 +31,7 @@
<div class="col Doc-Misc"><?php require_once "Misc.php"; ?></div>
<div class="col Doc-Armor"><?php require_once "Armor.php"; ?></div>
<div class="col Doc-Weapons"><?php require_once "Weapons.php"; ?></div>
<div class="col Doc-TCEX"><?php require_once "TC.php"; ?></div>
</div>

59
src/tabs/TC.php Normal file
View File

@ -0,0 +1,59 @@
<?php
/*
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
?>
<div style="text-align: center; margin-top: 20px;">
<div class="container">
<div class="form-group row">
<div class="" style="text-align: center; margin: 0 auto;">
<a style="margin-top: 60px; text-align: center;" target="_blank" href="/TCEX.php" class="">
<div style="height: 100px;">
<img style="height: 100px;" class="img-fluid" src="/img/chest.png">
</div>
</a>
</div>
</div>
<!-- <a class="btn btn-warning" target="_blank" href="/genDocs.php?cmd=genDocCube">Generate</a> -->
<p>TreasureClassEx.txt Drop Rates</p>
</div>
</div>

150
test.php Normal file
View File

@ -0,0 +1,150 @@
<?php
session_start();
ob_start();
require_once './config.php';
require_once './_pdo.php';
require_once './config.php';
require_once './src/D2Functions.php';
require_once './src/D2ByteReader.php';
require_once './src/D2BitReader.php';
error_reporting(E_ALL);
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"]; // total will be denominator
$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);
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Drop Chances Table</title>
<style>
body {
font-family: Input;
}
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;
}
</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) {
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>
</body>
</html>