--2.1.2偃师冰峰
x020086_g_scriptId = 020086

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

x020086_g_BossId = {}
x020086_g_BossId[1] = { 469000, 469010, 469020, 469030, 469040, 469050, 469060, 469070, 469080, 469090, 469100, 469110, 469120, 469130, 469140, 469150, 469160, 469170, 469180, 469190, 469200, 469210, 469220, 469230, 469240, 469250, 469260, 469270, 469280, 469290, 469300, 469310, 469320, 469330, 469340, 469350, 469360, 469370, 469380, 469390, 469400, 469410, 469420, 469430, 469440, 469450, 469460, 469470, 469480, 469490, 469500, 469510, 469520, 469530, 469540, 469550, 469560, 469570, 469580, 469590 }    -- Boss编号   表示Boss的自适应等级套数
x020086_g_BossPosList = {}
x020086_g_BossPosList[1] = { { 64.89, 68.6, -1.57 } }    --  Boss 坐标

x020086_g_Movparm = 10

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

x020086_g_WeakBuffId = 75108  --虚弱
x020086_g_FrozenBuffId = 75111 -- 冰冻

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

function x020086_OnCopySceneOpen(scene, objId)
    StoryAnimation(scene, 2201)
end

function x020086_OnCopySceneTick(scene, tickCount)
    --local nUserCount = GetSceneUserCount(scene)
    --for i = 0, nUserCount - 1 do
    --    local nUserObjId = GetUserObjIdByIdx(scene, i)
    --    if GetImactCount(scene, nUserObjId, x020086_g_WeakBuffId) >= 3 then
    --        RemoveImpact(scene, nUserObjId, x020086_g_WeakBuffId)
    --        SendImpactToUnit(scene, nUserObjId, x020086_g_FrozenBuffId)
    --    end
    --end
    if tickCount == 0 then
        CaluCSRound(scene)
    end
    local curStage = GetCopySceneParam(scene, x020086_g_CSParamIdxCurStage)
    local curSubStage = GetCopySceneParam(scene, x020086_g_CSParamIdxCurSubStage) + 1
    SetCopySceneParam(scene, x020086_g_CSParamIdxCurSubStage, curSubStage)
    if GetCopySceneStatus(scene) == 4 and curStage == 1 then
        curStage = 3
        x020086_ClearAllMonster(scene)
        SetCopySceneParam(scene, x020086_g_CSParamIdxCurStage, 3)
        ShowSJCSEnd(scene, false)
    end
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020086_g_AdapteLvl then
        nAdaptedLvl = x020086_g_AdapteLvl
    end
    if (tickCount == 20) then
        ChangeAllMonsterCamp(scene, 3)
    end
    if curStage == 0 then
        x020086_Stage_0(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 1 then
        x020086_Stage_1(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 2 then
        x020086_Stage_2(scene, curStage, curSubStage)
    end
end

function x020086_Stage_0(scene, stage, substage, nlv)
    if ((substage == x020086_g_Movparm and GetCopySceneParam(scene, 13) == 0) or GetCopySceneParam(scene, 13) == 1) then
        SetCopySceneParam(scene, 13, 2)
        SetCopySceneParam(scene, x020086_g_CSParamIdxCurStage, 1)
        SetCopySceneParam(scene, x020086_g_CSParamIdxCurSubStage, 0)
    end
end

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

function x020086_ClearAllMonster(scene)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020086_g_AdapteLvl then
        nAdaptedLvl = x020086_g_AdapteLvl
    end
    DeleMonsterByRoleId(scene, x020086_g_BossId[1][nAdaptedLvl])
end

function x020086_Stage_2(scene, curStage, curSubStage)
    local nCurStage = GetCopySceneParam(scene, x020086_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020086_g_CSParamIdxCurStage, nCurStage + 1)
    SetCopySceneParam(scene, x020086_g_CSParamIdxCurSubStage, 0)
    ShowSJCSEnd(scene, true)
    x020086_Success(scene)
end

function x020086_Success(scene)
    AccoutByCopyScene(scene)
    SetCopySceneSuccess(scene)
end

function x020086_OnObjDie(scene, objId, rolebaseId, killerId)
    local MonCount = GetHostileMonsterCount(scene)
    local nCurStage = GetCopySceneParam(scene, x020086_g_CSParamIdxCurStage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020086_g_AdapteLvl then
        nAdaptedLvl = x020086_g_AdapteLvl
    end
    x020086_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
    if (MonCount == 0) then
        SetCopySceneParam(scene, x020086_g_CSParamIdxCurStage, nCurStage + 1)
        SetCopySceneParam(scene, x020086_g_CSParamIdxCurSubStage, 0)
    end
end

function x020086_OnDieCountDown1(scene, rolebaseId, nlv)
    local TargetId = x020086_g_BossId[1][nlv]
    if (TargetId == rolebaseId) then
        local OldValue = GetCopySceneParam(scene, x020086_g_CSParamIdxrandtime)
        SetCopySceneParam(scene, x020086_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 x020086_Stage_1(scene, stage, substage, nlv)
    if substage == 1 then
        TellPlayerAutoCombat(scene, true)
        CreateMonster(scene, x020086_g_BossId[1][nlv], x020086_g_BossPosList[1][1][3], x020086_g_BossPosList[1][1][1], x020086_g_BossPosList[1][1][2])
    end
end
