x020041_g_scriptId = 020041

x020041_g_Boss1Id = {430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001,430001}
x020041_g_Boss1Pos = {61,65,0} --(x,z,f)
x020041_g_Boss1Shout = 1
x020041_g_Boss1FakeObjId = 1
x020041_g_Boss1CallSkill = 207900
x020041_g_Boss1CallStartTime = 4
x020041_g_Boss1CallDuration = 30
x020041_g_Monster1Id = {409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250}
x020041_g_Monster1IdPos = {{60, 65, 0}, {62, 65, 0}, {61, 64, 0}, {61, 66, 0}}

x020041_g_Boss2Id = {430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101,430101}
x020041_g_Boss2Pos = {61,65,0}
x020041_g_Boss2Shout = 1
x020041_g_Boss2FakeObjId = 1
x020041_g_Boss2CallSkill = 207900
x020041_g_Boss2CallStartTime = 4
x020041_g_Boss2CallDuration = 30
x020041_g_Monster2Id1 = {409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250}
x020041_g_Monster2Id2 = {409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250}
x020041_g_Monster2Id1Pos = {{60, 65, 0}, {62, 65, 0}}
x020041_g_Monster2Id2Pos = {{61, 64, 0}, {61, 66, 0}}

x020041_g_Boss3Id = {430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201,430201}
x020041_g_Boss3Pos = {61,65,0}
x020041_g_Boss3State = 4
x020041_g_Boss3Impact = 1
x020041_g_Boss3Shout = 1
x020041_g_Boss3FakeObjId = 1
x020041_g_Boss3StartTime = 5
x020041_g_Boss3Duration = 300

x020041_g_Boss4Id = {}
x020041_g_Boss4Id[1] = {430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301,430301}
x020041_g_Boss4Id[2] = {430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401,430401}
x020041_g_Boss4Pos = {{60,64,0}, {62,66,0}}
x020041_g_Boss4Impact = 1
x020041_g_Boss4Shout = 1
x020041_g_Boss4StartTime = 4
x020041_g_Boss4Duration = 30
x020041_g_Boss4State = 5

x020041_g_Boss5Id = {430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501,430501}
x020041_g_Boss5Pos = {61,65,0}
x020041_g_Boss5Impact = 1
x020041_g_Monster5Id = {409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250,409250}
x020041_g_Monster5Pos = {61, 64, 0}
x020041_g_Boss5MonsterHpImpactIndex = 6
x020041_g_Boss5MonsterHpImpact = {1, 2, 3, 4, 5}
x020041_g_Boss5State = 4
x020041_g_Boss5Shout = 1
x020041_g_Boss5FakeObjId = 1
x020041_g_Boss5CallSkill = 207900
x020041_g_Boss5CallStartTime = 5
x020041_g_Boss5CallDuration = 30

x020041_g_Boss6Id = {430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601,430601}
x020041_g_Boss6Pos = {61,65,0}
x020041_g_Boss6LineSkill = 404251
x020041_g_Boss6Shout = 1
x020041_g_Boss6FakeObjId = 1
x020041_g_Boss6StartTime = 4
x020041_g_Boss6Duration = 15

x020041_g_Boss7Id = {}
x020041_g_Boss7Id[1] = {430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701,430701}
x020041_g_Boss7Id[2] = {430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801,430801}
x020041_g_Boss7Id[3] = {430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901,430901}
x020041_g_Boss7Id[4] = {431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001,431001}
x020041_g_Boss7Pos = {}
x020041_g_Boss7Pos[1] = {61,68,0}
x020041_g_Boss7Pos[2] = {61,63,0}
x020041_g_Boss7Pos[3] = {59,65,0}
x020041_g_Boss7Pos[4] = {63,65,0}
x020041_g_Boss7State = 4
x020041_g_Boss7DieImpact = 10010

