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

import wolfpack
from wolfpack.consts import *
from wolfpack.utilities import *
from math import floor
import whrandom

def onSpellSuccess( char, spell, type, target ):
	# target check is done at c++ code
	defender = target.char
	if not defender:
		return

	# check criminal : noto - party, guild, faction systems are affected
	agression( char, defender, spell )
	if not defender.hastag( "poisoned" ):
		char.socket.sysmessage( "%s is not poisoned." % defender.name )
		return 1

	# effects
	defender.soundeffect( 0x1e1 )
	defender.effect( 0x374a )

	# skill 1.0 = 100 point
	# GM magery can cure upto level 4 poison
	poisonLevel = int( defender.gettag( "poisoned" ) )
	cureLevel = floor( char.skill[ MAGERY ] / 200 )

	# Will be mor or less put into defender.disturb() + defender.unfreeze() 
	# Stand by!
	# disturb medi
	defender.disturb()
	# unfreeze - needed to be implemented
	if( poisonLevel > cureLevel ):
		char.socket.sysmessage( "You failed to cure your target of all poisons!" )
		return 1
	whrandom.seed()
	if( whrandom.randint( 0, 20 ) <= (  char.skill[ MAGERY ] / 10 - poisonLevel * 20 ) ):
		defender.removetag( "poisoned" )
		char.socket.sysmessage( "%s cured." )
		defender.socket.sysmessage( "%s cured you completely!" % char.name )
	else:
		char.socket.sysmessage( "You failed to cure your target of all poisons!" )
	return 1
