mirror of
				https://gitlab.com/hashborgir/d2tools.git
				synced 2025-11-03 17:27:46 -06:00 
			
		
		
		
	
		
			
				
	
	
		
			284 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			284 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
include "./config.php";
 | 
						|
$idesc = new D2ItemDesc();
 | 
						|
/*
 | 
						|
 | 
						|
  Copyright (C) 2021 Hash Borgir
 | 
						|
 | 
						|
  This file is part of D2Modder
 | 
						|
 | 
						|
  Redistribution and use in source and binary forms, with
 | 
						|
  or without modification, are permitted provided that the
 | 
						|
  following conditions are met:
 | 
						|
 | 
						|
 * Redistributions of source code must retain the above
 | 
						|
  copyright notice, this list of conditions and the
 | 
						|
  following disclaimer.
 | 
						|
 | 
						|
 * Redistributions in binary form must reproduce the above
 | 
						|
  copyright notice, this list of conditions and the
 | 
						|
  following disclaimer in the documentation and/or other
 | 
						|
  materials provided with the distribution.
 | 
						|
 | 
						|
 * This software must not be used for commercial purposes
 | 
						|
 * without my consent. Any sales or commercial use are prohibited
 | 
						|
 * without my express knowledge and consent.
 | 
						|
 | 
						|
  This program is distributed in the hope that it will be useful,
 | 
						|
  but WITHOUT ANY WARRANTY!
 | 
						|
 | 
						|
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
						|
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 | 
						|
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
						|
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
						|
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 | 
						|
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
						|
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 | 
						|
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
						|
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
						|
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
						|
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 | 
						|
  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 | 
						|
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
						|
 | 
						|
 */
 | 
						|
 | 
						|
if (!empty($_GET['cmd']))
 | 
						|
	$cmd = $_GET['cmd'];
 | 
						|
if (!empty($_GET['sort']))
 | 
						|
	$sort = $_GET['sort'];
 | 
						|
if (!empty($_GET['view']))
 | 
						|
	$view = $_GET['view'];
 | 
						|
/*
 | 
						|
 *  @cmd = getUniqueItem
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *  */
 | 
						|
 | 
						|
// first search code in all 3 tables. Grab from where it exists.
 | 
						|
 | 
						|
if ($cmd == "getUniqueItem") {
 | 
						|
	$sql = "SELECT * FROM `uniqueitems` WHERE `enabled`='1' AND `index`=\"{$_GET['index']}\"";
 | 
						|
	$res = PDO_FetchRow($sql);
 | 
						|
 | 
						|
	if (empty($res['invfile'])) {
 | 
						|
 | 
						|
		// if no invfile, get from other tables
 | 
						|
		// try to get from armor, weapons, misc
 | 
						|
 | 
						|
		$sql = "SELECT invfile FROM armor WHERE code='{$res['code']}'";
 | 
						|
		$invfile[] = PDO_FetchRow($sql);
 | 
						|
 | 
						|
		$sql = "SELECT invfile FROM weapons WHERE code='{$res['code']}'";
 | 
						|
		$invfile[] = PDO_FetchRow($sql);
 | 
						|
 | 
						|
		$sql = "SELECT invfile FROM misc WHERE code='{$res['code']}'";
 | 
						|
		$invfile[] = PDO_FetchRow($sql);
 | 
						|
 | 
						|
		$invfile = array_filter($invfile);
 | 
						|
 | 
						|
		foreach ($invfile as $i) {
 | 
						|
			$x[] = $i;
 | 
						|
		}
 | 
						|
 | 
						|
 | 
						|
		$invClean = array_filter($x[0]);
 | 
						|
 | 
						|
		$return = array_merge($res, $invClean);
 | 
						|
	} else {
 | 
						|
		$return = $res;
 | 
						|
	}
 | 
						|
 | 
						|
	// var_dump($return);
 | 
						|
	// for all props for this unique item, get ISC strings
 | 
						|
 | 
						|
	$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
 | 
						|
	// 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
 | 
						|
		$sql = "SELECT stat1,stat2,stat3,stat4,stat5,stat6,stat7 FROM `properties` WHERE `code` = '{$val['prop' . $counter]}'";
 | 
						|
		$props[$key]['stat'] = array_filter(PDO_FetchRow($sql));
 | 
						|
 | 
						|
		$counter++;
 | 
						|
	}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
	//each stat now goes into getIscStrings
 | 
						|
	foreach ($props as $k => $v) {
 | 
						|
		$props[$k]['desc'] = array_filter(getIscStrings($v['stat']['stat1']));
 | 
						|
	}
 | 
						|
 | 
						|
 | 
						|
	//var_dump($return);
 | 
						|
	// todo: put 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'],
 | 
						|
			'descfunc' => $v['desc']['descfunc'],
 | 
						|
			'descval' => $v['desc']['descval'],
 | 
						|
			"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'])) {
 | 
						|
			$props[$k]['string'][] = $idesc->getDesc($params);
 | 
						|
		}
 | 
						|
		$counter++;
 | 
						|
	}
 | 
						|
 | 
						|
	$return['props'] = $props;
 | 
						|
 | 
						|
	//ddump($return);
 | 
						|
 | 
						|
 | 
						|
	header('Content-Type: application/json');
 | 
						|
	echo json_encode($return, JSON_INVALID_UTF8_IGNORE|JSON_PRETTY_PRINT);
 | 
						|
}
 | 
						|
