summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-09-12 13:13:23 -0300
committerJesusaves <cpntb1@ymail.com>2020-09-12 13:13:23 -0300
commit1443f47ca63972f737bd9cc0322f77dc416ff2a0 (patch)
tree6b851ced5b878ac8b2b13eeb01e04d598bacfe43 /tools
parentc53f8a099151f2e8c26c0ab36f35d34256c0d6cb (diff)
downloadhercules-1443f47ca63972f737bd9cc0322f77dc416ff2a0.tar.gz
hercules-1443f47ca63972f737bd9cc0322f77dc416ff2a0.tar.bz2
hercules-1443f47ca63972f737bd9cc0322f77dc416ff2a0.tar.xz
hercules-1443f47ca63972f737bd9cc0322f77dc416ff2a0.zip
This is Hercules v2019.09.22
Diffstat (limited to 'tools')
-rw-r--r--tools/itemcombodbconverter.py112
-rw-r--r--tools/scconfigconverter.py105
-rw-r--r--tools/utils/common.py6
3 files changed, 222 insertions, 1 deletions
diff --git a/tools/itemcombodbconverter.py b/tools/itemcombodbconverter.py
new file mode 100644
index 000000000..ae4deeba3
--- /dev/null
+++ b/tools/itemcombodbconverter.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+#
+# This file is part of Hercules.
+# http://herc.ws - http://github.com/HerculesWS/Hercules
+#
+# Copyright (C) 2019 Hercules Dev Team
+# Copyright (C) 2019 Asheraf
+#
+# 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/>.
+#
+
+import argparse
+import json
+import re
+from utils import libconf
+import utils.common as Tools
+
+
+def ConvertFile(args):
+ print(r'''//================= Hercules Database =====================================
+//= _ _ _
+//= | | | | | |
+//= | |_| | ___ _ __ ___ _ _| | ___ ___
+//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
+//= | | | | __/ | | (__| |_| | | __/\__ \
+//= \_| |_/\___|_| \___|\__,_|_|\___||___/
+//================= License ===============================================
+//= This file is part of Hercules.
+//= http://herc.ws - http://github.com/HerculesWS/Hercules
+//=
+//= Copyright (C) 2019 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/>.
+//================= Description ===========================================
+// Configurations file for status effects
+//=========================================================================
+
+combo_db: (
+/**************************************************************************
+ ************* Entry structure ********************************************
+ **************************************************************************
+{
+ // ================ Mandatory fields ===============================
+ Items: ["item_list"] (string, array) list of items
+ Script: <"
+ Script
+ (it can be multi-line)
+ ">
+}
+**************************************************************************/''')
+ ItemDB = Tools.LoadDBConsts('item_db', f'{args.mode}', '../')
+ with open (f'../db/{args.mode}/item_combo_db.txt') as dbfile:
+ line = 0
+ for entry in dbfile:
+ line = line + 1
+ if not entry.strip() or entry.startswith('//'):
+ continue
+ m = re.search(r'(^[0-9:]+),\{(.*)\}$', entry)
+ if not m:
+ print(f'Error: Invalid pattern in entry {entry}, line {line}, aborting..')
+ exit()
+
+ items_list = m.group(1).split(':')
+ script = m.group(2)
+ for item in range(len(items_list)):
+ if int(items_list[item]) not in ItemDB:
+ print(f'Error: invalid item {item} found in line {line}, aborting..')
+ exit()
+ items_list[item] = ItemDB[int(items_list[item])]
+
+ if args.enable_jsbeautifier:
+ import jsbeautifier
+ opts = jsbeautifier.default_options()
+ opts.indent_with_tabs = True
+ opts.indent_level = 2
+ script = jsbeautifier.beautify(script, opts)
+ print(
+f'''{{
+ Items: {json.dumps(items_list)}
+ Script: <"\n{script}\n\t">
+}},''')
+ print(')')
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Convert item combo db to new format')
+ parser.add_argument('--mode', type=str, dest='mode', help='Define usage mode re/pre-re.')
+ parser.add_argument('--enable-jsbeautifier', type=bool, dest='enable_jsbeautifier', help='Use jsbeautifier to auto format script fields.')
+ parsed_args = parser.parse_args()
+ ConvertFile(parsed_args)
diff --git a/tools/scconfigconverter.py b/tools/scconfigconverter.py
new file mode 100644
index 000000000..9216fa3b5
--- /dev/null
+++ b/tools/scconfigconverter.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+#
+# This file is part of Hercules.
+# http://herc.ws - http://github.com/HerculesWS/Hercules
+#
+# Copyright (C) 2019 Hercules Dev Team
+# Copyright (C) 2019 Asheraf
+#
+# 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/>.
+#
+
+import csv
+
+with open('../db/sc_config.txt') as dbfile:
+ sc_config = csv.reader(dbfile, delimiter=',')
+
+ print(r'''//================= Hercules Database =====================================
+//= _ _ _
+//= | | | | | |
+//= | |_| | ___ _ __ ___ _ _| | ___ ___
+//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
+//= | | | | __/ | | (__| |_| | | __/\__ \
+//= \_| |_/\___|_| \___|\__,_|_|\___||___/
+//================= License ===============================================
+//= This file is part of Hercules.
+//= http://herc.ws - http://github.com/HerculesWS/Hercules
+//=
+//= Copyright (C) 2019 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/>.
+//================= Description ===========================================
+// Configurations file for status effects
+//=========================================================================
+''')
+ print('''/**************************************************************************
+ ************* Entry structure ********************************************
+ **************************************************************************
+SC_TYPE: {
+ // ================ Optional fields ===============================
+ Visible: (bool) SC can be visible for all players
+ Flags: {
+ NoDeathReset: (bool) SC cannot be removed by death.
+ NoSave: (bool) SC cannot be saved.
+ NoDispelReset: (bool) SC cannot be reset by dispell.
+ NoClearanceReset: (bool) SC cannot be reset by clearance.
+ Buff: (bool) SC considered as buff and be removed by Hermode and etc.
+ Debuff: (bool) SC considered as debuff and be removed by Gospel and etc.
+ NoMadoReset: (bool) SC cannot be reset when MADO Gear is taken off.
+ NoAllReset: (bool) SC cannot be reset by 'sc_end SC_ALL' and status change clear.
+ }
+}
+**************************************************************************/''')
+ flags = [
+ ('NoDeathReset', 1),
+ ('NoSave', 2),
+ ('NoDispelReset', 4),
+ ('NoClearanceReset', 8),
+ ('Buff', 16),
+ ('Debuff', 32),
+ ('NoMadoReset', 64),
+ ('NoAllReset', 128)
+ ]
+
+ for sc in sc_config:
+ if len(sc) != 2 or sc[0].startswith('//'):
+ continue
+ value = int(sc[1])
+ print('{}: {{'.format(sc[0]))
+ if value & 256:
+ print('\tVisible: true')
+ value &= ~256;
+
+ print('\tFlags: {')
+ for flag in flags:
+ if value & flag[1]:
+ print('\t\t{}: true'.format(flag[0]))
+ value &= ~flag[1];
+ if value != 0:
+ print('Error: invalid value ({}) for status ({}), aborting.'.format(int(sc[1]), sc[0]))
+ exit()
+ print('\t}')
+ print('}')
diff --git a/tools/utils/common.py b/tools/utils/common.py
index acceb9b30..06695751a 100644
--- a/tools/utils/common.py
+++ b/tools/utils/common.py
@@ -21,7 +21,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import io
-import libconf as libconf
+import sys
+if sys.version_info >= (3, 0):
+ from utils import libconf as libconf
+else:
+ import libconf as libconf
import os.path
def LoadDBConsts(DBname, mode, serverpath):