x020041_g_Boss8Id = {}
x020041_g_Boss8Id[0]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[1]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[2]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[3]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[4]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[5]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[6]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[7]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[8]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[9]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Id[10]= {431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201,431201}
x020041_g_Boss8Pos = {61,65,0}
x020041_g_Boss8MonsterId = {431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301,431301}
x020041_g_Boss8MonsterPos = {}
x020041_g_Boss8MonsterPos[1] = {61, 77, 0}
x020041_g_Boss8MonsterPos[2] = {61, 53, 0}
x020041_g_Boss8MonsterPos[3] = {48, 65, 0}
x020041_g_Boss8MonsterPos[4] = {73, 65, 0}
x020041_g_Boss8MonsterPos[5] = {54, 72, 0}
x020041_g_Boss8MonsterPos[6] = {68, 72, 0}
x020041_g_Boss8MonsterPos[7] = {54, 55, 0}
x020041_g_Boss8MonsterPos[8] = {68, 54, 0}
x020041_g_Boss8MonsterPos[9] = {55, 65, 0}
x020041_g_Boss8MonsterPos[10] = {67, 65, 0}
x020041_g_Boss8State = 4
x020041_g_Boss8MonsterCount = 5
x020041_g_Boss8Shout = 1

x020041_g_Boss9Id = {431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401,431401}
x020041_g_Boss9Pos = {61,65,0}
x020041_g_Boss9CallMonsterId = {431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501,431501}
x020041_g_Boss9MonsterPos = {}
x020041_g_Boss9MonsterPos[1] = {61, 77, 0}
x020041_g_Boss9MonsterPos[2] = {61, 53, 0}
x020041_g_Boss9MonsterPos[3] = {48, 65, 0}
x020041_g_Boss9MonsterPos[4] = {73, 65, 0}
x020041_g_Boss9StunBuff = 10020
x020041_g_Boss9InvincibleBuff = 10019
x020041_g_Boss9DieBuff = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
x020041_g_Boss9State = 4
x020041_g_Boss9IsInvincible = 5
x020041_g_Boss9Shout = 1

x020041_g_Boss10Id = {}
x020041_g_Boss10Id[1] = {431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601,431601}
x020041_g_Boss10Id[2] = {431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701,431701}
x020041_g_Boss10Id[3] = {431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801,431801}
x020041_g_Boss10Id[4] = {431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901,431901}
x020041_g_Boss10FinalId = {431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101,431101}
x020041_g_Boss10Pos = {}
x020041_g_Boss10Pos[1] = {63, 65, 0}
x020041_g_Boss10Pos[2] = {59, 65, 0}
x020041_g_Boss10Pos[3] = {61, 63, 0}
x020041_g_Boss10Pos[4] = {61, 67, 0}
x020041_g_Boss10FinalPos = {61,65,0}
x020041_g_Boss10State = 4
x020041_g_Boss10CallStartTime= 5
x020041_g_Boss10CallDuration = 30
x020041_g_Boss10CallHp = 40
x020041_g_Boss10StunBuff = 10020
x020041_g_Boss10InvincibleBuff = 10019
x020041_g_Boss10AngryHP = 30
x020041_g_Boss10AngryDuration =480
x020041_g_Boss10AngryStartTime = 6
x020041_g_Boss10AngryImpact = 1

x020041_g_State = 0
x020041_g_IsReady = 1
x020041_g_ReadyStartTime = 2
x020041_g_IsEnterReady = 3
x020041_g_ReadyDuration = 5

x020018_g_AdapteLvl = 20

function x020041_OnCopySceneTick(scene, tickCount)
	x020041_TickReady(scene, tickCount)
	x020041_TickState(scene, tickCount)
end

function x020041_ResetCopyScene(scene, tickCount)
	SetCopySceneParam(scene, x020041_g_ReadyStartTime, tickCount)
	if tickCount == 0 then
		SetCopySceneParam(scene, x020041_g_State, 0)
		SetCopySceneParam(scene, x020041_g_ReadyStartTime, tickCount - x020041_g_ReadyDuration)
	end
	SetCopySceneParam(scene, x020041_g_IsReady, 1)
	SetCopySceneParam(scene, x020041_g_IsEnterReady, 0)
	for i=4, 9 do
		SetCopySceneParam(scene, i, 0)
	end
end

