--2.1.1无量劫境

x020084_g_scriptId = 020084

--副本参数
x020084_g_CSParamIdxCurStage = 0              --大阶段
x020084_g_CSParamIdxCurSubStage = 1           --小阶段
x020084_g_CSParam1 = 2
x020084_g_CSParam2 = 3   -- 7为当前阶段

x020084_g_CSParam5 = 5   -- 落雷时间

x020084_g_AdapteLvl = 60  --   每个怪物的自适应等级套数  必须随适应等级的变化而改变

x020084_g_CSParamAnimationID = 2204           --mov动画ID

x020084_g_BossId = {}
x020084_g_BossId[1] = { 484000, 484010, 484020, 484030, 484040, 484050, 484060, 484070, 484080, 484090, 484100, 484110, 484120, 484130, 484140, 484150, 484160, 484170, 484180, 484190, 484200 ,484210,484220,484230,484240,484250,484260,484270,484280,484290,484300,484310,484320,484330,484340,484350,484360,484370,484380,484390,484400,484410,484420,484430,484440,484450,484460,484470,484480,484490,484500,484510,484520,484530,484540,484550,484560,484570,484580,484590}    -- Boss编号   表示Boss的自适应等级套数

x020084_g_MonstorPosList = {}
x020084_g_MonstorPosList[1] = { { 62.73, 79.99, -1.57 } }

x020084_g_Thunder = 485000   -- 落雷ID

x020084_g_ThunderPost = {} --落雷刷新位置
x020084_g_ThunderPost[1] = { { 63, 73.39, 1.57 }, { 68.35, 80.2, 1.57 }, { 62.53, 85.23, 1.57 }, { 57.46, 79.79, 1.57 }, { 66.2, 72.23, 1.57 }, { 56.53, 72.87, 1.57 }, { 51.61, 77.26, 1.57 }, { 52.16, 84.05, 1.57 }, { 56.8, 88.57, 1.57 }, { 62.05, 91.45, 1.57 }, { 68.27, 89.3, 1.57 }, { 68.27, 84.42, 1.57 }, { 62.46, 79.75, 1.57 }, { 72.53, 85.88, 1.57 }, { 57.84, 83.13, 1.57 }, { 73.83, 79.96, 1.57 }, { 70.41, 75.41, 1.57 }, { 60.98, 68.62, 1.57 }, { 66.3, 66.57, 1.57 }, { 71.43, 69.43, 1.57 }, { 75.43, 73.77, 1.57 }, { 56.13, 67.49, 1.57 }, { 61.37, 74.57, 1.57 }, { 51.15, 71.65, 1.57 }, { 74.12, 92.51, 1.57 }, { 46.21, 75.07, 1.57 }, { 47.2, 81.62, 1.57 }, { 47.74, 86.81, 1.57 }, { 51.9, 89.41, 1.57 }, { 62.57, 73.36, 1.57 }, { 56.45, 94.91, 1.57 }, { 62.66, 95.47, 1.57 }, { 46.71, 69.22, 1.57 }, { 51.5, 65.26, 1.57 }, { 57.21, 63.11, 1.57 }, { 62.64, 62.92, 1.57 }, { 69.55, 63.58, 1.57 }, { 75.4, 66.11, 1.57 }, { 79.68, 78.97, 1.57 }, { 79.91, 72.31, 1.57 }, { 77.89, 85.55, 1.57 }, { 68.86, 95.04, 1.57 }, { 50.17, 94.49, 1.57 }, { 63.24, 72.2, 1.57 } }

x020084_g_ThunderTime = 3 -- 落雷掉落时间 秒

x020084_g_ThunderNum = 4 -- 每次落雷最小数量
x020084_g_MaxThunderNum = 6 -- 每次落雷最大数量

x020084_g_BuffID = 75507 -- 死亡BUff

x020084_g_BossTips = {}
x020084_g_BossTips[1] = { 94035, 61003 } -- (StrDicId, FakeObjId)

function x020084_OnCopySceneOpen(scene)
    x020084_ClearAllMonster(scene)
    x020084_Stage_1(scene)
    x020084_CreateMonster(scene, 1)
end

function x020084_OnObjEnter(scene, objId)
    SetCopySceneParam(scene, x020084_g_CSParamIdxCurStage, 0)
    SetCopySceneParam(scene, x020084_g_CSParamIdxCurSubStage, 0)
    SetCopySceneParam(scene, x020084_g_CSParam1, 0)
    SetCopySceneParam(scene, x020084_g_CSParam2, 0)
    SetCopySceneParam(scene, x020084_g_CSParam5, 0)
    SetCopySceneParam(scene, 7, 0)
    SynCsStageData(scene, objId, true)
    TestFullHp(scene,objId)
