#===============================================================#
#   )      (\_     | WOLFPACK 13.0.0 Scripts                    #
#  ((    _/{  "-;  | Created by: DarkStorm                      #
#   )).-' {{ ;'`   | Revised by:                                #
#  ( (  ;._ \\ ctr | Last Modification: Created                 #
#===============================================================#
# Script for Recall (Magic)										#
#===============================================================#

import wolfpack
from wolfpack.utilities import *

def onSpellSuccess( char, spell, type, target ):
	# Check the target : LoS, range check have done in c++ core
	# check the tile
	x = target.pos.x
	y = target.pos.y
	world = target.pos.map
	tmap = map( x, y, world )
	tstatics = statics( x, y, world )
	# how to check items ?
	titem = items( x, y, world )
	if not tmap and not tstatics:
		char.socket.sysmessage( "Invalid teleport target" )
		return 1
	if( tstatics ):
		id = tstatics.id
		z = tstatics.z
	elif( tmap ):
		id = tmap.id
		z = tmap.z
	tile = _wolfpack.tiledata( id )
	if not tile:
		char.socket.sysmessage( "Invalid teleport target" )
		return 1
	if( ( tile.flag1 & 0x40 ) == 0x40 ): # blocking tile
		char.socket.sysmessage( "Invalid teleport target" )
		return 1
	char.soundeffect( 0x1ff )
	char.effect( 0x3728 )
	char.removefromview()
	char.moveto( x, y, z, char.pos.map )
	char.update()
	char.soundeffect( 0x1ff )
	char.effect( 0x372a )
	# We moved so resync us
	char.socket.resendworld()
	return 1