function x020041_TickReady(scene, tickCount)	
	if tickCount == 0 or GetCopySceneParam(scene, x020041_g_IsEnterReady) == 1 then
		x020041_ResetCopyScene(scene, tickCount)
	end

	local ready = GetCopySceneParam(scene, x020041_g_IsReady)
	local startTime = GetCopySceneParam(scene, x020041_g_ReadyStartTime)
	if ready == 1 then
		if startTime + x020041_g_ReadyDuration <= tickCount then
			SetCopySceneParam(scene, x020041_g_IsReady, 0)
	 		x020041_EnterNextState(scene, tickCount)
	 	end
	end
end

--Init

function x020041_EnterNextState(scene, tickCount)
	local state = GetCopySceneParam(scene, x020041_g_State) + 1
	SetCopySceneParam(scene, x020041_g_State, state)
	print(state)
	if state == 1 then
		x020041_InitState1(scene, tickCount)
	elseif state == 2 then
		x020041_InitState2(scene, tickCount)
	elseif state == 3 then
		x020041_InitState3(scene, tickCount)
	elseif state == 4 then
		x020041_InitState4(scene, tickCount)
	elseif state == 5 then
		x020041_InitState5(scene, tickCount)
	elseif state == 6 then
		x020041_InitState6(scene, tickCount)
	elseif state == 7 then
		x020041_InitState7(scene, tickCount)
	elseif state == 8 then
		x020041_InitState8(scene, tickCount)
	elseif state == 9 then
		x020041_InitState9(scene, tickCount)
	elseif state == 10 then
		x020041_InitState10(scene, tickCount)
	end
end

function x020041_InitState1(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss1Id)
	CreateMonster(scene, id, x020041_g_Boss1Pos[3], x020041_g_Boss1Pos[1], x020041_g_Boss1Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss1CallStartTime, tickCount)
end

function x020041_InitState2(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss2Id)
	CreateMonster(scene, id, x020041_g_Boss2Pos[3], x020041_g_Boss2Pos[1], x020041_g_Boss2Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss2CallStartTime, tickCount)
end

function x020041_InitState3(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss3Id)
	CreateMonster(scene, id, x020041_g_Boss3Pos[3], x020041_g_Boss3Pos[1], x020041_g_Boss3Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss3StartTime, tickCount)
end

function x020041_InitState4(scene, tickCount)
	for i=1,#x020041_g_Boss4Id do
		local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss4Id[i])
		CreateMonster(scene, id, x020041_g_Boss4Pos[i][3], x020041_g_Boss4Pos[i][1], x020041_g_Boss4Pos[i][2])
	end
	SetCopySceneParam(scene, x020041_g_Boss4StartTime, tickCount)
end

function x020041_InitState5(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss5Id)
	CreateMonster(scene, id, x020041_g_Boss5Pos[3], x020041_g_Boss5Pos[1], x020041_g_Boss5Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss5CallStartTime, tickCount)
	SetCopySceneParam(scene, x020041_g_Boss5MonsterHpImpactIndex, 1)
end

function x020041_InitState6(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss6Id)
	CreateMonster(scene, id, x020041_g_Boss6Pos[3], x020041_g_Boss6Pos[1], x020041_g_Boss6Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss6StartTime, tickCount)
end

function x020041_InitState7(scene, tickCount)
	for i=1,#x020041_g_Boss7Id do
		local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[i])
		CreateMonster(scene, id, x020041_g_Boss7Pos[i][3], x020041_g_Boss7Pos[i][1], x020041_g_Boss7Pos[i][2])
	end
	SetCopySceneParam(scene, x020041_g_Boss7State, 0)
end

function x020041_InitState8(scene, tickCount)
	for i=1,#x020041_g_Boss8MonsterPos do
		local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss8MonsterId)
		local objId = CreateMonster(scene, id, x020041_g_Boss8MonsterPos[i][3], x020041_g_Boss8MonsterPos[i][1], x020041_g_Boss8MonsterPos[i][2])
		CommandMoveTo(scene, objId, x020041_g_Boss8Pos[1], x020041_g_Boss8Pos[2])
		BroadCastBossCallTheRoll(scene, -1, x020041_g_Boss8Shout)
	end
