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

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

private alias object.propertyValue : object.setLBounds

private alias object.value0 : object.timer

// States
private alias 0 : WFZEGGMAN_AWAITPLAYER
private alias 1 : WFZEGGMAN_WATCHFIGHT
private alias 2 : WFZEGGMAN_ESCAPE

// Player Aliases
private alias object.xpos : player.xpos

// Music Events
private alias 26 : SLOT_MUSICEVENT_BOSS

private alias  0 : MUSICEVENT_FADETOBOSS
private alias  1 : MUSICEVENT_FADETOSTAGE


// ========================
// Static Values
// ========================

private value WFZEggman_laserType = 0


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

event ObjectUpdate
	switch object.state
	case WFZEGGMAN_AWAITPLAYER
		temp0 = object.xpos
		temp0 -= 0x200000
		if player[0].xpos > temp0
			temp0 = stage.newYBoundary2
			temp0 -= screen.ysize
			stage.newYBoundary1 = temp0

			if object.setLBounds == true
				temp0 = object.ixpos
				temp0 -= 212
				stage.newXBoundary1 = temp0
			end if
			object.xpos += 0xE00000

			object[+1].type 		= TypeName[Eggman Barrier]
			object[+1].inkEffect 	= 3

			object[+2].type 			= TypeName[Eggman Barrier]
			object[+2].propertyValue 	= 1
			object[+2].inkEffect 		= 3

			object[+4].type = WFZEggman_laserType

			ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOBOSS, 0, 0)
			object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE
			
			object.priority = PRIORITY_ACTIVE
			object.state = WFZEGGMAN_WATCHFIGHT
		end if
		break

	case WFZEGGMAN_WATCHFIGHT
		break

	case WFZEGGMAN_ESCAPE
		object.ypos += 0x10000
		object.timer++
		if object.timer == 240
			stage.newYBoundary1 = 0
			object.type = TypeName[Blank Object]
			ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOSTAGE, 0, 0)
			object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE
		end if
		break
		
	end switch

	object.animationTimer++
	if object.animationTimer >= 6
		object.animationTimer = 0
		object.frame ^= 1
	end if
end event


event ObjectDraw
	if object.state > 0
		DrawSprite(object.frame)
		DrawSprite(2)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-16, -28, 32, 52, 398, 203)
		SpriteFrame(-16, -27, 32, 51, 431, 204)
		SpriteFrame(-32, 24, 64, 24, 1, 146)
		WFZEggman_laserType = TypeName[Eggman Laser]
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -28, 32, 52, 737, 58)
		SpriteFrame(-16, -27, 32, 51, 770, 58)
		SpriteFrame(-32, 24, 64, 24, 464, 999)
		WFZEggman_laserType = TypeName[Eggman Laser 3]
	end if
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			break
			
		case 0 // setLBounds
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // setLBounds
			object.propertyValue = editor.variableValue
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-16, -28, 32, 52, 398, 203)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -28, 32, 52, 737, 58)
	end if
	
	AddEditorVariable("setLBounds")
	SetActiveVariable("setLBounds")
	AddEnumVariable("false", false)
	AddEnumVariable("true", true)
end event
