Better stats editor

This commit is contained in:
Hash Borgir 2023-06-11 18:03:39 -06:00
parent 9c8f50f1f7
commit e68dde2f23
5 changed files with 216 additions and 211 deletions

View File

@ -43,7 +43,7 @@ foreach ($ISCData as $k => $v) {
//$filePath = "D:\Diablo II\MODS\MedianXL2012\save\Test.d2s";
$filePath = "Sorc.d2s";
$filePath = "Test.d2s";
$char = new D2Char($filePath);
//$char->setChar("CharacterStatus", "Died", 0);
@ -51,13 +51,14 @@ $char = new D2Char($filePath);
//$char->setChar("CharacterStatus", "Expansion", 1);
//$char->setChar("LeftmousebuttonskillID", 223);
$char->setAllSkills(1);
$char->setAllSkills(0);
//$char->setSkill(3, 20);
//$char->setChar("CharacterClass", "Necromancer"); // 127
//$char->setChar("CharacterProgression", 1); // 0 in normal, 1 finished normal, 2 finished nm, 3 finished hell
//$char->setChar("CharacterStatus", "Died", 1);
//$char->setChar("CharacterLevel", 99);
$char->setChar("CharacterLevel", 1);
$char->setStat("newskills", 99);
//$char->setStat("strength", 270);
//$char->setStat("energy", 270);
//$char->setStat("dexterity", 270);
@ -88,5 +89,5 @@ unset($char); // destroy $char so we can read it again after writing to it to ge
$char = new D2Char($filePath);
var_dump($char->cData['items']);
var_dump($char->cData);
//var_dump($char->cData['stats']);

View File

@ -400,7 +400,7 @@ $(document).ready(function () {
return "/saveCharacter.php?cmd=" + cmd + "&name=" + name + "&value=" + value + "&filePath=" + filePath;
}
$(".charform input[name='Difficulty'], .charform .skill, #CharacterName, #CharacterClass, #CharacterLevel, #CharacterClass, .stats input, .form-check-input").change(function () {
$(".charform input[name='Difficulty'], .charform .skill, #CharacterName, #CharacterClass, #CharacterLevel, #CharacterClass, .stats input, .form-check-input, #statsdiv input").change(function () {
var name = $(this).attr("name");
var newValue = $(this).val();

View File

@ -115,66 +115,7 @@ switch ($cmd) {
echo "Handling skills command - Skill: $name, Value: $value, File Path: $filePath";
break;
// stats
// Handle strength command
case "strength":
$char->setStat("strength", $value); // Set the "strength" stat to the provided value
echo "Handling strength command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the strength command
break;
// Handle dexterity command
case "dexterity":
$char->setStat("dexterity", $value); // Set the "dexterity" stat to the provided value
echo "Handling dexterity command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the dexterity command
break;
// Handle vitality command
case "vitality":
$char->setStat("vitality", $value); // Set the "vitality" stat to the provided value
echo "Handling vitality command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the vitality command
break;
// Handle energy command
case "energy":
$char->setStat("energy", $value); // Set the "energy" stat to the provided value
echo "Handling energy command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the energy command
break;
// Handle hitpoints command
case "hitpoints":
$char->setStat("hitpoints", $value); // Set the "hitpoints" stat to the provided value
echo "Handling hitpoints command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the hitpoints command
break;
// Handle maxhp command
case "maxhp":
$char->setStat("maxhp", $value); // Set the "maxhp" stat to the provided value
echo "Handling maxhp command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the maxhp command
break;
// Handle mana command
case "mana":
$char->setStat("mana", $value); // Set the "mana" stat to the provided value
echo "Handling mana command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the mana command
break;
// Handle maxmana command
case "maxmana":
$char->setStat("maxmana", $value); // Set the "maxmana" stat to the provided value
echo "Handling maxmana command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the maxmana command
break;
// Handle stamina command
case "stamina":
$char->setStat("stamina", $value); // Set the "stamina" stat to the provided value
echo "Handling stamina command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the stamina command
break;
// Handle maxstamina command
case "maxstamina":
$char->setStat("maxstamina", $value); // Set the "maxstamina" stat to the provided value
echo "Handling maxstamina command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the maxstamina command
break;
case "Died":
$char->setChar("CharacterStatus", "Died", $value); // Set the "CharacterStatusDied" value to the provided value
echo "Handling Died command - Value: $value, File Path: $filePath"; // Display a message indicating the handling of the Died command
@ -317,6 +258,12 @@ switch ($cmd) {
fclose($fp);
break;
// stats commands
case "stats":
echo "Handling $name command. New value: $value";
$char->setStat($name, $value);
break;
// default command
default:
// Handle unknown command

View File

@ -20,90 +20,110 @@ EOT;
<div class="tab-content" id="CTabContent">
<?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';
require_once './src/D2Item.php';
require_once './src/D2Char.php';
error_reporting(E_ERROR | E_PARSE);
set_time_limit(-1);
ini_set('max_input_time', '-1');
ini_set('max_execution_time', '0');
define('DB_FILE', $_SESSION['modname'] . ".db");
PDO_Connect("sqlite:" . DB_FILE);
foreach ($charData as $c) {
$quests = '';
$accordionCounter = 1;
$quests = '';
$accordionCounter = 1;
foreach ($c->cData['Quests'] as $quest) {
foreach ($quest as $difficulty => $q) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapseq-' . $accordionCounter;
$headingId = 'headingq-' . $accordionCounter;
foreach ($c->cData['Quests'] as $quest) {
foreach ($quest as $difficulty => $q) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapseq-' . $accordionCounter;
$headingId = 'headingq-' . $accordionCounter;
$quests .= "<div class='card'>";
$quests .= "<div class='card-header' id='{$headingId}'>";
$quests .= "<h5 class='mb-0'>";
$quests .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$collapseId}' aria-expanded='" . ($accordionCounter === 1 ? 'true' : 'false') . "' aria-controls='{$collapseId}'>{$difficulty}</button>";
$quests .= "</h5>";
$quests .= "</div>";
$quests .= "<div class='card'>";
$quests .= "<div class='card-header' id='{$headingId}'>";
$quests .= "<h5 class='mb-0'>";
$quests .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$collapseId}' aria-expanded='" . ($accordionCounter === 1 ? 'true' : 'false') . "' aria-controls='{$collapseId}'>{$difficulty}</button>";
$quests .= "</h5>";
$quests .= "</div>";
$quests .= "<div id='{$collapseId}' class='collapse {$isExpanded}' aria-labelledby='{$headingId}' data-parent='#accordionExample'>";
$quests .= "<div class='card-body'>";
$quests .= "<div id='{$collapseId}' class='collapse {$isExpanded}' aria-labelledby='{$headingId}' data-parent='#accordionExample'>";
$quests .= "<div class='card-body'>";
foreach ($q as $k => $v) {
$kD = str_replace("_", " ", $k);
$kD = str_replace([" NM", " Hell"], "", $kD);
$checked = ($v == 1) ? 'checked' : '';
foreach ($q as $k => $v) {
$kD = str_replace("_", " ", $k);
$kD = str_replace([" NM", " Hell"], "", $kD);
$checked = ($v == 1) ? 'checked' : '';
$quests .= "<div class='qcheckgroup'>";
$quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$k}' {$checked}>";
$quests .= "<label for='{$k}'>{$kD}</label><br>";
$quests .= "</div>";
$quests .= "<div class='qcheckgroup'>";
$quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$k}' {$checked}>";
$quests .= "<label for='{$k}'>{$kD}</label><br>";
$quests .= "</div>";
}
$quests .= "</div>";
$quests .= "</div>";
$quests .= "</div>";
$accordionCounter++;
}
}
$quests .= "</div>";
$quests .= "</div>";
$quests .= "</div>";
$accordionCounter++;
}
}
$wps = '';
//$wps .= "<input type='radio' value='1' name='wp_all' id='wp_all'>";
//$wps .= "<label style='font-size: 1.3em;color:green;' for='wp_all'>Enable All Waypoints</label><br>";
//$wps .= "<input type='radio' value='0' name='wp_all' id='wp_all_off'>";
//$wps .= "<label style='font-size: 1.3em; color: red;' for='wp_all_off'>Disable All Waypoints</label><hr>";
$wps = '';
$accordionCounter = 1;
$wps = '';
$accordionCounter = 1;
foreach ($c->cData['Waypoints'] as $diff => $waypoints) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapsewps-' . $accordionCounter;
$headingId = 'headingwps-' . $accordionCounter;
foreach ($c->cData['Waypoints'] as $diff => $waypoints) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapsewps-' . $accordionCounter;
$headingId = 'headingwps-' . $accordionCounter;
$wps .= "<div class='card'>";
$wps .= "<div class='card-header' id='{$headingId}'>";
$wps .= "<h5 class='mb-0'>";
$wps .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$collapseId}' aria-expanded='" . ($accordionCounter === 1 ? 'true' : 'false') . "' aria-controls='{$collapseId}'>{$diff}</button>";
$wps .= "</h5>";
$wps .= "</div>";
$wps .= "<div class='card'>";
$wps .= "<div class='card-header' id='{$headingId}'>";
$wps .= "<h5 class='mb-0'>";
$wps .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$collapseId}' aria-expanded='" . ($accordionCounter === 1 ? 'true' : 'false') . "' aria-controls='{$collapseId}'>{$diff}</button>";
$wps .= "</h5>";
$wps .= "</div>";
$wps .= "<div id='{$collapseId}' class='collapse {$isExpanded}' aria-labelledby='{$headingId}' data-parent='#accordionExample'>";
$wps .= "<div class='card-body'>";
$wps .= "<div id='{$collapseId}' class='collapse {$isExpanded}' aria-labelledby='{$headingId}' data-parent='#accordionExample'>";
$wps .= "<div class='card-body'>";
array_pop($waypoints);
$wp_count = 0;
foreach ($waypoints as $k => $v) {
$kD = str_replace("_", " ", $k);
$kD = str_replace([" NM", " Hell"], "", $kD);
$checked = ($v == 1 && $k != '') ? 'checked ' : '';
array_pop($waypoints);
$wp_count = 0;
foreach ($waypoints as $k => $v) {
$kD = str_replace("_", " ", $k);
$kD = str_replace([" NM", " Hell"], "", $kD);
$checked = ($v == 1 && $k != '') ? 'checked ' : '';
$wps .= "<div class='wcheckgroup'>";
$wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$k}' {$checked}>";
$wps .= "<label for='{$k}'>{$kD}</label><br>";
$wps .= "</div>";
$wp_count++;
}
$wps .= "<div class='wcheckgroup'>";
$wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$k}' {$checked}>";
$wps .= "<label for='{$k}'>{$kD}</label><br>";
$wps .= "</div>";
$wp_count++;
}
$wps .= "</div>";
$wps .= "</div>";
$wps .= "</div>";
$wps .= "</div>";
$wps .= "</div>";
$accordionCounter++;
}
$wps .= "</div>";
$accordionCounter++;
}
$classOptions = [
'Amazon', 'Assassin', 'Barbarian', 'Druid', 'Paladin', 'Necromancer', 'Sorceress'
@ -152,41 +172,41 @@ foreach ($c->cData['Waypoints'] as $diff => $waypoints) {
// $skillcounter++;
// }
$skillsByPage = array();
foreach ($c->cData['skills']['skills'] as $skNum => $skill) {
$page = $skill['page'];
if (!isset($skillsByPage[$page])) {
$skillsByPage[$page] = array();
}
$skillsByPage[$page][$skNum] = $skill;
}
$skillsByPage = array();
foreach ($c->cData['skills']['skills'] as $skNum => $skill) {
$page = $skill['page'];
if (!isset($skillsByPage[$page])) {
$skillsByPage[$page] = array();
}
$skillsByPage[$page][$skNum] = $skill;
}
$skillDivs = '';
$accordionCounter = 1;
foreach ($skillsByPage as $page => $skills) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapseskills-' . $accordionCounter;
$headingId = 'headingskills-' . $accordionCounter;
$skillDivs = '';
$accordionCounter = 1;
foreach ($skillsByPage as $page => $skills) {
$isExpanded = ($accordionCounter === 1) ? 'show' : '';
$collapseId = 'collapseskills-' . $accordionCounter;
$headingId = 'headingskills-' . $accordionCounter;
$skillDivs .= '<div class="card">';
$skillDivs .= '<div class="card-header" id="' . $headingId . '">';
$skillDivs .= '<h5 class="mb-0">';
$skillDivs .= '<button class="btn btn-link" data-toggle="collapse" data-target="#' . $collapseId . '" aria-expanded="' . ($accordionCounter === 1 ? 'true' : 'false') . '" aria-controls="' . $collapseId . '">Page ' . $page . '</button>';
$skillDivs .= '</h5>';
$skillDivs .= '</div>';
$skillDivs .= '<div class="card">';
$skillDivs .= '<div class="card-header" id="' . $headingId . '">';
$skillDivs .= '<h5 class="mb-0">';
$skillDivs .= '<button class="btn btn-link" data-toggle="collapse" data-target="#' . $collapseId . '" aria-expanded="' . ($accordionCounter === 1 ? 'true' : 'false') . '" aria-controls="' . $collapseId . '">Page ' . $page . '</button>';
$skillDivs .= '</h5>';
$skillDivs .= '</div>';
$skillDivs .= '<div id="' . $collapseId . '" class="collapse ' . $isExpanded . '" aria-labelledby="' . $headingId . '" data-parent="#accordionExample">';
$skillDivs .= '<div class="card-body">';
foreach ($skills as $skillNumber => $skill) {
$skillNumber++;
$skillDivs .= "<input cmd='skills' style='width: 64px;' class='skill-{$skill['id']} skill' name='$skillNumber' type='number' min='0' max='255' value='{$skill['points']}'>: {$skill['skill']}<hr>";
}
$skillDivs .= '</div>';
$skillDivs .= '</div>';
$skillDivs .= '<div id="' . $collapseId . '" class="collapse ' . $isExpanded . '" aria-labelledby="' . $headingId . '" data-parent="#accordionExample">';
$skillDivs .= '<div class="card-body">';
foreach ($skills as $skillNumber => $skill) {
$skillNumber++;
$skillDivs .= "<input cmd='skills' style='width: 64px;' class='skill-{$skill['id']} skill' name='$skillNumber' type='number' min='0' max='255' value='{$skill['points']}'>: {$skill['skill']}<hr>";
}
$skillDivs .= '</div>';
$skillDivs .= '</div>';
$skillDivs .= '</div>';
$accordionCounter++;
}
$skillDivs .= '</div>';
$accordionCounter++;
}
$statuses = [
@ -208,6 +228,41 @@ foreach ($skillsByPage as $page => $skills) {
HTML;
}
$sql = "SELECT ID,Stat,CSvBits FROM itemstatcost WHERE Saved=1";
$ISCData = PDO_FetchAll($sql);
foreach ($ISCData as $k) {
$ISC[$k["Stat"]] = $k['CSvBits'];
}
// stats
$cDataStats = $c->cData["stats"];
$commonKeys = array_intersect_key($cDataStats, $ISC);
foreach ($commonKeys as $key => $value) {
$cDataStats[$key] = $ISC[$key];
}
$stats = '';
foreach ($cDataStats as $stat => $bits) {
// Calculate the maximum value for the number of bits
$maxValue = pow(2, $bits) - 1;
// Get the default value from $c->cData['stats']
$defaultValue = isset($c->cData['stats'][$stat]) ? $c->cData['stats'][$stat] : 0;
// Create an HTML input for the stat
$stats .= '<div class="stats" id="statsdiv" style="border:1px solid #ccc;"><input cmd="stats" type="number" id="' . $stat . '" name="' . $stat . '" max="' . $maxValue . '" value="' . $defaultValue . '">';
// Create an HTML label for the stat
$stats .= '<label for="' . $stat . '">' . ucfirst($stat) . ':<br> Max Value - ' . $maxValue . '</label><br></div>';
}
// Create a new array to store objects sorted by container
$sortedArray = [];
// Iterate over the original array
@ -234,56 +289,57 @@ HTML;
$items = "<div class='accordion' id='accordionExample'>";
$items = "<div class='accordion' id='accordionExample'>";
foreach ($sortedArray as $index => $container) {
$containerId = "container_" . $index;
foreach ($sortedArray as $index => $container) {
$containerId = "container_" . $index;
// Create accordion card for the container
$items .= "<div class='card'>";
$items .= "<div class='card-header' id='{$containerId}-heading'>";
$items .= "<h5 class='mb-0'>";
$items .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$containerId}-collapse' aria-expanded='" . ($index === 0 ? "true" : "false") . "' aria-controls='{$containerId}-collapse'>{$index}</button>";
$items .= "</h5>";
$items .= "</div>";
if (empty($index)) $index = "Socketed";
// Create accordion content for the container
$isExpanded = ($index === 0) ? "show" : "";
$items .= "<div id='{$containerId}-collapse' class='collapse {$isExpanded}' aria-labelledby='{$containerId}-heading' data-parent='#accordionExample'>";
$items .= "<div class='card-body'>";
$items .= "<div class='row'>";
// Create accordion card for the container
$items .= "<div class='card'>";
$items .= "<div class='card-header' id='{$containerId}-heading'>";
$items .= "<h5 class='mb-0'>";
$items .= "<button class='btn btn-link' data-toggle='collapse' data-target='#{$containerId}-collapse' aria-expanded='" . ($index === 0 ? "true" : "false") . "' aria-controls='{$containerId}-collapse'>{$index}</button>";
$items .= "</h5>";
$items .= "</div>";
foreach ($container as $item) {
$i = array_filter($item->iData);
// Create accordion content for the container
$isExpanded = ($index === 0) ? "show" : "";
$items .= "<div id='{$containerId}-collapse' class='collapse {$isExpanded}' aria-labelledby='{$containerId}-heading' data-parent='#accordionExample'>";
$items .= "<div class='card-body'>";
$items .= "<div class='row'>";
foreach ($container as $item) {
$i = array_filter($item->iData);
$items .= "<div style='border: 1px solid #ccc;' class='col-md-3'>";
$items .= "<p style='font-size: 120%;'>";
$items .= "{$i['basename']}<br>";
$items .= "<img src='/docs/{$_SESSION['modname']}/img/items/{$i['txt']['invfile']}.png'>";
$items .= "</p>";
$items .= "<ul>";
$items .= "<li>Code: {$i['code']}</li>";
$items .= "<li>Socketed: {$i['gems_in']}</li>";
$items .= "<li>Item Level: {$i['ilvl']}</li>";
$items .= "<li>Identified: {$i['identified']}</li>";
$items .= "<li>Starting Item: {$i['startingItem']}</li>";
$items .= "<li>Ethereal: {$i['ethereal']}</li>";
$items .= "<li>Quality: {$i['iquality']}</li>";
$items .= "<li>Container: {$i['container']}</li>";
$items .= "<li>Runeword: {$i['runeword']}</li>";
$items .= "</ul>";
$items .= "</div>";
}
$items .= "</div>";
$items .= "</div>";
$items .= "</div>";
$items .= "</div>";
}
$items .= "<div style='border: 1px solid #ccc;' class='col-md-3'>";
$items .= "<p style='font-size: 120%;'>";
$items .= "{$i['basename']}<br>";
$items .= "<img src='/docs/{$_SESSION['modname']}/img/items/{$i['txt']['invfile']}.png'>";
$items .= "</p>";
$items .= "<ul>";
$items .= "<li>Code: {$i['code']}</li>";
$items .= "<li>Socketed: {$i['gems_in']}</li>";
$items .= "<li>Item Level: {$i['ilvl']}</li>";
$items .= "<li>Identified: {$i['identified']}</li>";
$items .= "<li>Starting Item: {$i['startingItem']}</li>";
$items .= "<li>Ethereal: {$i['ethereal']}</li>";
$items .= "<li>Quality: {$i['iquality']}</li>";
$items .= "<li>Container: {$i['container']}</li>";
$items .= "<li>Runeword: {$i['runeword']}</li>";
$items .= "</ul>";
$items .= "</div>";
}
$items .= "</div>";
$items .= "</div>";
$items .= "</div>";
$items .= "</div>";
}
$items .= "</div>";
$tabContent .= <<<EOT
<div style="background: white; margin-top: 10px;" class="tab-pane fade" id="{$c->cData['CharacterName']}" role="tabpanel" aria-labelledby="{$c->cData['CharacterName']}-tab">
@ -315,7 +371,7 @@ $checkboxes
<hr>
<!-- STATS -->
<!-- STATS
<div class="stats">
<div class="form-row" style="background: #eed;">
<div class="form-group col-md-3">
@ -365,8 +421,9 @@ $checkboxes
<input type="number" class="form-control" id="maxstamina" name="maxstamina" min="1" max="2097151" value="{$c->cData['stats']['maxstamina']}" required>
</div>
</div>
</div>
</div>-->
<hr>
$stats
<div style="background:;">
<h3 style="text-align: center">Skills</h3>
<div class="accordion" id="accordionExample">