end

function x020084_ClearAllMonster(scene)
    DeleHostileMonster(scene)
end

function x020084_OnCopySceneTimeOut(scene)
    DeleHostileMonster(scene)
    ShowSJCSEnd(scene, false)
    --SetCopySceneFail(scene)
end

function x020084_StageControl(scene, nstage)
    SetCopySceneParam(scene, 2, 0)
    SetCopySceneParam(scene, 3, 0)
    SetCopySceneParam(scene, 4, 0)
    SetCopySceneParam(scene, 7, nstage)
    local nUserCount = GetSceneUserCount(scene)
    for j = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, j)
        SynCsStageData(scene, nUserObjId)
    end
end

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

function x020084_OnObjDie(scene, objId, rolebaseId, killerId)
    local nCurStage = GetCopySceneParam(scene, x020084_g_CSParamIdxCurStage)
    local MonCount = GetHostileMonsterCount(scene)

    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020084_g_AdapteLvl then
        nAdaptedLvl = x020084_g_AdapteLvl
    end
    x020084_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)

    if (rolebaseId == x020084_g_BossId[1][nAdaptedLvl]) then
        DeleHostileMonster(scene)
        ShowSJCSEnd(scene, true)
        x020084_Success(scene)
    end

    if MonCount == 0 then
        SetCopySceneParam(scene, x020084_g_CSParamIdxCurStage, nCurStage + 1)
        SetCopySceneParam(scene, x020084_g_CSParamIdxCurSubStage, 0)
    end
end

function x020084_OnStoryEventEnd(scene, nStoryId, nAnimationId)
    if nAnimationId == x020084_g_CSParamAnimationID then
        TellPlayerAutoCombat(scene, true)
    end
end

function x020084_OnCopySceneTick(scene, tickCount)
    if tickCount == 0 then
        CaluCSRound(scene)
    end
    local curStage = GetCopySceneParam(scene, x020084_g_CSParamIdxCurStage)
    local curSubStage = GetCopySceneParam(scene, x020084_g_CSParamIdxCurSubStage)
    SetCopySceneParam(scene, x020084_g_CSParamIdxCurSubStage, curSubStage + 1)
    if curStage == 0 then
        SetCopySceneParam(scene, x020084_g_CSParamIdxCurStage, curStage + 1)
        SetCopySceneParam(scene, x020084_g_CSParamIdxCurSubStage, 0)
        x020084_StageControl(scene, 0)
        x020084_CreateMonsterThunder(scene, 1)
        SetCopySceneParam(scene, x020084_g_CSParam5, tickCount + x020084_g_ThunderTime)

        local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
        if nAdaptedLvl > x020084_g_AdapteLvl then
            nAdaptedLvl = x020084_g_AdapteLvl
        end
        BroadCastBossTips(scene, x020084_g_BossTips[1][2], x020084_g_BossTips[1][1], x020084_g_BossId[1][nAdaptedLvl])
        return
    end

    local pram1 = GetCopySceneParam(scene, x020084_g_CSParam5)
    if pram1 > 0 and pram1 == tickCount then
        local nRand = math.random(x020084_g_ThunderNum, x020084_g_MaxThunderNum)
        x020084_CreateMonsterThunder(scene, nRand)
        SetCopySceneParam(scene, x020084_g_CSParam5, tickCount + x020084_g_ThunderTime)
    end
end

--第1阶段 播放MOV
function x020084_Stage_1(scene)
    TellPlayerAutoCombat(scene, false)
    StoryAnimation(scene, x020084_g_CSParamAnimationID)
end

function x020084_CreateMonster(scene, stage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020084_g_AdapteLvl then
        nAdaptedLvl = x020084_g_AdapteLvl
    end
    CreateMonster(scene, x020084_g_BossId[1][nAdaptedLvl], x020084_g_MonstorPosList[1][1][3], x020084_g_MonstorPosList[1][1][1], x020084_g_MonstorPosList[1][1][2])
end

function x020084_CreateMonsterThunder(scene, num)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020084_g_AdapteLvl then
        nAdaptedLvl = x020084_g_AdapteLvl
    end
    local count = #x020084_g_ThunderPost[1]
    for i = 1, num do
        local nRand = math.random(1, count)
        local MonId = CreateMonster(scene, x020084_g_Thunder + (nAdaptedLvl - 1) * 10, x020084_g_ThunderPost[1][nRand][3], x020084_g_ThunderPost[1][nRand][1], x020084_g_ThunderPost[1][nRand][2])
        SendImpactToUnit(scene, MonId, x020084_g_BuffID)
    end
end

function x020084_Success(scene)
    AccoutByCopyScene(scene)
    SetCopySceneSuccess(scene)
end