better item parsing, clean up

This commit is contained in:
Hash Borgir 2023-06-05 22:03:59 -06:00
parent f769cc830c
commit 60b2a7b629
2 changed files with 60 additions and 31 deletions

View File

@ -39,9 +39,6 @@ class D2Item {
*/ */
private function parseItem() { private function parseItem() {
$b = new D2BitReader($this->bits); $b = new D2BitReader($this->bits);
// if the item is extended or not, based on length of bits
$this->iData['extended'] = (strlen($this->bits) > 112) ? 1 : 0;
$b->skip(16); // Skip JM $b->skip(16); // Skip JM
$b->skip(4); // skip unknown 4 bytes $b->skip(4); // skip unknown 4 bytes
$this->iData['identified'] = $b->read(1); // bit 20, identified $this->iData['identified'] = $b->read(1); // bit 20, identified
@ -139,10 +136,18 @@ Orbs (Sorceress-Only wands)
// if item is in a container, bodypart will be NULL // if item is in a container, bodypart will be NULL
// if item is on bodypart, container will be NULL // if item is on bodypart, container will be NULL
switch ($location) { switch ($location) {
case D2ItemLocation::BELT:
$this->iData['container'] = 'Belt';
break;
case D2ItemLocation::CURSOR:
break;
case D2ItemLocation::SOCKET:
break;
case D2ItemLocation::STORED: case D2ItemLocation::STORED:
switch ($_stored) { switch ($_stored) {
case D2ItemLocationStored::NONE: case D2ItemLocationStored::NONE:
$this->iData['container'] = ''; // item is not stored, check bit 58
$this->iData['container'] = 'None'; // item is not stored, check bit 58
break; break;
case D2ItemLocationStored::INVENTORY: case D2ItemLocationStored::INVENTORY:
$this->iData['container'] = 'Inventory'; $this->iData['container'] = 'Inventory';
@ -159,31 +164,43 @@ Orbs (Sorceress-Only wands)
break; break;
case D2ItemLocation::EQUIPPED: case D2ItemLocation::EQUIPPED:
switch ($body) { switch ($body) {
case D2ItemLocationBody::HELMET: $this->iData['bodypart'] = 'Helmet'; case D2ItemLocationBody::HELMET: $this->iData['location'] = 'Helmet';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::AMULET: $this->iData['bodypart'] = 'Amulet'; case D2ItemLocationBody::AMULET: $this->iData['location'] = 'Amulet';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::ARMOR: $this->iData['bodypart'] = 'Armor'; case D2ItemLocationBody::ARMOR: $this->iData['location'] = 'Armor';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::WEAPONR: $this->iData['bodypart'] = 'Weapon R'; case D2ItemLocationBody::WEAPONR: $this->iData['location'] = 'Weapon R';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::WEAPONL: $this->iData['bodypart'] = 'Weapon L'; case D2ItemLocationBody::WEAPONL: $this->iData['location'] = 'Weapon L';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::RINGR: $this->iData['bodypart'] = 'Ring R'; case D2ItemLocationBody::RINGR: $this->iData['location'] = 'Ring R';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::RINGL: $this->iData['bodypart'] = 'Ring L'; case D2ItemLocationBody::RINGL: $this->iData['location'] = 'Ring L';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::BELT: $this->iData['bodypart'] = 'Belt'; case D2ItemLocationBody::BELT: $this->iData['location'] = 'Belt';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::BOOTS: $this->iData['bodypart'] = 'Boots'; case D2ItemLocationBody::BOOTS: $this->iData['location'] = 'Boots';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::GLOVES: $this->iData['bodypart'] = 'Gloves'; case D2ItemLocationBody::GLOVES: $this->iData['location'] = 'Gloves';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::WEAPONR2: $this->iData['bodypart'] = 'Weapon Alt R'; case D2ItemLocationBody::WEAPONR2: $this->iData['location'] = 'Weapon Alt R';
$this->iData['container'] = 'Body';
break; break;
case D2ItemLocationBody::WEAPONL2: $this->iData['bodypart'] = 'Weapon Alt L'; case D2ItemLocationBody::WEAPONL2: $this->iData['location'] = 'Weapon Alt L';
$this->iData['container'] = 'Body';
break; break;
default: $this->iData['bodypart'] = 'Unknown'; default: $this->iData['location'] = 'Unknown';
break; break;
} }
break; break;
@ -208,6 +225,18 @@ Orbs (Sorceress-Only wands)
} }
$this->iData['code'] = trim($itemCode); $this->iData['code'] = trim($itemCode);
$sql = "SELECT * from armor WHERE code = '{$this->iData['code']}'";
$res = PDO_FetchRow($sql);
if (empty($res)) {
$sql = "SELECT * from misc WHERE code = '{$this->iData['code']}'";
$res = PDO_FetchRow($sql);
}
if (empty($res)) {
$sql = "SELECT * from weapons WHERE code = '{$this->iData['code']}'";
$res = PDO_FetchRow($sql);
}
$this->iData['txt']=($res);
$sql = " $sql = "
SELECT code, namestr SELECT code, namestr
FROM armor FROM armor

View File

@ -17,7 +17,7 @@ class D2ItemLocation {
/** /**
* *
*/ */
const BELTI = 2; const BELT = 2;
/** /**
* *
*/ */
@ -25,7 +25,7 @@ class D2ItemLocation {
/** /**
* *
*/ */
const ITEM = 6; const SOCKET = 6;
} }