// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Eggman Claw Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value1 : object.parent
private alias object.value2 : object.electricityActive
private alias object.value3 : object.electricityFrame

// States
private alias 0 : CNZEGGMANCLAW_ACTIVE
private alias 1 : CNZEGGMANCLAW_DEBRIS

// CNZEggman Aliases
private alias object.value4  : cnzEggman.invincibilityTimer
private alias object.value10 : cnzEggman.isClawWide


// ========================
// Events
// ========================

event ObjectUpdate
	if object.state == CNZEGGMANCLAW_ACTIVE
		arrayPos0 = object.parent
		object.xpos = object[arrayPos0].xpos
		object.ypos = object[arrayPos0].ypos

		if object.electricityActive == true
			if cnzEggman[arrayPos0].invincibilityTimer < 48
				if cnzEggman[arrayPos0].isClawWide == false
					foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
						BoxCollisionTest(C_TOUCH, object.entityPos, -16, 40, 16, 48, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
						if checkResult == true
							CallFunction(Player_Hit)
						end if
					next
				else
					foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
						BoxCollisionTest(C_TOUCH, object.entityPos, -28, 32, 28, 40, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
						if checkResult == true
							CallFunction(Player_Hit)
						end if
					next
				end if
			end if

			object.animationTimer++
			object.animationTimer %= 6
		end if
	else
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800

		if object.outOfBounds == true
			object.type = TypeName[Blank Object]
		end if
	end if
end event


event ObjectDraw
	if object.state == CNZEGGMANCLAW_ACTIVE
		arrayPos0 = object.parent
		object.direction = object[arrayPos0].direction

		object.frame = cnzEggman[arrayPos0].isClawWide
		object.frame <<= 1
		object.frame += object.propertyValue
		DrawSpriteFX(object.frame, FX_FLIP, object[arrayPos0].xpos, object[arrayPos0].ypos)

		if object.electricityActive == true
			object.electricityFrame = cnzEggman[arrayPos0].isClawWide
			object.electricityFrame *= 3

			temp0 = object.animationTimer
			temp0 >>= 1
			object.electricityFrame += temp0
			object.electricityFrame += 4
			DrawSpriteFX(object.electricityFrame, FX_FLIP, object[arrayPos0].xpos, object[arrayPos0].ypos)
		end if
	else
		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone04")
	if checkResult == true
		LoadSpriteSheet("CNZ/Objects.gif")
		SpriteFrame(-28, 24, 16, 24, 77, 231)	// Claw L (Closed) 		- #0
		SpriteFrame(8, 19, 24, 28, 150, 227)	// Claw R (Closed) 		- #1
		SpriteFrame(-37, 19, 16, 20, 94, 235)	// Claw L (Open) 		- #2
		SpriteFrame(8, 17, 38, 22, 111, 233)	// Claw R (Open) 		- #3
		SpriteFrame(-16, 40, 32, 7, 142, 205)	// Electricity (Short) 	- #4
		SpriteFrame(-16, 40, 32, 7, 142, 213)	// Electricity (Short) 	- #5
		SpriteFrame(-16, 41, 32, 5, 142, 221)	// Electricity (Short) 	- #6
		SpriteFrame(-28, 33, 64, 6, 77, 209)	// Electricity (Wide) 	- #7
		SpriteFrame(-28, 32, 64, 8, 77, 216)	// Electricity (Wide) 	- #8
		SpriteFrame(-28, 34, 64, 5, 77, 225)	// Electricity (Wide) 	- #9
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-28, 24, 16, 24, 134, 154)	// Claw L (Closed) 		- #0
		SpriteFrame(8, 19, 24, 28, 207, 154)	// Claw R (Closed) 		- #1
		SpriteFrame(-37, 19, 16, 20, 151, 154)	// Claw L (Open) 		- #2
		SpriteFrame(8, 17, 38, 22, 168, 154)	// Claw R (Open) 		- #3
		SpriteFrame(-16, 40, 32, 7, 167, 130)	// Electricity (Short) 	- #4
		SpriteFrame(-16, 40, 32, 7, 167, 138)	// Electricity (Short) 	- #5
		SpriteFrame(-16, 41, 32, 5, 167, 146)	// Electricity (Short) 	- #6
		SpriteFrame(-28, 33, 64, 6, 167, 108)	// Electricity (Wide) 	- #7
		SpriteFrame(-28, 32, 64, 8, 167, 115)	// Electricity (Wide) 	- #8
		SpriteFrame(-28, 34, 64, 5, 167, 124)	// Electricity (Wide) 	- #9
	end if
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone04")
	if checkResult == true
		LoadSpriteSheet("CNZ/Objects.gif")
		SpriteFrame(-28, 24, 16, 24, 77, 231)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-28, 24, 16, 24, 134, 154)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
