wx020048_g_scriptId = 020048

x020048_g_AdapteLvl = 60  --   每个怪物的自适应等级套数  必须随适应等级的变化而改变
--以上为波次刷怪的波次适应等级  编号1代表第一波怪的自适应等级    编号1里第一个中括号表示第一波第一个怪物的自适应等级套数  依次类推

x020048_g_YuansuId = {}
x020048_g_YuansuId[1] = { 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031, 7031 } -- 第一种怪物的Id
x020048_g_YuansuId[2] = { 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032, 7032 } -- 第二种怪物的Id
x020048_g_ZHCD = 20
x020048_g_ZHHp = 99    -- 触发血量
x020048_g_YuansuIdCs = 482000    -- 召唤物初始ID

x020048_g_YuansuPosList = {}
x020048_g_YuansuPosList[1] = { { 40.9, 42.78, -1.22 } }          -- 坐标控制数量，多少个坐标一次刷多少个  第一波的第一种怪物坐标
x020048_g_YuansuPosList[2] = { { 51.77, 44.31, 4.6 } }        --第一波的第2种


x020048_g_TotalTargetNum = {}    --  通关击杀总分数
x020048_g_TotalTargetNum[1] = { 1, 2 } -- 通关需要达到的怪物击杀数量  第一个1表示一个boss  第二个2表示2个小弟

x020048_g_YuansuBuffId = {}
x020048_g_YuansuBuffId[1] = { -1, -1, -1, -1, -1, -1 }

x020048_g_BossId = {}
x020048_g_BossId[1] = { 481000, 481010, 481020, 481030, 481040, 481050, 481060, 481070, 481080, 481090, 481100, 481110, 481120, 481130, 481140, 481150, 481160, 481170, 481180, 481190, 481200, 481210, 481220, 481230, 481240, 481250, 481260, 481270, 481280, 481290, 481300, 481310, 481320, 481330, 481340, 481350, 481360, 481370, 481380, 481390, 481400, 481410, 481420, 481430, 481440, 481450, 481460, 481470, 481480, 481490, 481500, 481510, 481520, 481530, 481540, 481550, 481560, 481570, 481580, 481590 }    -- Boss编号   表示Boss的自适应等级套数
x020048_g_BossPosList = {}
x020048_g_BossPosList[1] = { { 47, 38, -1.57 } }    --  Boss 坐标

x020048_g_TpPosList = {}
x020048_g_TpPosList[1] = { { 40.9, 42.78, -1.22 }, { 51.77, 44.31, 3.21 } }
x020048_g_CSParamIdxCurStage = 0                     -- 场景切换波数
x020048_g_CSParamIdxCurSubStage = 1                   -- 同一场景中的时间点
x020048_g_CSParamIdxrandtime = 2                       -- 记录击杀了boss
x020048_g_Movparm = 20

x020048_g_OldTick = 5                       -- 记录击杀了boss
function x020048_OnObjEnter(scene, objId)
    --CopySceneNPC(scene,1001101,51001,6,202,1,"XXX")--场景、角色ID、CharModel表ID、势力、出现的场景SceneID、等级、名称
    SynCsStageData(scene, objId, true)
    --AutoCombat(scene,objId,true)
end
function x020048_OnCopySceneOpen(scene, objId)
    --SynCsStageData(scene, objId, true)
    --AutoCombat(scene,objId,true)
    StoryAnimation(scene, 2202)
end

