summaryrefslogtreecommitdiff
path: root/tools/itemdb_jobmask_converter.pl
blob: e9295c21760e9cdb569a1f64e1100b8fa6a09e37 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl
#
# This file is part of Hercules.
# http://herc.ws - http://github.com/HerculesWS/Hercules
#
# Copyright (C) 2016-2020 Hercules Dev Team
#
# Hercules is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Base Author: Dastgir @ http://herc.ws

# This script converts item_db.conf Jobmask field into groups format
# usage example: perl tools/itemdb_jobmask_converter.pl < db/item_db2.conf > db/item_db_out.conf

use strict;
use warnings;

sub parsedb (@) {
	my @input = @_;
	my @jobNames = (
		"Novice",
		"Swordsman",
		"Magician",
		"Archer",
		"Acolyte",
		"Merchant",
		"Thief",
		"Knight",
		"Priest",
		"Wizard",
		"Blacksmith",
		"Hunter",
		"Assassin",
		"Unused",
		"Crusader",
		"Monk",
		"Sage",
		"Rogue",
		"Alchemist",
		"Bard",
		"Unused",
		"Taekwon",
		"Star_Gladiator",
		"Soul_Linker",
		"Gunslinger",
		"Ninja",
		"Gangsi",
		"Death_Knight",
		"Dark_Collector",
		"Kagerou",
		"Rebellion"
	);
	my $jobSize = $#jobNames + 1;

	foreach (@input) {
		chomp $_;
		if ($_ =~ /^\s*Job\s*:\s*(?<Job>(?:0x)?[0-9A-Fa-f]+)/x) {
			my %cols = map { $_ => $+{$_} } keys %+;
			my $jobMask = hex($cols{Job});
			my $allJobs = 0xFFFFFFFF;
			my $allJobsExceptNovice = 0xFFFFFFFE;
			if ($jobMask < 0 || $jobMask eq "") {
				print "$_\n";
				next;
			}
			print "\tJob: {\n";
			if (($jobMask&$allJobs) == $allJobs) {
				print "\t\tAll: true\n";
			} elsif (($jobMask&$allJobsExceptNovice) == $allJobsExceptNovice) {
				print "\t\tAll: true\n";
				print "\t\tNovice: false\n";
			} elsif ($jobMask == 0) {
				print "\t\tAll: false\n";
			} else {
				for (my $i = 0; $i < $jobSize; $i++) {
					my $currBit = 1<<$i;
					if (($jobMask & $currBit) == $currBit) {
						print "\t\t$jobNames[$i]: true\n" unless $jobNames[$i] eq "Unused";
					}
				}
			}
			print "\t}\n";
		} else {
			print "$_\n";
		}
	}
}

parsedb(<>);