#################################################################
#   )      (\_     # 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( 0x15f )
	defender.effect( 0x36d4 )
	# disturb medi
	defender.disturb()
	# unfreeze - needed to be implemented
	# calc damage
	whrandom.seed()
	# fireball damage = 3d6
	basedamage = 3 * whrandom.randint( 1, 7 )
	if( resist == 1 ):
		basedamage = basedamage / 2
	damage = totalSpellDamage( attacker, defender, spell, basedamage )
	if( defender.npc ):
		damage = damage * 2
	defender.damage( damage )
	return 1

