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

import wolfpack
from spells.spellfunctions import *
import whrandom
from wolfpack.consts import *

def onSpellSuccess( char, spell, type, target ):
	# target check is done at c++ code
	defender = target.char
	if not defender:
		return
	# noto check
	agression( char, defender, spell )
	attacker = char
	reflected = magicReflection( char, defender )
	if( reflected == 1 ):
		attacker = defender
		defender = char
	# check resist
	resist = resistSpell( attacker, defender, spell )
	if( resist == 1 ):
		defender.socket.sysmessage( "You feel yourself resisting magical energy!")
	# effects
	defender.soundeffect( 0x1e6 )
	defender.effect( 0x36e4 )
	# disturb medi
	defender.disturb()
	# unfreeze - needed to be implemented
	# calc damage
	whrandom.seed()
	# magic arrow damage = 1d8
	basedamage = whrandom.randint( 1, 9 )
	if( resist == 1 ):
		basedamage = basedamage / 2
	damage = totalSpellDamage( attacker, defender, spell, basedamage )
	defender.damage( damage )
	return 1

