From 50252def84cea7f183ac285a85aa07b681c5808b Mon Sep 17 00:00:00 2001 From: "color.diff=auto" Date: Tue, 23 Mar 2021 12:35:28 -0600 Subject: [PATCH] Filter and refactor --- filterProperties.txt | 129 +++++++++++++++++++ index.php | 39 +++++- src/D2Functions.php | 4 + src/D2SM.php | 270 ++++++++++++++++++++------------------- src/D2SaveFile.php | 13 +- src/D2TxtParser.php | 28 +++- src/D2UM.php | 103 ++++++++------- txt/.~lock.SetItems.txt# | 1 - 8 files changed, 385 insertions(+), 202 deletions(-) create mode 100644 filterProperties.txt delete mode 100644 txt/.~lock.SetItems.txt# diff --git a/filterProperties.txt b/filterProperties.txt new file mode 100644 index 0000000..426b585 --- /dev/null +++ b/filterProperties.txt @@ -0,0 +1,129 @@ +color +bloody +Expansion +gembonus +fire-fx +light-fx +gems%/lvl +dmg-slash +dmg-slash% +dmg-crush +dmg-crush% +dmg-thrust +dmg-thrust% +abs-slash +abs-crush +abs-thrust +abs-slash% +abs-crush% +abs-thrust% +ac/time +ac%/time +hp/time +mana/time +dmg/time +dmg%/time +str/time +dex/time +enr/time +vit/time +att/time +att%/time +dmg-cold/time +dmg-fire/time +dmg-ltng/time +dmg-pois/time +res-cold/time +res-fire/time +res-ltng/time +res-pois/time +abs-cold/time +abs-fire/time +abs-ltng/time +abs-pois/time +gold%/time +mag%/time +regen-stam/time +stam/time +dmg-dem/time +dmg-und/time +att-dem/time +att-und/time +crush/time +wounds/time +kick/time +deadly/time +gems%/time +fade +state +pruby +fruby +nruby +flruby +cruby +pamethyst +famethyst +namethyst +flamethyst +camethyst +pdiamond +fdiamond +ndiamond +fldiamond +cdiamond +pemerald +femerald +nemerald +flemerald +cemerald +psapphire +fsapphire +nsapphire +flsapphire +csapphire +ptopaz +ftopaz +ntopaz +fltopaz +ctopaz +pskull +fskull +nskull +flskull +cskull +rbgr01 +rbgr02 +rbgr03 +rbgr04 +rbgr05 +rbgr06 +rbgr07 +rbgr08 +rbgr09 +rbgr10 +rbgr11 +rbgr12 +rbgr13 +rbgr14 +rbgr15 +rbgr16 +rbgr17 +rbgr18 +rbgr19 +rbgr20 +rbgr21 +rbgr22 +rbgr23 +rbgr24 +rbgr25 +rbgr26 +rbgr27 +rbgr28 +rbgr29 +rbgr30 +rbgr31 +rbgr32 +rbgr33 +magharv +showkills +iforge \ No newline at end of file diff --git a/index.php b/index.php index 13dab06..d047357 100644 --- a/index.php +++ b/index.php @@ -23,6 +23,8 @@ ini_set('display_errors', 1); ini_set('log_errors', 1); +define('FILTER_PROPERTIES_FILE', 'filterProperties.txt'); + $filename = 'd2im.conf'; if (file_exists($filename)) { @@ -58,21 +60,46 @@ if (file_exists($filename)) { $u = $files->getFile("UniqueItems"); $s = $files->getFile("SetItems"); - - + + // If there's data, process it and save if (!empty($_POST)) { require_once './src/D2SaveFile.php'; $saver = new D2SaveFile(); + // process post + // combine armor/weapon codes + $post = $_POST; + if (!empty($post['code'])) { + array_filter($post['code']); + + if (!empty($post['code'][0])) { + $post['code'] = $post['code'][0]; + } else { + $post['code'] = $post['code'][1]; + } + } + + + // if ladder or carry1 is 0, set empty field. + if (!$post['ladder']){ + $post['ladder'] = ''; + } + if (!$post['carry1']){ + $post['carry1'] = ''; + } + + + + if ($_POST['formtype'] == "uniqueitems") { $saver->save($u); $saver->saveTblEnries("UniqueItems.tbl.txt"); } if ($_POST['formtype'] == "setitems") { - - - - + + + + $saver->save($s); $saver->saveTblEnries("SetItems.tbl.txt"); } diff --git a/src/D2Functions.php b/src/D2Functions.php index 3e756f6..81dc656 100644 --- a/src/D2Functions.php +++ b/src/D2Functions.php @@ -6,3 +6,7 @@ function dd($var) { echo ""; die(); } + +function filterFunc($arg1, $arg2) { + return !($arg1 == $arg2); +} \ No newline at end of file diff --git a/src/D2SM.php b/src/D2SM.php index f45a6e6..9041031 100644 --- a/src/D2SM.php +++ b/src/D2SM.php @@ -4,29 +4,30 @@
-
-
- -
[show/hide Help] +
+
+ +
+ Index: string key to item's name in a .tbl file
-
-
+
+
-
[show/hide Help] +
+ Set: string key to the index field in Sets.txt - the set the item is a part of.
- +
- - + ' . $a['name'] . ''; @@ -50,206 +50,212 @@ ?>
-
- - + -
-
+
-
[show/hide Help] +
+ Rarity: Chance to pick this set item if more then one set item of the same base item exist, this uses the common rarity/total_rarity formula, so if you have two set rings, one with a rarity of 100 the other with a rarity of 1, then the first will drop 100/101 percent of the time (99%) and the other will drop 1/101 percent of the time (1%), rarity can be anything between 0 and 255.
- [show/hide Help] + + The quality level of this set item, monsters, cube recipes, vendors, objects and the like most be at least this level or higher to be able to drop this item, otherwise they would drop a magical item with twice normal durability.
- [show/hide Help] + + lvl req: The character level required to use this set item.
- [show/hide Help] + + ChrTransform: palette shift to apply to the the DCC component-file and the DC6 flippy-file (whenever or not the color shift will apply is determined by Weapons.txt, Armor.txt or Misc.txt). This is an ID pointer from Colors.txt.
- [show/hide Help] + + InvTransform: palette shift to apply to the the DC6 inventory-file (whenever or not the color shift will apply is determined by Weapons.txt, Armor.txt or Misc.txt). This is an ID pointer from Colors.txt.
- [show/hide Help] + + InvFile: overrides the invfile and uniqueinvfile specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains the file name of the DC6 inventory graphic.
- [show/hide Help] + + FlippyFile: overrides the flippyfile specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains the file name of the DC6 flippy animation.
- [show/hide Help] + + DropSound: overrides the dropsound (the sound played when the item hits the ground) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt.
- [show/hide Help] + + DropSfxFrame: how many frames after the flippy animation starts playing will the associated drop sound start to play. This overrides the values in Weapons.txt, Armor.txt or Misc.txt.
- [show/hide Help]UseSound: overrides the usesound (the sound played when the item is consumed by the player) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt. + + UseSound: overrides the usesound (the sound played when the item is consumed by the player) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt.
- Cost Mult: - [show/hide Help] + + + Cost Mult: the base item's price is multiplied by this value when sold, repaired or bought from a vendor.
- Cost Add: - [show/hide Help] + + + Cost Add: after the price has been multiplied, this amount of gold is added to the price on top.
-
-
-

