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

import wolfpack
from wolfpack.consts import *
import whrandom

def onSpellSuccess( char, spell, type, target ):
	# target check is done at c++ code
	defender = target.char
	if not defender:
		return
	if defender.hastag( "reactivearmor" ):
		char.socket.sysmessage( "Already under the influence!" )
		return 1
	# effects
	defender.soundeffect( 0x1f3 )
	defender.effect( 0x375a )
	# disturb medi
	defender.disturb()
	# unfreeze - needed to be implemented
	# reactive armor tag to core function or armor modifier functoin - needed to be implemented
	whrandom.seed()
	rand = whrandom.randint( 1, 11 )
	duration = rand * 10000 + char.skill[ MAGERY ] * 50
	modArmor = char.skill[ MAGERY ] / 100
	defender.settag( "reactivearmor", modArmor )
	defender.addtimer( "reactivearmor.restore", duration, ( defender.serial, ) )
	defender.update()
	return 1

def restore( serial ):
	char = findchar( serial )
	if not char:
		return 1
	if not char.hastag( "reactivearmor" ):
		return 1
	char.removetag( "reactivearmor" )
	char.update()
	return 1
