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

import wolfpack
import wolfpack.consts
import whrandom

def resistSpell( attacker, defender, spell ):
	# do not use baseskill
	magery = int( attacker.skill[ MAGERY ] )
	resist = int( defender.skill[ MAGICRESISTANCE ] )
	# calc chance to resist
	circle = floor( spell / 8 )
	chance = floor( resist / 5 )
	# skill value is skill * 10
	chance2 = floor( resist - ( ( ( magery - 200 ) / 5 ) + circle * 50 ) )
	if( chance2 > chance ):
		chance = chance2
	if( chance <= 0 ):
		return 0
	whrandom.seed()
	rand = whrandom.randint( 0, 1000 )
	if( rand > chance ):
		return 0
	else:
		#defender.socket.sysmessage( "You feel yourself resisting magical energy!" )
		return 1

def totalSpellDamage( attacker, defender, spell, basedamage ):
	damage = basedamage
	if( defender.skill[ MAGICRESISTANCE ] > mage.skill[ EVALUATINGINTEL ] ):
		damage = damage * ( 1 + ( mage.skill[ EVALUATINGINTEL ] - defender.skill[ MAGICRESISTANCE ] ) / 2000 )
	else:
		damage = damage * ( 1 + ( mage.skill[ EVALUATINGINTEL ] - defender.skill[ MAGICRESISTANCE ] ) / 5000 )
	return damage

def magicReflection( attacker, defecnder ):
	if defender.hastag( "magicreflection" ):
		attacker.socket.sysmessage( "Your magic reflect spell saved you!" )
		defender.soundeffect( 0x1e8 )
		defender.effect( 0x374a )
		defender.removetag( "magicreflection" )
		return 1
	return 0

