--2.1.2偃师冰峰
x020088_g_scriptId = 020088

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

x020088_g_RoleBaseId = {}
x020088_g_RoleBaseId[1] = { 463000 }    -- 3个回春神龛的自适应等级套数
x020088_g_RoleBaseId[2] = { 461000, 461000, 461000, 462000 }

x020088_g_RoleBaseId2 = {}
x020088_g_RoleBaseId2[1] = { 463000, 463000 }    -- 3个回春神龛的自适应等级套数
x020088_g_RoleBaseId2[2] = { 461000, 461000, 461000, 462000, 461000, 461000, 461000, 462000 }

x020088_g_RoleBasePosList = {}
x020088_g_RoleBasePosList[1] = { { 60.99, 47.76, 1.57 } }    --  回春神龛 坐标
x020088_g_RoleBasePosList[2] = { { 61.71, 50.78, -1.57 }, { 63.89, 47.51, -1.81 }, { 57.91, 48.43, -2.08 }, { 60.45, 45.14, -2.07 } }

x020088_g_RoleBasePosList2 = {}
x020088_g_RoleBasePosList2[1] = { { 51.69, 66.04, 1.57 }, { 72.02, 65.04, 1.57 } }    --  回春神龛 坐标
x020088_g_RoleBasePosList2[2] = { { 52.19, 69.42, -1.57 }, { 53.89, 64.63, -1.72 }, { 49.53, 64.42, -1.18 }, { 48.84, 67.43, -1.4 }, { 69.81, 67.83, -1.22 }, { 74.1, 64.33, -1.76 }, { 74.6, 67.24, -1.99 }, { 70.11, 64.25, -1.92 } }

x020088_g_Movparm = 10

x020088_g_CSParamIdxCurStage = 0                     -- 场景切换波数
x020088_g_CSParamIdxCurSubStage = 1                   -- 同一场景中的时间点
x020088_g_CSParamIdxrandtime = 2                       -- 记录击杀了几个第一只怪

x020088_g_TargetList = {}                      --目标
x020088_g_TargetList[1] = { { 463000, 462000, 461000 } }  --{{第1阶段目标},{第1阶段目标2}}

--3个回春神龛 特效 BUff
x020088_g_BuffId = 75303

--死亡impact
x020088_g_DieImpact = 77001

function x020088_OnObjEnter(scene, objId)
    SynCsStageData(scene, objId, true)
    TestFullHp(scene,objId)
end

function x020088_OnCopySceneOpen(scene, objId)
    StoryAnimation(scene, 2205)
end

function x020088_OnCopySceneTick(scene, tickCount)
    if tickCount == 0 then
        CaluCSRound(scene)
    end
    local curStage = GetCopySceneParam(scene, x020088_g_CSParamIdxCurStage)
    local curSubStage = GetCopySceneParam(scene, x020088_g_CSParamIdxCurSubStage) + 1
    SetCopySceneParam(scene, x020088_g_CSParamIdxCurSubStage, curSubStage)
    if GetCopySceneStatus(scene) == 4 and curStage == 1 then
        curStage = 3
        x020088_ClearAllMonster(scene)
        SetCopySceneParam(scene, x020088_g_CSParamIdxCurStage, 3)
        ShowSJCSEnd(scene, false)
    end
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020088_g_AdapteLvl then
        nAdaptedLvl = x020088_g_AdapteLvl
    end
    if (tickCount == 20) then
        ChangeAllMonsterCamp(scene, 3)
    end
    if curStage == 0 then
        x020088_Stage_0(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 1 then
        x020088_Stage_1(scene, curStage, curSubStage, nAdaptedLvl - 1)
    elseif curStage == 2 then
        x020088_Stage_2(scene, curStage, curSubStage)
    end
end

function x020088_Stage_0(scene, stage, substage, nlv)
    if ((substage == x020088_g_Movparm and GetCopySceneParam(scene, 13) == 0) or GetCopySceneParam(scene, 13) == 1) then
        SetCopySceneParam(scene, 13, 2)
        SetCopySceneParam(scene, x020088_g_CSParamIdxCurStage, 1)
        SetCopySceneParam(scene, x020088_g_CSParamIdxCurSubStage, 0)
    end
end

function x020088_OnStoryEventEnd(scene, nStoryId, nAnimwaationId)
    local OldValue = GetCopySceneParam(scene, 13)
    if OldValue == 0 then
        SetCopySceneParam(scene, 13, 1)
    end
end

function x020088_ClearAllMonster(scene)
    DeleHostileMonster(scene)
end

function x020088_Stage_2(scene, curStage, curSubStage)
    local nCurStage = GetCopySceneParam(scene, x020088_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020088_g_CSParamIdxCurStage, nCurStage + 1)
    SetCopySceneParam(scene, x020088_g_CSParamIdxCurSubStage, 0)
    ShowSJCSEnd(scene, true)
    x020088_Success(scene)
end

function x020088_Success(scene)
    AccoutByCopyScene(scene)
    SetCopySceneSuccess(scene)
end

function x020088_OnObjDie(scene, objId, rolebaseId, killerId)
    local MonCount = GetHostileMonsterCount(scene)
    local nCurStage = GetCopySceneParam(scene, x020088_g_CSParamIdxCurStage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020088_g_AdapteLvl then
        nAdaptedLvl = x020088_g_AdapteLvl
    end
    x020088_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl - 1)
    if (MonCount == 0) then
        SetCopySceneParam(scene, x020088_g_CSParamIdxCurStage, nCurStage + 1)
        SetCopySceneParam(scene, x020088_g_CSParamIdxCurSubStage, 0)
    end
end

function x020088_OnDieCountDown1(scene, rolebaseId, nlv)
    local count2 = #x020088_g_TargetList[1][1]
    for j = 1, count2 do
        local TargetId = x020088_g_TargetList[1][1][j]
        if (TargetId == rolebaseId - nlv * 10) then
            local OldValue = GetCopySceneParam(scene, 1 + j)
            SetCopySceneParam(scene, 1 + j, OldValue + 1)
            local nUserCount = GetSceneUserCount(scene)
            for i = 0, nUserCount - 1 do
                local nUserObjId = GetUserObjIdByIdx(scene, i)
                SynCsStageData(scene, nUserObjId)
            end
        end
    end
end

function x020088_Stage_1(scene, stage, substage, nlv)
    if substage == 1 then
        TellPlayerAutoCombat(scene, true)
        for i = 1, #x020088_g_RoleBaseId do
            for j = 1, #x020088_g_RoleBaseId[i] do
                local monsterId = CreateMonster(scene, x020088_g_RoleBaseId[i][j] + nlv * 10, x020088_g_RoleBasePosList[i][j][3], x020088_g_RoleBasePosList[i][j][1], x020088_g_RoleBasePosList[i][j][2])
                if i == 1 then
                    SendImpactToUnit(scene, monsterId, x020088_g_BuffId)
                    SendImpactToUnit(scene, monsterId, x020088_g_DieImpact)
                end
            end
        end
    elseif substage == 2 then
        for i = 1, #x020088_g_RoleBaseId2 do
            for j = 1, #x020088_g_RoleBaseId2[i] do
                local monsterId = CreateMonster(scene, x020088_g_RoleBaseId2[i][j] + nlv * 10, x020088_g_RoleBasePosList2[i][j][3], x020088_g_RoleBasePosList2[i][j][1], x020088_g_RoleBasePosList2[i][j][2])
                if i == 1 then
                    SendImpactToUnit(scene, monsterId, x020088_g_BuffId)
                    SendImpactToUnit(scene, monsterId, x020088_g_DieImpact)
                end
            end
        end
    end
end
