Scriptname KA_RevakheimTripleSCRIPT extends activemagiceffect  
{Script that handles the use of the clay Revakheim mask as a key to the forge}

float property posX auto hidden
float property posY auto hidden
float property posZ auto hidden

float property rotX auto hidden
float property rotY auto hidden
float property rotZ auto hidden

objectReference property RangeMarkerBridgePresent auto
objectReference property RangeMarkerForgePresent auto
objectReference property RangeMarkerBedroomPresent auto
objectReference property RangeMarkerScrollPresent auto

objectReference property RangeMarkerBridgePast auto
objectReference property RangeMarkerForgePast auto
objectReference property RangeMarkerBedroomPast auto
objectReference property RangeMarkerScrollPast auto

objectReference property PopInMarkerBridgePresent auto
objectReference property PopInMarkerForgePresent auto
objectReference property PopInMarkerBedroomPresent auto
objectReference property PopInMarkerScrollPresent auto

objectReference property PopInMarkerBridgePast auto
objectReference property PopInMarkerForgePast auto
objectReference property PopInMarkerBedroomPast auto
objectReference property PopInMarkerScrollPast auto

objectReference property BridgeBoundry01 auto
objectReference property BridgeBoundry02 auto
objectReference property BridgeBoundry03 auto

objectReference property BedroomBoundry01 auto
objectReference property BedroomBoundry02 auto

objectReference property ScrollBoundry auto

float property RangeBedroom = 705.0 auto
{705 BY DEFAULT}
float property RangeForge = 512.0 auto
{512 BY DEFAULT}
float property RangeBridge = 615.0 auto
{615 BY DEFAULT}
float property RangeScroll = 615.0 auto
{615 BY DEFAULT}

location property KA_RevakheimLocation auto
location property KA_RevakheimVaultLocation auto
location property KA_RevakheimTrialsLocation auto

imageSpaceModifier property AzuraFadeToBlack auto
{Use a basic fade-to-black for the transition}
imageSpaceModifier property FadeToBlackBackImod auto

Sound Property TransitionSFX  Auto 

objectReference property maskActual auto
{Point explicity to the unique, placed reference of the mask in the world}
ObjectReference selfRef

actor property playerRef auto

;======================/
;			MASK ON				/
;======================/

EVENT OnEffectStart(Actor Target, Actor Caster)	
;selfRef = caster
	
;=========================================================================
;			Forge
;=========================================================================
	if ((playerRef.getDistance(RangeMarkerForgePresent) <= RangeForge) && (caster == playerRef))
		effectIntro()
		playerRef.moveTo(PopInMarkerForgePast, abMatchRotation = false)
		playerRef.setAngle(rotX, rotY, (rotZ + 220))
		FadeToBlackBackImod.apply()
		AzuraFadeToBlack.remove()
;=========================================================================
;			Living Quarters
;=========================================================================
	elseif ((playerRef.getDistance(RangeMarkerBedroomPresent) <= RangeBedroom) && (caster == playerRef))
		effectIntro()
		playerRef.moveTo(PopInMarkerBedroomPast)
		effectOutro()
;=========================================================================
;			Elder Scroll
;=========================================================================
	elseif ((playerRef.getDistance(RangeMarkerScrollPresent) <= RangeScroll) && (caster == playerRef))
		if (playerRef.getDistance(ScrollBoundry) >= 160)	
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			posX = ((playerRef.GetPositionX()) + 8)
			posY = ((playerRef.GetPositionY()) + 8)
			posZ = ((playerRef.GetPositionZ()) + 2.95)
			rotX = playerRef.GetAngleX()
			rotY = playerRef.GetAngleY()
			rotZ = playerRef.GetAngleZ()
			playerRef.moveTo(PopInMarkerScrollPast, abMatchRotation = false)
			effectOutro()
		else
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			rotX = playerRef.GetAngleX()
			rotY = playerRef.GetAngleY()
			rotZ = playerRef.GetAngleZ()
			playerRef.moveTo(PopInMarkerScrollPast, abMatchRotation = false)
			playerRef.setAngle(rotX, rotY, rotZ)
			FadeToBlackBackImod.apply()
			AzuraFadeToBlack.remove()
		endif		
;=========================================================================
;			Bridge
;=========================================================================
	elseif ((playerRef.getDistance(RangeMarkerBridgePresent) <= RangeBridge) && (caster == playerRef))
		AzuraFadeToBlack.apply()
		TransitionSFX.play(playerRef)
		utility.wait(2.5)
		posX = ((playerRef.GetPositionX()) - 5632)
		posY = ((playerRef.GetPositionY()) + 512)
		posZ = ((playerRef.GetPositionZ()) + 3584)
		rotX = playerRef.GetAngleX()
		rotY = playerRef.GetAngleY()
		rotZ = playerRef.GetAngleZ()
		playerRef.moveTo(PopInMarkerBridgePast, abMatchRotation = false)
		effectOutro()
	else
		; do nothing
	endif
