summaryrefslogtreecommitdiff
path: root/hercules
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-06-22 22:13:11 -0300
committerJesusaves <cpntb1@ymail.com>2020-06-22 22:13:11 -0300
commit711e8efeca69bbb4d00b2d87b152343a1178e425 (patch)
treed59f0889aadb0dac53c2b3093ef5fd39ffed3196 /hercules
parenteff7882787bf064c4b90583507922505130fc3f0 (diff)
downloadtools-711e8efeca69bbb4d00b2d87b152343a1178e425.tar.gz
tools-711e8efeca69bbb4d00b2d87b152343a1178e425.tar.bz2
tools-711e8efeca69bbb4d00b2d87b152343a1178e425.tar.xz
tools-711e8efeca69bbb4d00b2d87b152343a1178e425.zip
Initial version of DynCollision and Switch
Diffstat (limited to 'hercules')
-rwxr-xr-xhercules/tmx_converter.py118
1 files changed, 110 insertions, 8 deletions
diff --git a/hercules/tmx_converter.py b/hercules/tmx_converter.py
index a29da5f..5b21961 100755
--- a/hercules/tmx_converter.py
+++ b/hercules/tmx_converter.py
@@ -69,6 +69,12 @@ NPC_WARPS = '_warps.txt'
NPC_IMPORTS = '_import.txt'
NPC_MASTER_IMPORTS = NPC_IMPORTS
+def ifte(ifs, thens, elses):
+ if ifs:
+ return thens
+ else:
+ return elses
+
class State(object):
pass
State.INITIAL = State()
@@ -114,6 +120,8 @@ class Warp(Object):
def __init__(self):
self.npc_id = 'WARP'
+# TMW2 CUSTOM OBJECTS
+####################################
class Slide(Object):
__slots__ = (
'dest_x',
@@ -126,6 +134,48 @@ class Slide(Object):
def __init__(self):
self.npc_id = 'SLIDE'
+class DynCollision(Object):
+ __slots__ = (
+ 'colid',
+ )
+ def __init__(self):
+ self.colid = 1
+
+class DungeonSwitch(Object):
+ __slots__ = (
+ 'enabled',
+ 'distance',
+ 'callfunc',
+ 'args',
+ )
+ def __init__(self):
+ self.enabled = False
+ self.distance = 2
+ self.args = ''
+
+class FunctionTrigger(Object):
+ __slots__ = (
+ 'callfunc',
+ 'doevent',
+ )
+ def __init__(self):
+ self.callfunc = ''
+ self.doevent = ''
+
+class Trap(Object):
+ __slots__ = (
+ 'disarmtime',
+ 'stuntime',
+ 'damage',
+ 'target',
+ )
+ def __init__(self):
+ self.disarmtime = 15
+ self.stuntime = 3
+ self.damage = 80
+ self.target = 2
+
+####################################
class ContentHandler(xml.sax.ContentHandler):
__slots__ = (
'locator', # keeps track of location in document
@@ -136,7 +186,7 @@ class ContentHandler(xml.sax.ContentHandler):
'compression', # compression of layer data
'width', # width of the height layer
'height', # height of the height layer
- 'firstgid', # first gid of height layer
+ 'firstgid', # first gid of height layer
'heightmap',# height map
'base', # base name of current map
'npc_dir', # world/map/npc/<base>
@@ -147,7 +197,7 @@ class ContentHandler(xml.sax.ContentHandler):
'object', # stores properties of the latest <object> tag
'mob_ids', # set of all mob types that spawn here
)
- def __init__(self, npc_dir, mobs, saves, warps, imports):
+ def __init__(self, npc_dir, mobs, confs, warps, imports):
xml.sax.ContentHandler.__init__(self)
self.locator = None
self.state = State.INITIAL
@@ -162,7 +212,7 @@ class ContentHandler(xml.sax.ContentHandler):
self.base = posixpath.basename(npc_dir)
self.npc_dir = npc_dir
self.mobs = mobs
- self.saves = saves
+ self.confs = confs
self.warps = warps
self.imports = imports
self.object = None
@@ -198,8 +248,8 @@ class ContentHandler(xml.sax.ContentHandler):
self.name = attr[u'value']
self.mobs.write('// %s\n' % MESSAGE)
self.mobs.write('// Map %s: %s mobs\n' % (self.base, self.name))
- self.saves.write('// %s\n' % MESSAGE)
- self.saves.write('// Map %s: %s saves\n' % (self.base, self.name))
+ self.confs.write('// %s\n' % MESSAGE)
+ self.confs.write('// Map %s: %s conf\n' % (self.base, self.name))
self.warps.write('// %s\n' % MESSAGE)
self.warps.write('// Map %s: %s warps\n' % (self.base, self.name))
@@ -262,12 +312,38 @@ class ContentHandler(xml.sax.ContentHandler):
y += h/2
w -= 1
h -= 1
+ ### TMW2 INSTANCES
+ ##########################################################
elif obj_type == 'slide':
self.object = Slide()
x += w/2
y += h/2
w -= 1
h -= 1
+ elif obj_type == 'dyncollision':
+ self.object = DynCollision()
+ x += w/2
+ y += h/2
+ w -= 1
+ h -= 1
+ elif obj_type == 'switch':
+ self.object = DungeonSwitch()
+ x += w/2
+ y += h/2
+ w -= 1
+ h -= 1
+ elif obj_type == 'function':
+ self.object = FunctionTrigger()
+ x += w/2
+ y += h/2
+ w -= 1
+ h -= 1
+ elif obj_type == 'trap':
+ self.object = Trap()
+ x += w/2
+ y += h/2
+ w -= 1
+ h -= 1
else:
if obj_type not in other_object_types:
print('Unknown object type:', obj_type, file=sys.stderr)
@@ -330,7 +406,7 @@ class ContentHandler(xml.sax.ContentHandler):
self.mob_cnt = True
elif isinstance(obj, Save):
obj_name = "%s_%s_%s" % (self.base, obj.x, obj.y)
- self.saves.write(
+ self.confs.write(
SEPARATOR.join([
'%s,%d,%d,0\tscript\t#save_%s\tNPC_SAVE_POINT,{\n' % (self.base, obj.x, obj.y, obj_name),
' savepointparticle .map$, .x, .y, %s;\n close;\n\nOnInit:\n .distance = 2;\n .sex = G_OTHER;\n end;\n}\n' % (obj.inn),
@@ -357,6 +433,8 @@ class ContentHandler(xml.sax.ContentHandler):
])
)
self.warp_cnt = True
+ ### TMW2 INSTANCES
+ ##############################################################
elif isinstance(obj, Slide):
if (obj.npc_id == u'SLIDE'):
obj_name = "#%s_%s_%s" % (self.base, obj.x, obj.y)
@@ -378,6 +456,30 @@ class ContentHandler(xml.sax.ContentHandler):
])
)
self.warp_cnt = True
+ elif isinstance(obj, DynCollision):
+ obj_name = "%s_%s_%s" % (self.base, obj.x, obj.y)
+ self.confs.write(
+ SEPARATOR.join([
+ '%s,%d,%d,0\t' % (self.base, obj.x, (obj.y)),
+ 'script\t',
+ '%s\tNPC_HIDDEN,{\n\tend;\nOnDisable:\n\tdelcells "%s"; end;\n' % (obj_name, obj_name),
+ 'OnEnable:\nOnInit:\n\tsetcells "%s", %d, %d, %d, %d, %d, "%s";\n}\n' % (self.base, obj.x, obj.y, obj.x+obj.w, obj.y+obj.h, obj.colid, obj_name),
+ ])
+ )
+ self.save_cnt = True
+ elif isinstance(obj, DungeonSwitch):
+ obj_name = "%s_%s_%s" % (self.base, obj.x, obj.y)
+ self.confs.write(
+ SEPARATOR.join([
+ '%s,%d,%d,0\t' % (self.base, obj.x, (obj.y)),
+ 'script\t',
+ '%s\tNPC_SWITCH_%s,{\n\tcallfunc "%s"%s;\n' % (obj_name, ifte(obj.enabled, "OFFLINE", "ONLINE"), obj.callfunc, ifte(obj.args != '', ", %s" % obj.args, "")),
+ '\tsetnpcdisplay %s, NPC_SWITCH_%s;\n\tend;\nOnInit:\n\t.distance=%d;\n}\n' % (obj_name, ifte(obj.enabled, "ONLINE", "OFFLINE"), obj.distance),
+ ])
+ )
+ self.save_cnt = True
+
+ ##############################################################
if name == u'data':
if self.state is State.DATA:
@@ -447,10 +549,10 @@ def main(argv):
os.path.isdir(main.this_map_npc_dir) or os.mkdir(main.this_map_npc_dir)
print('Converting %s' % (tmx))
with open(posixpath.join(main.this_map_npc_dir, NPC_MOBS), 'w') as mobs:
- with open(posixpath.join(main.this_map_npc_dir, NPC_CONFIG), 'w') as saves:
+ with open(posixpath.join(main.this_map_npc_dir, NPC_CONFIG), 'w') as confs:
with open(posixpath.join(main.this_map_npc_dir, NPC_WARPS), 'w') as warps:
with open(posixpath.join(main.this_map_npc_dir, NPC_IMPORTS), 'w') as imports:
- xml.sax.parse(tmx, ContentHandler(main.this_map_npc_dir, mobs, saves, warps, imports))
+ xml.sax.parse(tmx, ContentHandler(main.this_map_npc_dir, mobs, confs, warps, imports))
if os.path.isfile(posixpath.join(main.this_map_npc_dir, NPC_IMPORTS)):
npc_master.append('@include "%s"\n' % posixpath.join(SERVER_NPCS, base, NPC_IMPORTS))
if heigherror: