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

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

def onSpellSuccess( attacker, spell, type, target ):
	defender = target.char

	if not defender:
		return

	if defender == attacker:
		if attacker.socket:
			attacker.socket.sysmessage( "You can't cast this on yourself." )
		return

	# Casting clumsy is an agression
	spellAgression( attacker, defender )

	# check reflection
	reflected = magicReflection( attacker, defender )
	if( reflected == 1 ):
		attacker = defender
		defender = char

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

	# not a resistable spell : just check the damage : 1 ~ 11
	# skill 1.0 = 10 point
	damage = - floor( 1 + attacker.skill[ MAGERY ] / 100 ) # One Bonus point per 10.0 Skill

	# Disturb Casting of Spells and Meditation
	defender.disturb()

	# Bit 2 set in Priv2 = Frozen
	if char.priv2 & 0x02:
		char.priv2 &= 0xFD

	# FIXME: Duration is more or less unknown for this spell
	statmodifier( defender, CLUMSY_DURATION, 0, damage, 0 )
	return 1