/*
 | 
						|
 *  @cmd = sortBy
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *  */
 | 
						|
if ($cmd == "sortBy") {
 | 
						|
	$sql = "SELECT `index`,`$sort` FROM `uniqueitems` WHERE `enabled`='1' ORDER BY `$sort`";
 | 
						|
	$res = PDO_FetchAll($sql);
 | 
						|
 | 
						|
	$html = '';
 | 
						|
	foreach ($res as $r) {
 | 
						|
		if ($sort == 'index') {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
 | 
						|
		} else {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">$r[$sort] - {$r['index']}</option>";
 | 
						|
		}
 | 
						|
	}
 | 
						|
	echo $html;
 | 
						|
}
 | 
						|
/*
 | 
						|
 *  @cmd = viewOnly
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *  */
 | 
						|
if ($cmd == "viewOnly") {
 | 
						|
 | 
						|
	$table = 'misc';
 | 
						|
	$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, misc.`type`
 | 
						|
FROM uniqueitems
 | 
						|
LEFT JOIN misc ON uniqueitems.`code` = misc.`code`
 | 
						|
WHERE `type` IS NOT NULL AND uniqueitems.`code`='$view'";
 | 
						|
	if ($view == 'armo') {
 | 
						|
		$table = 'armor';
 | 
						|
		$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, $table.`code`
 | 
						|
FROM uniqueitems
 | 
						|
LEFT JOIN $table ON uniqueitems.`code` = $table.`code`
 | 
						|
WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`";
 | 
						|
	}
 | 
						|
	if ($view == 'weap') {
 | 
						|
		$table = 'weapons';
 | 
						|
		$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, $table.`code`
 | 
						|
FROM uniqueitems
 | 
						|
LEFT JOIN $table ON uniqueitems.`code` = $table.`code`
 | 
						|
WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`";
 | 
						|
	}
 | 
						|
	if ($view == "char") {
 | 
						|
		$sql .= " OR uniqueitems.`code`='cm1' OR uniqueitems.`code`='cm2' OR uniqueitems.`code`='cm3'";
 | 
						|
	}
 | 
						|
	$res = PDO_FetchAll($sql);
 | 
						|
	$html = '';
 | 
						|
	foreach ($res as $r) {
 | 
						|
		if ($sort == 'index') {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
 | 
						|
		} else {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
 | 
						|
		}
 | 
						|
	}
 | 
						|
	echo $html;
 | 
						|
}
 | 
						|
 | 
						|
/*
 | 
						|
 *  @cmd = search
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *
 | 
						|
 */
 | 
						|
if ($cmd == 'search') {
 | 
						|
	$search = $_GET['search'];
 | 
						|
	$sql = "SELECT * FROM uniqueitems WHERE `index` LIKE '%$search%' OR `code` LIKE '%$search%' AND `enabled`=1 ORDER BY `index`";
 | 
						|
	$res = PDO_FetchAll($sql);
 | 
						|
	$html = '';
 | 
						|
	foreach ($res as $r) {
 | 
						|
		if ($sort == 'index') {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
 | 
						|
		} else {
 | 
						|
			$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
 | 
						|
		}
 | 
						|
	}
 | 
						|
	echo $html;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
 *  @cmd = getString
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *
 | 
						|
 *
 | 
						|
 */
 | 
						|
if ($cmd == 'getString') {
 | 
						|
	$prop = $_GET['prop'];
 | 
						|
 | 
						|
	$sql = "SELECT stat1,stat2,stat3,stat4,stat5,stat6,stat7 FROM `properties` WHERE `code` = '$prop'";
 | 
						|
	$stat = array_filter(PDO_FetchRow($sql));
 | 
						|
 | 
						|
	$s = array_filter(getIscStrings($stat['stat1']));
 | 
						|
 | 
						|
	header('Content-Type: application/json');
 | 
						|
	echo json_encode($s, JSON_INVALID_UTF8_IGNORE);
 | 
						|
} |