endEVENT

;======================/
;			MASK OFF				/
;======================/


EVENT onEffectFinish(Actor Target, Actor Caster)
;=========================================================================
;			Forge
;=========================================================================
	if ((playerRef.getDistance(RangeMarkerForgePast) <= RangeForge) && (caster == playerRef))
		effectIntro()		
		playerRef.moveTo(PopInMarkerForgePresent, abMatchRotation = false)		
		playerRef.setAngle(rotX, rotY, (rotZ + 50))
		FadeToBlackBackImod.apply()
		AzuraFadeToBlack.remove()
		maskcheck()
;=========================================================================
;			Living Quarters
;=========================================================================
	elseif ((playerRef.getDistance(RangeMarkerBedroomPast) <= RangeBedroom) && (caster == playerRef))
		if ((playerRef.getDistance(bedroomBoundry01) > 165) && (playerRef.getDistance(bedroomBoundry02) > 300))
			effectIntro()
			playerRef.moveTo(PopInMarkerBedroomPresent, abMatchRotation = false)
			effectOutro()
		else
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			playerRef.moveTo(PopInMarkerBedroomPresent, abMatchRotation = false)
			FadeToBlackBackImod.apply()
			AzuraFadeToBlack.remove()
		endif
		maskCheck()
;=========================================================================
;			Elder Scroll
;=========================================================================
	elseif ((Caster == playerRef) && (playerRef.isInLocation(KA_RevakheimVaultLocation) == TRUE))		
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			posX = (playerRef.GetPositionX() - 8)
			posY = (playerRef.GetPositionY() - 8)
			posZ = (playerRef.GetPositionZ() + 800)
			rotX = playerRef.GetAngleX()
			rotY = playerRef.GetAngleY()
			rotZ = playerRef.GetAngleZ()
			playerRef.moveTo(PopInMarkerScrollPresent, abMatchRotation = false)
			effectOutro()
		maskCheck()
;=========================================================================
;			Pit and Maze
;=========================================================================
	elseif ((caster == playerRef) && (playerRef.isInLocation( KA_RevakheimTrialsLocation) == TRUE))
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			playerRef.moveTo(PopInMarkerBridgePresent)
			FadeToBlackBackImod.apply()
			AzuraFadeToBlack.remove()
			maskCheck()
;=========================================================================
;			Bridge
;=========================================================================
	elseif ((caster == playerRef) && (playerRef.isInLocation(KA_RevakheimLocation) == TRUE))
		if (playerRef.getDistance(BridgeBoundry01) > 650) && (playerRef.getDistance(BridgeBoundry02) > 990) && (playerRef.getDistance(BridgeBoundry03) > 990)
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			posX = (playerRef.GetPositionX() + 5632)
			posY = (playerRef.GetPositionY() - 512)
			posZ = (playerRef.GetPositionZ() - 3584)
			rotX = playerRef.GetAngleX()
			rotY = playerRef.GetAngleY()
			rotZ = playerRef.GetAngleZ()
			playerRef.moveTo(PopInMarkerBridgePresent, abMatchRotation = false)
			effectOutro()
			maskCheck()
		else
			AzuraFadeToBlack.apply()
			TransitionSFX.play(playerRef)
			utility.wait(2.5)
			playerRef.moveTo(PopInMarkerBridgePresent)
			FadeToBlackBackImod.apply()
			AzuraFadeToBlack.remove()
		endif

	else
		;do nothing
	endIf
endEVENT

;======================/
;			INTRO FUNCTION		/
;======================/
Function effectIntro()
	AzuraFadeToBlack.apply()
	TransitionSFX.play(playerRef)
	utility.wait(2.5)
	posX = playerRef.GetPositionX()
	posY = playerRef.GetPositionY()
	posZ = playerRef.GetPositionZ()
	rotX = playerRef.GetAngleX()
	rotY = playerRef.GetAngleY()
	rotZ = playerRef.GetAngleZ()
endFunction

;======================/
;			OUTRO FUNCTION		/
;======================/
FUNCTION effectOutro()
	playerRef.setPosition(posX, posY, posZ)
	playerRef.setAngle(rotX, rotY, rotZ)
	FadeToBlackBackImod.apply()
	AzuraFadeToBlack.remove()
endFUNCTION

;======================/
;			MASK BACKUP			/
;======================/
FUNCTION maskCheck()
if playerRef.getItemCount(maskActual) < 1
	playerRef.addItem(maskActual)
endif
endFUNCTION