end

function x020041_InitState9(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss9Id)
	CreateMonster(scene, id, x020041_g_Boss9Pos[3], x020041_g_Boss9Pos[1], x020041_g_Boss9Pos[2])
	SetCopySceneParam(scene, x020041_g_Boss9State, 0)
	SetCopySceneParam(scene, x020041_g_Boss9IsInvincible, 0)
end

function x020041_InitState10(scene, tickCount)
	for i=1,#x020041_g_Boss10Id do
		local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[i])	
		local objId = CreateMonster(scene, id, x020041_g_Boss10Pos[i][3], x020041_g_Boss10Pos[i][1], x020041_g_Boss10Pos[i][2])
		if i > 1 then
			SendImpactToUnit(scene, objId, x020041_g_Boss10StunBuff)
			SendImpactToUnit(scene, objId, x020041_g_Boss10InvincibleBuff)
		end
	end
	SetCopySceneParam(scene, x020041_g_Boss10State, 0)
end

--Tick
function x020041_TickState(scene, tickCount)
	local ready = GetCopySceneParam(scene, x020041_g_IsReady)
	if ready == 1 then
		return
	end

	local state = GetCopySceneParam(scene, x020041_g_State)
	if state == 1 then
		x020041_TickState1(scene, tickCount)
	elseif state == 2 then
		x020041_TickState2(scene, tickCount)
	elseif state == 3 then
		x020041_TickState3(scene, tickCount)
	elseif state == 4 then
		x020041_TickState4(scene, tickCount)
	elseif state == 5 then
		x020041_TickState5(scene, tickCount)
	elseif state == 6 then
		x020041_TickState6(scene, tickCount)
	elseif state == 7 then
		x020041_TickState7(scene, tickCount)
	elseif state == 8 then
		x020041_TickState8(scene, tickCount)
	elseif state == 9 then
		x020041_TickState9(scene, tickCount)
	elseif state == 10 then
		x020041_TickState10(scene, tickCount)
	end
end

function x020041_TickState1(scene, tickCount)
	local startTime = GetCopySceneParam(scene, x020041_g_Boss1CallStartTime)
	if startTime + x020041_g_Boss1CallDuration <= tickCount then
		local bassId = x020041_GetMonsterRoleBaseId(x020041_g_Boss1Id)
		ProcessSkillRequestRBID(scene, bassId, bassId, x020041_g_Boss1CallSkill)
		BroadCastBossTips(scene, x020041_g_Boss1FakeObjId, x020041_g_Boss1Shout, bassId)
		SetCopySceneParam(scene, x020041_g_Boss1CallStartTime, tickCount)

		local monsterId = x020041_GetMonsterRoleBaseId(x020041_g_Monster1Id)
		for i=1, #x020041_g_Monster1IdPos do
			CreateMonster(scene, monsterId, x020041_g_Monster1IdPos[i][3], x020041_g_Monster1IdPos[i][1], x020041_g_Monster1IdPos[i][2])
		end
	end
end

function x020041_TickState2(scene, tickCount)
	local startTime = GetCopySceneParam(scene, x020041_g_Boss2CallStartTime)
	if startTime + x020041_g_Boss2CallDuration <= tickCount then
		local bassId = x020041_GetMonsterRoleBaseId(x020041_g_Boss2Id)
		ProcessSkillRequestRBID(scene, bassId, bassId, x020041_g_Boss2CallSkill)
		BroadCastBossTips(scene, x020041_g_Boss2FakeObjId, x020041_g_Boss2Shout, bassId)
		SetCopySceneParam(scene, x020041_g_Boss2CallStartTime, tickCount)

		local monsterId1 = x020041_GetMonsterRoleBaseId(x020041_g_Monster2Id1)
		for i=1, #x020041_g_Monster2Id1Pos do
			CreateMonster(scene, monsterId1, x020041_g_Monster2Id1Pos[i][3], x020041_g_Monster2Id1Pos[i][1], x020041_g_Monster2Id1Pos[i][2])
		end		
		local monsterId2 = x020041_GetMonsterRoleBaseId(x020041_g_Monster2Id2)
		for i=1, #x020041_g_Monster2Id2Pos do
			CreateMonster(scene, monsterId2, x020041_g_Monster2Id2Pos[i][3], x020041_g_Monster2Id2Pos[i][1], x020041_g_Monster2Id2Pos[i][2])
		end
	end
