require("Necessary")
require("StoryUtility")

function initNPCDia()
	gValue.npcDia = {}
	--gValue.npcCount = 0
end

--第一期剧情DLC开始函数
function DLCStory1Begin()
	task()
		.log("DLCStory1Begin")
		.initNPCDia()
		.SetStoryVersion(1)
		.InitTourCamera()
		.taskDoPostScreen(1, 1.0, 0)
		.stopMusic(1.5, false)
		.joinTeam(106, false)
		.setRoleLevel(106, 30)
		.addObject(21507, 1, 0)
		.addObject(21609, 1, 0)
		.addObject(21811, 1, 0)
		.addObject(22103, 1, 0)
		.addObject(22303, 1, 0)
		.addObject(22310, 1, 0)
		.addObject(1002, 10, 0)
		.addObject(1006, 5, 0)
		.equip(106, 21507)
		.equip(106, 21609)
		.equip(106, 21811)
		.equip(106, 22103)
		.setRoleInt(106, "CurrentAP", 0)
		.setRoleInt(106, "CurrentActPoint", 3)
		.addSkill(106, 1153)
		.addSkill(106, 1154)
		.addSkill(106, 1155)
		.addSkill(106, 2301)
		.addSkill(106, 2302)
		.addSkill(106, 2303)
		.addSkill(106, 2304)
		.addSkill(106, 3501)
		.addSkill(106, 3502)
		.addSkill(106, 3503)
		.SetDLC1Story(200000)		--初始化剧情变量
		.changeScene("Q13", "Q13N02DLC1", "null", "")	--跳转场景
end

function OnDLCEnterLevelQ13()
	callTaskFunction("dlcstory200000")
end


function OnDLCEnterLevelQ07()
	setMiniMap("MQ007")
	
	callTaskFunction("dlcstory200100")
	
	if GetDLC1Story() == 300200 or GetDLC1Story() == 200401 then
		playMusic("P13.ogg",1,3,0,1,3)
	else
		playMusic("P31.ogg",1,3,0,1,3)
	end
end

function dlcstory200000()
	if GetDLC1Story() == 200000 then
		task()
		.playMusic("P105.ogg",1,3,0,1,3)--红玉·剑舞红袖·变调
		.taskPlaySequence("200000","Q13DLC1")
		.playSWF("Dlc001_1.swf")
		.taskPlaySequence("200001","Q13DLC1")
		.stopSWF()
		.taskDoPostScreen(1, 0, 1)
		.addEffort(420, 1)
		.SetDLC1Story( 200100 )
		--.SetTourCamera( 1 , true )
		.changeScene("Q07","Q07D","null","")
		.taskDoPostScreen( 1 , 1.0 , 1)
	end
end

function dlcstory200100()
	if GetDLC1Story() == 200100 then
		task()
		.taskPlaySequence("200100","Q07DLC1")
		.SetDLC1Story( 200200 )
		.playMusic("P31.ogg",1,3,0,1,3)
		.SetTourCamera( 1 , true )
		.setPlayerPos(-16.28428, 72.70964, 0.07415811)
		.setPlayerDir(180)
		.taskDoPostScreen(1 , 1.0 , 1)
		.setHUD(true)
		.setControl(true)
	end
end

function dlcstory200200()
	if GetDLC1Story() == 200200 then
		task()
		--沿用场景音乐
		.changeScene("Q07","Q07N14DLC1","null","")
		.taskPlaySequence("200200","Q07DLC1")
		.SetDLC1Story( 200201 )
		.changeScene("Q07","Q07D","null","")
		.taskPlaySequence("200201","Q07DLC1")
		.SetDLC1Story( 200300 )
		.SetTourCamera( 1 , true )
		.setPlayerPos(55.9051, -40.23005, -0.01503628)
		.setPlayerDir(180)
		.taskDoPostScreen(1 , 1.0 , 1)
		.setHUD(true)
		.setControl(true)
	end
end

