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,6 +20,26 @@ 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 = '';
@ -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
@ -239,6 +294,8 @@ $items = "<div class='accordion' id='accordionExample'>";
foreach ($sortedArray as $index => $container) {
$containerId = "container_" . $index;
if (empty($index)) $index = "Socketed";
// Create accordion card for the container
$items .= "<div class='card'>";
$items .= "<div class='card-header' id='{$containerId}-heading'>";
@ -284,7 +341,6 @@ foreach ($sortedArray as $index => $container) {
$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">
<form id='{$c->cData['CharacterName']}' class="charform {$c->cData['CharacterName']}" method="POST" action="/saveCharacter.php">
@ -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">