#################################################################
#   )      (\_     # WOLFPACK 13.0.0 Scripts                    #
#  ((    _/{  "-;  # Created by: khpae                          #
#   )).-" {{ ;"`   # Revised by:                                #
#  ( (  ;._ \\ ctr # Last Modification: Created                 #
#################################################################

import wolfpack
from spells.spellfunctions import *
from math import floor

def onSpellSuccess( char, spell, type, target ):
	# target check is done at c++ code
	tgt = target.item
	if not tgt:
		return
	# skill check is done in c++ core
	# target validation : multi ?
	# door / wooden box
	if( ( tgt.type == 12 ) or ( tgt.id == "e79" ) or ( tgt.id == "e7d" ) ):
		unlockLevel = floor( char.skill[ MAGERY ] / 40 )
	else:
		char.socket.sysmessage( "You cannot magic unlock that!" )
		return 1
	if( !tgt.hastag( "lockLevel" ) ):
		return
	lockLevel = int( tgt.gettag( "lockLevel" ) )
	tgt.soundeffect( 0x200 )
	if( lockLevel > unlockLevel ):
		char.socket.sysmessage( "Your spell does not seem to work on that lock!" )
		return 1
	# effects
	char.socket.sysmessage( "*Unlocked!*" )
	return 1

