Scriptname KA_RevRitualSCRIPT extends ObjectReference  

bool property isGemAct auto
{check gem placement (or mask)}
bool property isMaskAct auto
{check mask placement (or gem)}
soulgem property SoulGemGrand auto
armor property myMask auto
{Which mask am I made for?}
int property myIndex auto
{Need indices to track the various masks and gems}
message property defaultLackTheItemMSG auto
KA_revRitualMaster property master auto

bool property Placed auto

bool placed = FALSE
Auto STATE waiting
EVENT onActivate(objectReference actronaut)
gotoState ("busy")
;===================================================
;	IF ACTIVATING A MASK BUST
;===================================================		
if isMaskACT
	if placed == FALSE
		if actronaut.getItemCount(myMask) >= 1
			blockActivation()
			actronaut.removeItem(myMask, 1)
			placed = TRUE
			getLinkedRef().playAnimationandWait("on","TransOn")
			updateMaster()
			blockActivation(FALSE)
		else
			if (actronaut == Game.GetPlayer())
			defaultLackTheItemMSG.show()
			endif
		endif

	elseIf placed == TRUE
		blockActivation()
		actronaut.addItem(myMask, 1)
		Placed = FALSE
		getLinkedRef().playAnimationAndWait("off","TransOff")
		updateMaster()
		blockActivation(FALSE)
	endIf	

;===================================================
;	IF ACTIVATING A GEM RECEPTICLE
;===================================================

elseif isGemACT
	if placed == FALSE
		if actronaut.GetItemCount(SoulGemGrand) >= 1
			blockActivation()
			actronaut.removeitem(SoulGemGrand, 1)
			placed = TRUE			
			getLinkedRef().enable()
			updateMaster()
			blockActivation(FALSE)
		else
			if (actronaut == Game.GetPlayer())		
				defaultLackTheItemMSG.show()
			endif
		endif

	elseif placed == TRUE
		blockActivation()		
		placed = FALSE
		actronaut.additem(SoulGemGrand, 1)
		getLinkedRef().disable()
		updateMaster()
		blockActivation(FALSE)
	endif
	
endIf
gotoState ("waiting")
endEVENT
endSTATE

STATE busy
	EVENT onActivate (objectReference triggerRef)
			;do nothing
	endEVENT
endSTATE

;===================================================
;	UPDATE MASTER
;===================================================
FUNCTION updateMaster()	
if isMaskACT		
		if myIndex == 01
			master.mask01placed = placed
		elseif myIndex == 02
			master.mask02placed = placed
		elseif myIndex == 03
			master.mask03placed = placed
		elseif myIndex == 04
			master.mask04placed = placed
		elseif myIndex == 05
			master.mask05placed = placed
		elseif myIndex == 06
			master.mask06placed = placed
		elseif myIndex == 07
			master.mask07placed= placed
		elseif myIndex == 08
			master.mask08placed = placed
		endif
elseif isGemACT
		if myIndex == 01
			master.gem01placed = placed
		elseif myIndex == 02
			master.gem02placed = placed
		elseif myIndex == 03
			master.gem03placed = placed
		elseif myIndex == 04
			master.gem04placed = placed
		elseif myIndex == 05
			master.gem05placed = placed
		elseif myIndex == 06
			master.gem06placed = placed
		elseif myIndex == 07
			master.gem07placed = placed
		elseif myIndex == 08
			master.gem08placed = placed
		endif
endif	
endFUNCTION

;===================================================
;	CLEAR ALTAR
;===================================================
FUNCTION ClearAltar()
activate(self)
updateMaster()
endFUNCTION