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

import wolfpack
from spells.spellfunctions import *
import whrandom

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( 0x1f2 )
	defender.effect( 0x37c3 )
	# disturb medi
	defender.disturb()
	# unfreeze - needed to be implemented
	# calc damage
	#whrandom.seed()
	# harm damage = 1d12
	#basedamage = whrandom.randint( 1, 13 )
	basedamage = 12
	if( resist == 1 ):
		basedamage = basedamage / 2
	damage = totalSpellDamage( attacker, defender, spell, basedamage )
	if( defender.npc ):
		damage = damage * 2
	if( attacker.distanceto( defender ) > 1 ):
		damage = damage / attacker.distanceto( defender )
	defender.damage( damage )
	return 1