function dlcstory200300()
	if GetDLC1Story() == 200300 then
		task()
		.playMusic("P32.ogg",1,3,0,1,3)
		.taskPlaySequence("200300","Q07DLC1")
		.SetDLC1Story( 200400 )
		.changeScene("Q07","Q07N25DLC1","null","")
		.playMusic("P13.ogg",1,3,0,1,3)    --剧情音乐P13，夜景场景音乐
		.taskPlaySequence("200400","Q07DLC1")
		.addObject(21519, 1, 0)
		.equip(106, 21519)
		.showWeapon(106, false)
		.SetDLC1Story( 200401 )
		.changeScene("Q07","Q07M","null","")
		.taskPlaySequence("200401","Q07DLC1")
		.setPlayerPos(55.9051, -40.23005, -0.01503628)
		.setPlayerDir(180)
		--.SetTourCamera(1 , true)
		.taskDoPostScreen(1 , 1.0 , 1)
		.SetDLC1Story( 300200 )
		.setHUD(true)
		.setControl(true)
	end
end


function dlcstory300200()
	if GetDLC1Story() == 300200 then
		task()
		.playMusic("P09.ogg",1,3,0,1,3) --剧情音乐
		.taskPlaySequence("300200","Q07DLC1")
        .SetDLC1Story( 300201 )
        .enterBattle("Q07", "Q07M", "Q07_1", 15)--接红玉与紫胤战斗
        .taskDoPostScreen( 1 , 0 , 1)
	end
end

function dlcstory300201()        --接战斗结束
	if GetDLC1Story() == 300201 then
		task()
		.playMusic("P09.ogg",1,3,0,1,3)
		.taskPlaySequence("300201","Q07DLC1")
		.SetDLC1Story( 300202 )
		.joinTeam(113, false)
		.addSkill(113, 6005)
		.addSkill(113, 6006)
		.addSkill(113, 6007)
		.addSkill(113, 6008)
		.setRoleInt(113, "CurrentAP", 121)
		.enterBattle("Q07", "Q07M", "Q07_1", 16)        --接镜罔Boss战
		.taskDoPostScreen( 1 , 0 , 1)
	end
end

function dlcstory300202() --接战斗结束
	if GetDLC1Story() == 300202 then
		task()
		.leaveTeam(113,false)
		.playMusic("P09.ogg",1,3,0,1,3)          --剧情音乐
		.taskPlaySequence("300202","Q07DLC1")
		.SetDLC1Story( 300300 )
		.playMusic("P86.ogg",1,3,0,1,3)       --P86
		.taskPlaySequence("300300","Q07DLC1")
		.SetDLC1Story( 400100 )
		.changeScene("Q07","Q07D","null","")
        .taskPlaySequence("400100","Q07DLC1")--音乐在fxf中，p104
        .playSWF("Dlc001_2.swf")
        .taskPlaySequence("400101","Q07DLC1")
        .stopSWF()
        .addEffort(421, 1)
        .saveEffort()
        .taskDoPostScreen(1, 0, 1)
		.endGame(false)
	end
end

function OnDLCBackQ07()
	if GetDLC1Story() == 300201 then
		dlcstory300201()
	elseif GetDLC1Story() == 300202 then
		dlcstory300202()
	elseif GetDLC1Story() == 300200 then
		playMusic("P13.ogg",1,3,0,1,3)
	end
end

function DLCEnterM071(cfgID)
	log(cfgID)
	if cfgID == 16 then
		--joinTeam(113,false)
	end
end

function DLCLeaveM071(cfgID, result)
	log(cfgID)
	log(result)
	if cfgID == 16 then
		--leaveTeam(113,false)
	elseif cfgID == 11 and result == 2 then
		addEffort(418, 1)
	end
	
	if result == 2 then
		addEffort(419, 1)
	end
end

function dlcDialogQ07(npcName)
	npcDialogue(npcName)
	log(gValue.npcDia)
	log(#gValue.npcDia)
	for i = 1, #gValue.npcDia do
		if gValue.npcDia[i] == npcName then
			log(npcName)
			return
		end
	end
	addEffort(422, 1)
	gValue.npcDia[#gValue.npcDia+1] = npcName
	log(#gValue.npcDia)
end