end

function x020041_TickState3(scene, tickCount)
	local bossState = GetCopySceneParam(scene, x020041_g_Boss3State)
	if bossState == 0 then
		local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss3Id)
		local startTime = GetCopySceneParam(scene, x020041_g_Boss3StartTime)
		if CalculatePercenHpByRBId(scene, id) < 30 or startTime + x020041_g_Boss3Duration <= tickCount then
			SendImpactToAllByRBID(scene, id, x020041_g_Boss3Impact)
			BroadCastBossTips(scene, x020041_g_Boss3FakeObjId, x020041_g_Boss3Shout, id)
			SetCopySceneParam(scene, x020041_g_Boss3State, 1)
		end
	end
end

function x020041_TickState4(scene, tickCount)
	local startTime = GetCopySceneParam(scene, x020041_g_Boss4StartTime)
	if startTime + x020041_g_Boss4Duration >= tickCount then
		local count = GetSceneUserCount(scene)
		local index	= RandomMon(0, count)
		local objId = GetUserObjIdByIdx(scene, index)
		local bossId = x020041_GetMonsterRoleBaseId(x020041_g_Boss4Id[2])
		SendImpactToObjByRBID(scene, bossId, objId, x020041_g_Boss4Impact)
		BroadCastBossCallTheRoll(scene, -1, x020041_g_Boss4Shout)
		SetCopySceneParam(scene, x020041_g_Boss4StartTime, tickCount)
	end
end

function x020041_TickState5(scene, tickCount)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss5Id)

	local state = GetCopySceneParam(scene, x020041_g_Boss5State)
	if state == 0 then
		if CalculatePercenHpByRBId(scene, id) < 30 then
			SendImpactToAllByRBID(scene, id, x020041_g_Boss5Impact)
			SetCopySceneParam(scene, x020041_g_Boss5State, 1)
		end
	end

	local startTime = GetCopySceneParam(scene, x020041_g_Boss5CallStartTime)
	if startTime + x020041_g_Boss5CallDuration <= tickCount then
		ProcessSkillRequestRBID(scene, id, id, x020041_g_Boss5CallSkill)
		BroadCastBossTips(scene, x020041_g_Boss5FakeObjId, x020041_g_Boss5Shout, id)
		SetCopySceneParam(scene, x020041_g_Boss5CallStartTime, tickCount)
		local objId = CreateMonster(scene, x020041_GetMonsterRoleBaseId(x020041_g_Monster5Id), x020041_g_Monster5Pos[3], x020041_g_Monster5Pos[1], x020041_g_Monster5Pos[2])
		local index = GetCopySceneParam(scene, x020041_g_Boss5MonsterHpImpactIndex)
		SendImpactToUnit(scene, objId, x020041_g_Boss5MonsterHpImpact[index])
		SetHpFull(scene, objId)
		if index < #x020041_g_Boss5MonsterHpImpact  then
			SetCopySceneParam(scene, x020041_g_Boss5MonsterHpImpactIndex, index + 1)
		end
	end
end

function x020041_TickState6(scene, tickCount)
	local startTime = GetCopySceneParam(scene, x020041_g_Boss6StartTime)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss6Id)
	if startTime + x020041_g_Boss6Duration <= tickCount then
		local count = GetSceneUserCount(scene)
		local index	= RandomMon(0, count)
		local objId = GetUserObjIdByIdx(scene, index)
		ProcessSkillRequestRBID(scene, id, objId, x020041_g_Boss6LineSkill)
		objId = GetObjIdByRoleBase(scene, id)
		BroadCastBossCallTheRoll(scene, objId, x020041_g_Boss6Shout)
		SetCopySceneParam(scene, x020041_g_Boss6StartTime, tickCount)
	end