function x020048_OnCopySceneTick(scene, tickCount)
    --副本阶段

    if tickCount == 0 then
        CaluCSRound(scene)

    end
    local curStage = GetCopySceneParam(scene, x020048_g_CSParamIdxCurStage)
    local curSubStage = GetCopySceneParam(scene, x020048_g_CSParamIdxCurSubStage) + 1
    SetCopySceneParam(scene, x020048_g_CSParamIdxCurSubStage, curSubStage)
    if GetCopySceneStatus(scene) == 4 and curStage == 1 then
        curStage = 3
        x020048_ClearAllMonster(scene)
        SetCopySceneParam(scene, x020048_g_CSParamIdxCurStage, 3)
        ShowSJCSEnd(scene, false)
    end
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020048_g_AdapteLvl then
        nAdaptedLvl = x020048_g_AdapteLvl
    end
    if (tickCount == 20) then
        ChangeAllMonsterCamp(scene, 3)
    end
    if tickCount == 0 then
        SetSceneBuff(scene, 4702, x020048_g_TpPosList[1][1][1], x020048_g_TpPosList[1][1][2], 0)
        SetSceneBuff(scene, 4702, x020048_g_TpPosList[1][2][1], x020048_g_TpPosList[1][2][2], 0)
    end
    local ZhobjId1 = GetObjIdByRoleBase(scene, x020048_g_BossId[1][nAdaptedLvl])
    local Hp = CalculatePercenHp(scene, ZhobjId1)
    local OldTick = GetCopySceneParam(scene, x020048_g_OldTick)
    if Hp < x020048_g_ZHHp and Hp ~= -1 and OldTick == 0 then
        SetCopySceneParam(scene, x020048_g_OldTick, tickCount)
        --print("達到目標血量")
    end


    --if(not MonIsBattle(scene, x020050_g_YuansuId[2][nAdaptedLvl]) and CalculatePercenHp(scene, ZhobjId2) == 100) then
    local NewTick = GetCopySceneParam(scene, x020048_g_OldTick)
    if NewTick > 0 and tickCount >= NewTick then

        if (CalculatePercenHp(scene, ZhobjId1) > 0 and (tickCount - NewTick) % x020048_g_ZHCD == 0) then
            --print("召喚怪物了")
            --	print(x020048_g_YuansuIdCs + nAdaptedLvl)
            CreateMonster(scene, x020048_g_YuansuIdCs + (nAdaptedLvl * 10), x020048_g_TpPosList[1][1][3], x020048_g_TpPosList[1][1][1], x020048_g_TpPosList[1][1][2])
            CreateMonster(scene, x020048_g_YuansuIdCs + (nAdaptedLvl * 10), x020048_g_TpPosList[1][2][3], x020048_g_TpPosList[1][2][1], x020048_g_TpPosList[1][2][2])
        end
    end
    if curStage == 0 then
        x020048_Stage_0(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 1 then
        x020048_Stage_1(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 2 then
        x020048_Stage_2(scene, curStage, curSubStage)
    end
end
function x020048_Stage_0(scene, stage, substage, nlv)
    --	print(x020048_g_Movparm)
    --	print((substage == x020048_g_MovCdTime and GetCopySceneParam(scene,13) == 0))
    if ((substage == x020048_g_Movparm and GetCopySceneParam(scene, 13) == 0) or GetCopySceneParam(scene, 13) == 1) then
        SetCopySceneParam(scene, 13, 2)
        local nCurStage = GetCopySceneParam(scene, x020048_g_CSParamIdxCurStage)
        SetCopySceneParam(scene, x020048_g_CSParamIdxCurStage, 1)
        SetCopySceneParam(scene, x020048_g_CSParamIdxCurSubStage, 0)
    end
end

function x020048_OnStoryEventEnd(scene, nStoryId, nAnimationId)
    local OldValue = GetCopySceneParam(scene, 13)
    --print("播放完MOV")
    --print(OldValue)
    if OldValue == 0 then

        SetCopySceneParam(scene, 13, 1)
    end
end
function x020048_ClearAllMonster(scene)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020048_g_AdapteLvl then
        nAdaptedLvl = x020048_g_AdapteLvl
    end
    --  for i = 1, 2 do
    --	DeleMonsterByRoleId(scene, x020048_g_YuansuId[i][nAdaptedLvl])
    -- end
    DeleMonsterByRoleId(scene, x020048_g_BossId[1][nAdaptedLvl])

end
function x020048_CreateYuansuBuff(scene, idx, nlv)
    SendImpactToAllByRBID(scene, x020048_g_YuansuId[idx][nlv], x020048_g_YuansuBuffId[1][idx])
end
function x020048_Stage_2(scene, curStage, curSubStage)
    -- body
    -- body
    local nCurStage = GetCopySceneParam(scene, x020048_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020048_g_CSParamIdxCurStage, nCurStage + 1)
    SetCopySceneParam(scene, x020048_g_CSParamIdxCurSubStage, 0)
    ShowSJCSEnd(scene, true)
    x020048_Success(scene)
end
function x020048_Success(scene)
    AccoutByCopyScene(scene)
    local nUserCount = GetSceneUserCount(scene)
    for i = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, i)
        --	AwardCSItemBox(scene,nUserObjId,x020048_g_IdCSxiayiBox, x020048_g_IdCSItemBox)
    end
    SetCopySceneSuccess(scene)
end

function x020048_OnObjDie(scene, objId, rolebaseId, killerId)
    local MonCount = GetHostileMonsterCount(scene)
    local nCurStage = GetCopySceneParam(scene, x020048_g_CSParamIdxCurStage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020048_g_AdapteLvl then
        nAdaptedLvl = x020048_g_AdapteLvl
    end
    x020048_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
    --local OldValue = GetCopySceneParam(scene, x020048_g_CSParamIdxrandtime)
    --local OldValue2 = GetCopySceneParam(scene, x020048_g_CSParamIdxrandtime2)
    if rolebaseId == x020048_g_BossId[1][nAdaptedLvl] and nCurStage < 3 then

        SetCopySceneParam(scene, x020048_g_CSParamIdxCurStage, 2)
        SetCopySceneParam(scene, x020048_g_CSParamIdxCurSubStage, 0)
    end
end
function x020048_OnDieCountDown1(scene, rolebaseId, nlv)
    local TargetId = x020048_g_BossId[1][nlv]
    if (TargetId == rolebaseId) then
        local OldValue = GetCopySceneParam(scene, x020048_g_CSParamIdxrandtime)
        SetCopySceneParam(scene, x020048_g_CSParamIdxrandtime, OldValue + 1)

        local nUserCount = GetSceneUserCount(scene)
        for i = 0, nUserCount - 1 do
            local nUserObjId = GetUserObjIdByIdx(scene, i)
            SynCsStageData(scene, nUserObjId)
        end
    end
end
function x020048_OnDieCountDown2(scene, rolebaseId, nlv)
    for i = 1, 2 do
        local TargetId = x020048_g_YuansuId[i][nlv]
        if (TargetId == rolebaseId) then
            local OldValue = GetCopySceneParam(scene, x020048_g_CSParamIdxrandtime2)
            SetCopySceneParam(scene, x020048_g_CSParamIdxrandtime2, OldValue + 1)

            local nUserCount = GetSceneUserCount(scene)
            for j = 0, nUserCount - 1 do
                local nUserObjId = GetUserObjIdByIdx(scene, j)
                SynCsStageData(scene, nUserObjId)
            end
            print(OldValue)
            break
        end

    end
end

function x020048_CreateMonster(scene, idx, camp, nlv)
    --if substage == 1 then				--刷怪（
    --	print("CreateMonster")
    --	for i = 1, 3 do
    --		local index = (idx-1)*3 + i
    --		local count = #x020048_g_YuansuPosList[i]
    --		for j = 1, count  do
    --			CreateMonster(scene,  x020048_g_YuansuId[i][nlv], x020048_g_YuansuPosList[i][j][3], x020048_g_YuansuPosList[i][j][1],x020048_g_YuansuPosList[i][j][2])
    --		end
    --	end
    --end
    local count = #x020048_g_YuansuPosList[idx]
    for i = 1, count do
        CreateMonster(scene, x020048_g_YuansuId[idx][nlv], x020048_g_YuansuPosList[idx][i][3], x020048_g_YuansuPosList[idx][i][1], x020048_g_YuansuPosList[idx][i][2])
    end
end

function x020048_Stage_1(scene, stage, substage, nlv)
    if substage == 1 then
        local nUserCount = GetSceneUserCount(scene)
        for i = 0, nUserCount - 1 do
            local nUserObjId = GetUserObjIdByIdx(scene, i)
            AutoCombat(scene, nUserObjId, true)
        end
        local objId = CreateMonster(scene, x020048_g_BossId[1][nlv], x020048_g_BossPosList[1][1][3], x020048_g_BossPosList[1][1][1], x020048_g_BossPosList[1][1][2])
        --	SetNpcCampByObjId(scene,objId,1)
        --	for i = 1, 2 do
        --		x020048_CreateMonster(scene, i, 3, nlv)
        --	end
    end
end
