-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtctree.php
More file actions
60 lines (46 loc) · 1.19 KB
/
tctree.php
File metadata and controls
60 lines (46 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/**
* @file
* Display a TC tree (only TC names and heirarchy).
*/
chdir(realpath(__DIR__));
define('TREASURECLASSEX', json_decode(file_get_contents('json/treasureclassex.json'), TRUE));
if ($argc < 2) {
echo "Usage: php tctree.php [TC name]\n";
exit(1);
}
function print_tc_tree($tc_name, $indent = 0) {
if (!isset(TREASURECLASSEX[$tc_name])) {
return;
}
$tc = TREASURECLASSEX[$tc_name];
if ($tc['Picks'] > 0) {
for ($c = 0; $c < 10; $c++) {
$name = $tc['Item' . $c] ?? '';
$prob = $tc['Prob' . $c] ?? 0;
if ($name && $prob > 0) {
echo str_repeat("\t", $indent) . "$name @ $prob\n";
print_tc_tree($name, $indent + 1);
}
}
}
elseif ($tc['Picks'] < 0) {
$picks = -$tc['Picks'];
for ($c = 0; $c < 10; $c++) {
$name = $tc['Item' . $c] ?? '';
$prob = $tc['Prob' . $c] ?? 0;
if ($name && $prob > 0) {
$sub = min($picks, $prob);
if ($sub < 0) {
break;
}
echo str_repeat("\t", $indent) . "$name @ $prob\n";
print_tc_tree($name, $indent + 1);
$picks -= $sub;
}
}
}
}
print($argv[1] . "\n");
print_tc_tree($argv[1], 1);