Processing custom strings for some properties, like skill-rand. https://d2mods.info/forum/kb/viewarticle?a=345. fixed

This commit is contained in:
Hash Borgir 2022-04-27 16:26:43 -06:00
parent c40f67545f
commit db3c6473ca

View File

@ -2,11 +2,11 @@
class D2ItemData {
public $strings;
public $images;
public $strings;
public $images;
public function getImages() {
$sql = "
public function getImages() {
$sql = "
SELECT code,invfile,type,type2 FROM armor
UNION ALL
SELECT code,invfile,type,type2 FROM misc
@ -14,216 +14,216 @@ class D2ItemData {
SELECT code,invfile,type,type2 FROM weapons
";
$res = PDO_FetchAll($sql);
$res = PDO_FetchAll($sql);
$isc = null;
foreach ($res as $r) {
$isc1[$r['code']] = $r;
$isc1[$r['code']]['code'] = $r['prop'];
$isc = null;
foreach ($res as $r) {
$isc1[$r['code']] = $r;
$isc1[$r['code']]['code'] = $r['prop'];
$isc2[$r['type']] = $r;
$isc2[$r['type']]['type'] = $r['prop'];
}
$isc2[$r['type']] = $r;
$isc2[$r['type']]['type'] = $r['prop'];
}
$this->images = array_merge($isc1, $isc2);
$this->images = array_merge($isc1, $isc2);
unset($isc1);
unset($isc2);
}
unset($isc1);
unset($isc2);
}
public function uniqueItems($index, $doc = FALSE) {
// This is where we get props for each item
$sql = "SELECT * FROM uniqueitems WHERE enabled='1' AND `index`=?";
public function uniqueItems($index, $doc = FALSE) {
$res = (PDO_FetchRow($sql, [$index]));
// This is where we get props for each item
$sql = "SELECT * FROM uniqueitems WHERE enabled='1' AND `index`=?";
/*
* Get invfile code all 3 item tables wherever it is
*
*/
$res = (PDO_FetchRow($sql, [$index]));
if (empty($this->images)) {
$this->getImages();
}
/*
* Get invfile code all 3 item tables wherever it is
*
*/
$res['invfile'] = $this->images[$res['code']]['invfile'];
$return = $res;
if (empty($this->images)) {
$this->getImages();
}
/*
* for all props for this unique item, get ISC strings
*/
$res['invfile'] = $this->images[$res['code']]['invfile'];
$return = $res;
$props = array_filter([
"Prop1" => array_filter(
["prop1" => $return['prop1'], "par1" => $return['par1'], "min1" => $return['min1'], "max1" => $return['max1']]
),
"Prop2" => array_filter(
["prop2" => $return['prop2'], "par1" => $return['par2'], "min1" => $return['min2'], "max1" => $return['max2']]
),
"Prop3" => array_filter(
["prop3" => $return['prop3'], "par1" => $return['par3'], "min1" => $return['min3'], "max1" => $return['max3']]
),
"Prop4" => array_filter(
["prop4" => $return['prop4'], "par1" => $return['par4'], "min1" => $return['min4'], "max1" => $return['max4']]
),
"Prop5" => array_filter(
["prop5" => $return['prop5'], "par1" => $return['par5'], "min1" => $return['min5'], "max1" => $return['max5']]
),
"Prop6" => array_filter(
["prop6" => $return['prop6'], "par1" => $return['par6'], "min1" => $return['min6'], "max1" => $return['max6']]
),
"Prop7" => array_filter(
["prop7" => $return['prop7'], "par1" => $return['par7'], "min1" => $return['min7'], "max1" => $return['max7']]
),
"Prop8" => array_filter(
["prop8" => $return['prop8'], "par1" => $return['par8'], "min1" => $return['min8'], "max1" => $return['max8']]
),
"Prop9" => array_filter(
["prop9" => $return['prop9'], "par1" => $return['par9'], "min1" => $return['min9'], "max1" => $return['max9']]
),
"Prop10" => array_filter(
["prop10" => $return['prop10'], "par1" => $return['par10'], "min1" => $return['min10'], "max1" => $return['max10']]
)
]);
/*
* for all props for this unique item, get ISC strings
*/
// need par, min, max value for each prop
// ( Also need func1 and val1 for each prop )
// for each prop, get stat
$counter = 1;
foreach ($props as $key => $val) {
// val = Prop1,Prop2 etc.
// for each propr, get all 7 stats in ISC
// for now only get stat1, and for else, use dgrp
// prop funcs
$props = array_filter([
"Prop1" => array_filter(
["prop1" => $return['prop1'], "par1" => $return['par1'], "min1" => $return['min1'], "max1" => $return['max1']]
),
"Prop2" => array_filter(
["prop2" => $return['prop2'], "par1" => $return['par2'], "min1" => $return['min2'], "max1" => $return['max2']]
),
"Prop3" => array_filter(
["prop3" => $return['prop3'], "par1" => $return['par3'], "min1" => $return['min3'], "max1" => $return['max3']]
),
"Prop4" => array_filter(
["prop4" => $return['prop4'], "par1" => $return['par4'], "min1" => $return['min4'], "max1" => $return['max4']]
),
"Prop5" => array_filter(
["prop5" => $return['prop5'], "par1" => $return['par5'], "min1" => $return['min5'], "max1" => $return['max5']]
),
"Prop6" => array_filter(
["prop6" => $return['prop6'], "par1" => $return['par6'], "min1" => $return['min6'], "max1" => $return['max6']]
),
"Prop7" => array_filter(
["prop7" => $return['prop7'], "par1" => $return['par7'], "min1" => $return['min7'], "max1" => $return['max7']]
),
"Prop8" => array_filter(
["prop8" => $return['prop8'], "par1" => $return['par8'], "min1" => $return['min8'], "max1" => $return['max8']]
),
"Prop9" => array_filter(
["prop9" => $return['prop9'], "par1" => $return['par9'], "min1" => $return['min9'], "max1" => $return['max9']]
),
"Prop10" => array_filter(
["prop10" => $return['prop10'], "par1" => $return['par10'], "min1" => $return['min10'], "max1" => $return['max10']]
)
]);
// need par, min, max value for each prop
// ( Also need func1 and val1 for each prop )
// for each prop, get stat
$counter = 1;
foreach ($props as $key => $val) {
// val = Prop1,Prop2 etc.
// for each propr, get all 7 stats in ISC
// for now only get stat1, and for else, use dgrp
// prop funcs
/*
* 1 - Applies a value to a stat, can use SetX parameter.
2 - defensive function only, similar to 1 ???
3 - Apply the same min-max range as used in the previous function block (see res-all).
4 - not used ???
5 - Dmg-min related ???
6 - Dmg-max related ???
7 - Dmg% related ???
8 - ??? use for speed properties (ias, fcr, etc ...)
9 - Apply the same param and value in min-max range, as used in the previous function block.
10 - skilltab skill group ???
11 - event-based skills ???
12 - random selection of parameters for parameter-based stat ???
13 - durability-related ???
14 - inventory positions on item ??? (related to socket)
15 - use min field only
16 - use max field only
17 - use param field only
18 - Related to /time properties.
19 - Related to charged item.
20 - Simple boolean stuff. Use by indestruct.
21 - Add to group of skills, group determined by stat ID, uses ValX parameter.
22 - Individual skill, using param for skill ID, random between min-max.
23 - ethereal
24 - property applied to character or target monster ???
25--32 can be used in custom code. Check plugin documentation for syntax.
*
* 1 - Applies a value to a stat, can use SetX parameter.
2 - defensive function only, similar to 1 ???
3 - Apply the same min-max range as used in the previous function block (see res-all).
4 - not used ???
5 - Dmg-min related ???
6 - Dmg-max related ???
7 - Dmg% related ???
8 - ??? use for speed properties (ias, fcr, etc ...)
9 - Apply the same param and value in min-max range, as used in the previous function block.
10 - skilltab skill group ???
11 - event-based skills ???
12 - random selection of parameters for parameter-based stat ???
13 - durability-related ???
14 - inventory positions on item ??? (related to socket)
15 - use min field only
16 - use max field only
17 - use param field only
18 - Related to /time properties.
19 - Related to charged item.
20 - Simple boolean stuff. Use by indestruct.
21 - Add to group of skills, group determined by stat ID, uses ValX parameter.
22 - Individual skill, using param for skill ID, random between min-max.
23 - ethereal
24 - property applied to character or target monster ???
25--32 can be used in custom code. Check plugin documentation for syntax.
*
*/
$sql = "SELECT func1,stat1 FROM properties WHERE code = ?";
$props[$key]['stat'] = PDO_FetchRow($sql, [$val['prop' . $counter]]);
// if not empty, filter props key stat
if (!empty($props[$key]['stat'])) {
$props[$key]['stat'] = array_filter($props[$key]['stat']);
}
$counter++;
}
$counter = 1;
//each stat now goes into getIscStrings
foreach ($props as $k => $v) {
$props[$k]['desc'] = $this->getIscStrings($v['prop' . $counter]);
$counter++;
}
// Values in params, so I can get generated string for that prop
$counter = 1;
foreach ($props as $k => $v) { // for each property Prop1 Prop2
$params = [
'string1' => $v['desc']['string1'],
'string2' => $v['desc']['string2'],
'gstring1' => $v['desc']['gstring1'],
'gstring2' => $v['desc']['gstring2'],
'descfunc' => $v['desc']['descfunc'],
'descval' => $v['desc']['descval'],
'dgrp' => $v['desc']['dgrp'],
'dgrpfunc' => $v['desc']['dgrpfunc'],
'dgrpval' => $v['desc']['dgrpval'],
"prop" => $return['prop' . $counter],
"par" => $return['par' . $counter],
"min" => $return['min' . $counter],
"max" => $return['max' . $counter],
];
/*
* getDesc should process string1, not file guide copy pasta
*
*/
if ( (!empty($v['desc'])) ) {
require_once 'D2ItemDesc.php';
$idesc = new D2ItemDesc();
$props[$k]['string'][] = ($idesc->getDesc($params));
if ($v['stat']['func1'] == '12'){
$props[$k]['string'] = "+{$params['par']} to a Random Skill";
}
ddump($props[$k]['string']);
}
$counter++;
}
$sql = "SELECT func1,stat1 FROM properties WHERE code = ?";
$props[$key]['stat'] = PDO_FetchRow($sql, [$val['prop' . $counter]]);
$return['props'] = $props;
// if not empty, filter props key stat
if (!empty($props[$key]['stat'])) {
$props[$key]['stat'] = array_filter($props[$key]['stat']);
}
$sqlArmor = "SELECT * FROM armor WHERE code=?";
$sqlMisc = "SELECT * FROM misc WHERE code=?";
$sqlWeapons = "SELECT * FROM weapons WHERE code=?";
$counter++;
}
$baseItemInfo = PDO_FetchRow($sqlArmor, [$res['code']]);
$uTable = "armor";
$counter = 1;
//each stat now goes into getIscStrings
foreach ($props as $k => $v) {
$props[$k]['desc'] = $this->getIscStrings($v['prop' . $counter]);
$counter++;
}
if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlMisc, [$res['code']]);
}
if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlWeapons, [$res['code']]);
}
// Values in params, so I can get generated string for that prop
$counter = 1;
foreach ($props as $k => $v) { // for each property Prop1 Prop2
$params = [
'string1' => $v['desc']['string1'],
'string2' => $v['desc']['string2'],
'gstring1' => $v['desc']['gstring1'],
'gstring2' => $v['desc']['gstring2'],
'descfunc' => $v['desc']['descfunc'],
'descval' => $v['desc']['descval'],
'dgrp' => $v['desc']['dgrp'],
'dgrpfunc' => $v['desc']['dgrpfunc'],
'dgrpval' => $v['desc']['dgrpval'],
"prop" => $return['prop' . $counter],
"par" => $return['par' . $counter],
"min" => $return['min' . $counter],
"max" => $return['max' . $counter],
];
$return['baseItemInfo'] = $baseItemInfo;
/*
* getDesc should process string1, not file guide copy pasta
*
*/
if ((!empty($v['desc']))) {
require_once 'D2ItemDesc.php';
$idesc = new D2ItemDesc();
if (!empty($baseItemInfo)) {
$return['baseItemInfo'] = array_filter($baseItemInfo);
}
// process all properties.txt func1 here, total 25 in comments above
//process property func 12, random skill
if ($v['stat']['func1'] == '12') {
$props[$k]['string'][] = "+{$params['par']} to Random Skill";
} else {
$props[$k]['string'][] = ($idesc->getDesc($params));
}
}
$counter++;
}
if (!$doc) {
header('Content-Type: application/json');
return json_encode($return, JSON_INVALID_UTF8_IGNORE | JSON_PRETTY_PRINT);
} else {
return $return;
}
}
$return['props'] = $props;
public function getIscStrings($iscStat) {
if (empty($this->strings)) {
$this->getStrings();
}
return ($this->strings[$iscStat]);
}
$sqlArmor = "SELECT * FROM armor WHERE code=?";
$sqlMisc = "SELECT * FROM misc WHERE code=?";
$sqlWeapons = "SELECT * FROM weapons WHERE code=?";
public function getStrings() {
$sql = "
$baseItemInfo = PDO_FetchRow($sqlArmor, [$res['code']]);
$uTable = "armor";
if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlMisc, [$res['code']]);
}
if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlWeapons, [$res['code']]);
}
$return['baseItemInfo'] = $baseItemInfo;
if (!empty($baseItemInfo)) {
$return['baseItemInfo'] = array_filter($baseItemInfo);
}
if (!$doc) {
header('Content-Type: application/json');
return json_encode($return, JSON_INVALID_UTF8_IGNORE | JSON_PRETTY_PRINT);
} else {
return $return;
}
}
public function getIscStrings($iscStat) {
if (empty($this->strings)) {
$this->getStrings();
}
return ($this->strings[$iscStat]);
}
public function getStrings() {
$sql = "
SELECT p.`code` as prop,
p.stat1,
i.descstrpos,
@ -254,9 +254,10 @@ class D2ItemData {
LEFT JOIN strings as s4
ON i.dgrpstr2= s4.Key
";
$strings = PDO_FetchAll($sql);
foreach ($strings as $k => $v) {
$this->strings[$v['prop']] = $v;
}
}
$strings = PDO_FetchAll($sql);
foreach ($strings as $k => $v) {
$this->strings[$v['prop']] = $v;
}
}
}