end

function x020041_TickState7(scene, tickCount)
end

function x020041_TickState8(scene, tickCount)
	local state = GetCopySceneParam(scene, x020041_g_Boss8State)
	local monsterId = x020041_GetMonsterRoleBaseId(x020041_g_Boss8MonsterId)
	if state == 0 then
		local count = GetAliveByRoleBaseNum(scene, monsterId)
	 	if count <= 0 then
			local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss8Id[GetCopySceneParam(scene, x020041_g_Boss8MonsterCount)])
			CreateMonster(scene, id , x020041_g_Boss8Pos[3], x020041_g_Boss8Pos[1], x020041_g_Boss8Pos[2])
			SetCopySceneParam(scene, x020041_g_Boss8State, 1)
		else
			local old = GetCopySceneParam(scene, x020041_g_Boss8MonsterCount)
			local rangeCount = GetMonCountInRange(scene, monsterId, x020041_g_Boss8Pos[1], x020041_g_Boss8Pos[2], 1)
			SetCopySceneParam(scene, x020041_g_Boss8MonsterCount, old + rangeCount)
		end
	end
end

function x020041_TickState9(scene, tickCount)
	local state = GetCopySceneParam(scene, x020041_g_Boss9State)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss9Id)		
	local monsterId = x020041_GetMonsterRoleBaseId(x020041_g_Boss9CallMonsterId)
	local inVin = GetCopySceneParam(scene, x020041_g_Boss9IsInvincible)
	if inVin == 0 then
		if (state == 0 and CalculatePercenHpByRBId(scene, id) < 80) or (state == 1 and CalculatePercenHpByRBId(scene, id) < 50) or (state == 2 and CalculatePercenHpByRBId(scene, id) < 30) then
			for i=1, #x020041_g_Boss9MonsterPos do
				local objId = CreateMonster(scene, monsterId, x020041_g_Boss9MonsterPos[i][3], x020041_g_Boss9MonsterPos[i][1], x020041_g_Boss9MonsterPos[i][2])
				local pos = GetObjPositionByRBID(scene, id)
				CommandMoveTo(scene, objId, pos[0], pos[1])
			end
			SendImpactToUnitByRBID(scene, id, x020041_g_Boss9InvincibleBuff)
			SendImpactToUnitByRBID(scene, id, x020041_g_Boss9StunBuff)
			local bossObjId = GetObjIdByRoleBase(scene, id)
			BroadCastBossCallTheRoll(scene, bossObjId, x020041_g_Boss9Shout)
			SetCopySceneParam(scene, x020041_g_Boss9IsInvincible, 1)
		end
	else
		local pos = GetObjPositionByRBID(scene, id)
		local count = GetMonCountInRange(scene, monsterId, pos[0], pos[1], 1)
		for i=1, count do
			SendImpactToUnitByRBID(scene, id, x020041_GetMonsterRoleBaseId(x020041_g_Boss9DieBuff))
		end

		if GetAliveByRoleBaseNum(scene, monsterId) <= 0 then
			SetCopySceneParam(scene, x020041_g_Boss9State, state + 1)
			RemoveImpactByBRId(scene, id, x020041_g_Boss9InvincibleBuff)
			RemoveImpactByBRId(scene, id, x020041_g_Boss9StunBuff)
			SetCopySceneParam(scene, x020041_g_Boss9IsInvincible, 0)
		end

	end
end