Add Func:

-
- - -
-
- - -
-
- - -

[show/hide Help] - add func: a property mode field that controls how the variable attributes will appear and be functional on a set item. See the appendix for further details about this field's effects.
    -
  1. no green properties on item (apropxx will appear as a blue attribute on the list instead).
  2. -
  3. green properties (apropxx) depend on which other items from the set are equipped.
  4. -
  5. green properties (apropxx) depend on how many other items from the set are equipped.
  6. -
-
-
-
-

Blue Attributes

-
- -
- - - - - - +
+
+ + +
+
+ + +
+
+ + +

+ Add Func + add func: a property mode field that controls how the variable attributes will appear and be functional on a set item. See the appendix for further details about this field's effects. +
+
+
+

Blue Attributes

-
- - -
-
-

Green Attributes

-

Note: Edit boxes in Vertical Order.
[aprop1a, aprop1b][aprop2a, aprop2b]

- -
- -
- - - - - - - - - -
- - - + ' . $a['code'] . ''; + echo ''; } ?> + - + - + -
+ +
+ +
+
+
+

Green Attributes

+

Note: Edit boxes in Vertical Order.
[aprop1a, aprop1b][aprop2a, aprop2b]

+ $html = ''; + foreach (range(1, 5) as $p) { + ?> +
+ + -
-
- [show/hide Help] - -

aprop1a,aprop1b to aprop5a,aprop5b: An ID pointer of a property from Properties.txt, these columns control each of the five pairs of different variable (green) modifiers a set item can grant you at most.

-

apar1a,apar1b to apar5a,apar5b: The parameter passed on to the associated property, this is used to pass skill IDs, state IDs, monster IDs, montype IDs and the like on to the properties that require them, these fields support calculations.

-

amin1a,amin1b to amin5a,amin5b: Minimum value to assign to the associated property. Certain properties have special interpretations based on stat encoding (e.g. chance-to-cast and charged skills). See the File Guide for Properties.txt and ItemStatCost.txt for further details.

-

amax1a,amax1b to amax5a,amax5b: Maximum value to assign to the associated property. Certain properties have special interpretations based on stat encoding (e.g. chance-to-cast and charged skills). See the File Guide for Properties.txt and ItemStatCost.txt for further details.

+ + + + + + +
+ + + + + + + + + +
+ +
+ + +
+
+ + + +

aprop1a,aprop1b to aprop5a,aprop5b: An ID pointer of a property from Properties.txt, these columns control each of the five pairs of different variable (green) modifiers a set item can grant you at most.

+

apar1a,apar1b to apar5a,apar5b: The parameter passed on to the associated property, this is used to pass skill IDs, state IDs, monster IDs, montype IDs and the like on to the properties that require them, these fields support calculations.

+

amin1a,amin1b to amin5a,amin5b: Minimum value to assign to the associated property. Certain properties have special interpretations based on stat encoding (e.g. chance-to-cast and charged skills). See the File Guide for Properties.txt and ItemStatCost.txt for further details.

+

amax1a,amax1b to amax5a,amax5b: Maximum value to assign to the associated property. Certain properties have special interpretations based on stat encoding (e.g. chance-to-cast and charged skills). See the File Guide for Properties.txt and ItemStatCost.txt for further details.

-
-
+ +
- - + + + + + - - -
    diff --git a/src/D2SaveFile.php b/src/D2SaveFile.php index 181ed1e..d920732 100644 --- a/src/D2SaveFile.php +++ b/src/D2SaveFile.php @@ -23,22 +23,13 @@ class D2SaveFile { public $path; - public function save($file) { - $post = $_POST; - if (!empty($post['code'])) { - array_filter($post['code']); + public function save($file, $data) { - if (!empty($post['code'][0])) { - $post['code'] = $post['code'][0]; - } else { - $post['code'] = $post['code'][1]; - } - } $fp = fopen($this->path.DIRECTORY_SEPARATOR.$file, 'a+'); $this->saveBackup($file); - fputcsv($fp, $post, "\t"); + fputcsv($fp, $data, "\t"); } diff --git a/src/D2TxtParser.php b/src/D2TxtParser.php index a4cdc2d..528de97 100644 --- a/src/D2TxtParser.php +++ b/src/D2TxtParser.php @@ -25,17 +25,31 @@ class D2TxtParser { public $path = TXT_PATH; + // Files specific to Unique Items public function __construct() { - } - - public function parseFile($file){ - return $this->toPHP($file); } - - function toPHP($file) { + + public function parseFile($file) { + if ($file == "Properties.txt") { + return $this->filterProps($file); + } + return $this->parseData($file); + } + + function filterProps($file) { + $data = $this->parseData($file); + $propsToFilter = file(FILTER_PROPERTIES_FILE, FILE_IGNORE_NEW_LINES); + foreach ($data as $d) { + $allProps[] = $d['code']; + } + $filteredProps = array_diff($allProps, $propsToFilter); + return $filteredProps; + } + + public function parseData($file) { $file = $this->path . $file; $rows = array_map(function ($v) { return str_getcsv($v, "\t"); @@ -47,6 +61,6 @@ class D2TxtParser { } return $data; } - } + ?> \ No newline at end of file diff --git a/src/D2UM.php b/src/D2UM.php index c2bfb11..0118d65 100644 --- a/src/D2UM.php +++ b/src/D2UM.php @@ -3,21 +3,17 @@
    -
    +
    +

    Index

    -
    -
    - -
    -
    - - -
    [show/hide Help] + +
    + Index: the ID pointer that is referenced by the game in TreasureClassEx.txt and CubeMain.txt, this column also contains the string-key used in the TBL files.
    -
    +

    Version:

    @@ -30,7 +26,8 @@
    -

    [show/hide Help] +

    + Version: Switch, what game version was this unique item added in, 0 referes to real classic Diablo II (1.00-1.06), 1 refers to new classic Diablo II (1.07-1.11) and 100 refers to the Expansion Set. Items with 100 will be unable to drop in Classic Diablo II.
    @@ -44,7 +41,8 @@
    -

    [show/hide Help] +

    + Ladder: Boolean, 1 = item available only on the realms (enabled), 0 = item available both in single player/open games, TCP/IP and on the realms.
    @@ -53,51 +51,57 @@

    Ladder:

    - +
    - + -

    [show/hide Help] +

+ Ladder: Boolean, 1 = item available only on the realms (ladder), 0 = item available both in single player/open games, TCP/IP and on the realms.
-
+
+

Rarity

+ -
[show/hide Help] +
+ Rarity: chance to pick this unique item if more then one unique item of the same base item exist, this uses the common rarity/total_rarity formula, so if you have two unique rings, one with a rarity of 100 the other with a rarity of 1, then the first will drop 100/101 percent of the time (99%) and the other will drop 1/101 percent of the time (1%), rarity can be anything between 1 and 255 (rarity of less then 1 will be set to 1 by the code).
-
-
-

NoLimit

+
+
[show/hide Help] + + NoLimit: Boolean, 0 = can drop only once per game, 1 = can drop more then once per game.
-
- [show/hide Help] +
+ + Lvl: the quality level of this unique item. Monsters, cube recipes, vendors, objects and the like most be at least this level or higher to be able to drop this item, otherwise they would drop a rare item with enhanced durability.
- [show/hide Help] + + Lvl Req: the character level required to use this unique item.
- - + ' . $a['name'] . ''; @@ -124,68 +127,78 @@

-
-
-

Carry1

+
+
[show/hide Help] + + + Carry1: Boolean, 0 = allow the player to hold as many of this item as he wants, 1 = allow the player to hold a single copy only. In reality this just prevents the player from picking up the item when it is dropped on the floor and it prevents the player from putting this item in the trading window.
-
- [show/hide Help] +
+ + Cost Mult: the base item's price is multiplied by this value when sold, repaired or bought from a vendor.
- [show/hide Help] + + Cost Add: after the price has been multiplied, this amount of gold is added to the price on top.
-
- [show/hide Help] +
+ + ChrTransform: palette shift to apply to the the DCC component-file and the DC6 flippy-file (whenever or not the color shift will apply is determined by Weapons.txt, Armor.txt or Misc.txt). This is an ID pointer from Colors.txt.
- [show/hide Help] + + InvTransform: palette shift to apply to the the DC6 inventory-file (whenever or not the color shift will apply is determined by Weapons.txt, Armor.txt or Misc.txt). This is an ID pointer from Colors.txt.
- [show/hide Help] + + FlippyFile: overrides the flippyfile specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains the file name of the DC6 flippy animation.
- [show/hide Help] + + InvFile: overrides the invfile and uniqueinvfile specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains the file name of the DC6 inventory graphic.
- [show/hide Help] + + DropSound: overrides the dropsound (the sound played when the item hits the ground) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt.
- [show/hide Help] + + DropSfxFrame: how many frames after the flippy animation starts playing will the associated drop sound start to play. This overrides the values in Weapons.txt, Armor.txt or Misc.txt.
- [show/hide Help]UseSound: overrides the usesound (the sound played when the item is consumed by the player) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt. + +UseSound: overrides the usesound (the sound played when the item is consumed by the player) specified in Weapons.txt, Armor.txt or Misc.txt for the base item. This field contains an ID pointer from Sounds.txt.
@@ -200,7 +213,7 @@ ' . $a['code'] . ''; + echo ''; } ?> diff --git a/txt/.~lock.SetItems.txt# b/txt/.~lock.SetItems.txt# deleted file mode 100644 index 77df7c0..0000000 --- a/txt/.~lock.SetItems.txt# +++ /dev/null @@ -1 +0,0 @@ -,stoned,stoned-desktop,23.03.2021 02:12,file:///home/stoned/.config/libreoffice/4; \ No newline at end of file