function x020041_TickState10(scene, tickCount)
	local state = GetCopySceneParam(scene, x020041_g_Boss10State)
	local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss10FinalId)
	if state == 4 then
		CreateMonster(scene, id, x020041_g_Boss10FinalPos[3], x020041_g_Boss10FinalPos[1], x020041_g_Boss10FinalPos[2])
		SetCopySceneParam(scene, x020041_g_Boss10CallStartTime, tickCount)
		SetCopySceneParam(scene, x020041_g_Boss10AngryStartTime, tickCount)
		SetCopySceneParam(scene, x020041_g_Boss10State, 5)
	elseif state >= 5 then
		local startTime = GetCopySceneParam(scene, x020041_g_Boss10CallStartTime)
		if startTime + x020041_g_Boss10CallDuration < tickCount then
			local index = RandomMon(1, 5)
			CreateMonster(scene, x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[index]), x020041_g_Boss10Pos[index][3], x020041_g_Boss10Pos[index][1], x020041_g_Boss10Pos[index][2])
			SetCopySceneParam(scene, x020041_g_Boss10CallStartTime, tickCount)
		end

		if state == 5 then
			if CalculatePercenHpByRBId(scene, id) < x020041_g_Boss10AngryHP or GetCopySceneParam(scene, x020041_g_Boss10AngryStartTime) + x020041_g_Boss10AngryDuration <= tickCount then
				SendImpactToUnitByRBID(scene, id, x020041_g_Boss10AngryImpact)
				SetCopySceneParam(scene, x020041_g_Boss10State, 4)
			end
		end
	end
end

function x020041_OnObjDie(scene, objId, roleBaseId, killerId)
	if roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss1Id) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss2Id) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss3Id) then
		SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss4Id[1]) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss4Id[2]) then	
		local state = GetCopySceneParam(scene, x020041_g_Boss4State)
		if state == 0 then
			SetCopySceneParam(scene, x020041_g_Boss4State, 1)
		elseif state == 1 then
			SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss5Id) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss6Id) then
		SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[1]) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[2]) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[3]) or roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[4]) then
		local state = GetCopySceneParam(scene, x020041_g_Boss7State)
		if state >= 3 then
			SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
		else
			SetCopySceneParam(scene, x020041_g_Boss7State, state + 1)
			for i=1,#x020041_g_Boss7Id do
				local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss7Id[i])
				if CalculatePercenHpByRBId(scene, id) > 0 then
					SendImpactToAllByRBID(scene, id, x020041_g_Boss7DieImpact)
				end
			end
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss8Id[GetCopySceneParam(scene, x020041_g_Boss8MonsterCount)]) then
		SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss9Id) then
		SetCopySceneParam(scene, x020041_g_IsEnterReady, 1)
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[1]) then
		if GetCopySceneParam(scene, x020041_g_Boss10State) == 0 then
			local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[2])
			RemoveImpactByBRId(scene, id, x020041_g_Boss10StunBuff)
			RemoveImpactByBRId(scene, id, x020041_g_Boss10InvincibleBuff)
			SetCopySceneParam(scene, x020041_g_Boss10State, 1)
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[2]) then
		if GetCopySceneParam(scene, x020041_g_Boss10State) == 1 then
			local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[3])
			RemoveImpactByBRId(scene, id, x020041_g_Boss10StunBuff)
			RemoveImpactByBRId(scene, id, x020041_g_Boss10InvincibleBuff)
			SetCopySceneParam(scene, x020041_g_Boss10State, 2)
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[3]) then
		if GetCopySceneParam(scene, x020041_g_Boss10State) == 2 then
			local id = x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[4])
			RemoveImpactByBRId(scene, id, x020041_g_Boss10StunBuff)
			RemoveImpactByBRId(scene, id, x020041_g_Boss10InvincibleBuff)
			SetCopySceneParam(scene, x020041_g_Boss10State, 3)
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss10Id[4]) then
		if GetCopySceneParam(scene, x020041_g_Boss10State) == 3 then
			SetCopySceneParam(scene, x020041_g_Boss10State, 4)
		end
	elseif roleBaseId == x020041_GetMonsterRoleBaseId(x020041_g_Boss10FinalId) then
		x020041_EndCopyScene(scene)
	end
end

function x020041_EndCopyScene(scene)
	AccoutByCopyScene(scene)
	SetCopySceneSuccess(scene)
end

function x020041_GetMonsterRoleBaseId(role)
	local adapt = math.ceil(GetAdaptLvl(scene)/5)
	if adapt > x020018_g_AdapteLvl then
		adapt = GetAdaptLvl
	end

	return role[adapt]
end