--2.1.1飞廉风屿
x020085_g_scriptId = 020085

x020085_g_CSParamIdxCurStage = 0                     -- 场景切换波数
x020085_g_CSParamIdxCurSubStage = 1                   -- 同一场景中的时间点
x020085_g_CSParamIdxrandtime = 2                       -- 记录击杀了boss
x020085_g_OldTick = 5                       -- 记录飙风怪刷新时间

x020085_g_CreateCount = 6                       -- 记录飙风怪波次

x020085_g_Movparm = 20                                 --mov超时时间

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

x020085_g_ZHHp = 80                         -- 飙风怪触发血量

x020085_g_OneCreateJuFeng = 2               -- 第一次刷新飙风怪数量

x020085_g_BossId = {}
x020085_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的自适应等级套数

x020085_g_BossPosList = {}
x020085_g_BossPosList[1] = { { 47, 38.23, -1.43 } }    --  Boss 坐标

x020085_g_YuansuIdCs = 482000    -- 小怪物初始ID
x020085_g_TpPosList = {}
x020085_g_TpPosList[1] = { { 45, 40.75, -1.57 }, { 49.12, 40.75, 4.54 } }

x020085_g_JuFengIdCs = {}       -- 召唤飓风怪初始ID
x020085_g_JuFengIdCs[1] = { 482700, 482701, 482702, 482703 }

x020085_g_TpPosListJuFeng = {}
x020085_g_TpPosListJuFeng[1] = { { 44.81, 40.83, -1.22 }, { 49.75, 40.59, 3.21 } }
x020085_g_TpPosListJuFeng[2] = { { 44.34, 30.65, -1.22 }, { 50.66, 28.83, 3.21 }, { 36.5, 44.37, -1.22 }, { 55.55, 27.87, -1.22 } }
x020085_g_TpPosListJuFeng[3] = { { 44.14, 27.25, -1.22 }, { 49.5, 26.97, 3.21 }, { 38.71, 30.56, -1.22 }, { 40.98, 29.86, -1.22 } }
x020085_g_TpPosListJuFeng[4] = { { 53.72, 30.27, -1.22 }, { 55.12, 31.92, 3.21 }, { 34.83, 33.23, -1.22 }, { 57.21, 44.98, -1.22 } }

--飙风怪物寻路，路径表ID（NpcPatroPath）
x020085_g_MoveListId = {}
x020085_g_MoveListId[1] = { 30001, 30011 }
x020085_g_MoveListId[2] = { 30101, 30111, 30121, 30131 }
x020085_g_MoveListId[3] = { 30201, 30211, 30221, 30231 }
x020085_g_MoveListId[4] = { 30301, 30311, 30321, 30331 }

x020085_g_JuFengAttrBuffId = 75101 -- 伤害BUFF

x020085_g_TargetList = {}                      --目标
x020085_g_TargetList[1] = { { 481000 } }  --{{第1阶段目标},{第1阶段目标2}}

x020085_g_BossTips = {}
x020085_g_BossTips[1] = { 94029, 61002 } -- (StrDicId, FakeObjId)

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

function x020085_OnCopySceneOpen(scene, objId)
    StoryAnimation(scene, 2202)
end

function x020085_OnCopySceneTick(scene, tickCount)
    if tickCount == 0 then
        CaluCSRound(scene)
    end
    local curStage = GetCopySceneParam(scene, x020085_g_CSParamIdxCurStage)
    local curSubStage = GetCopySceneParam(scene, x020085_g_CSParamIdxCurSubStage) + 1
    SetCopySceneParam(scene, x020085_g_CSParamIdxCurSubStage, curSubStage)
    if GetCopySceneStatus(scene) == 4 and curStage == 1 then
        curStage = 3
        x020085_ClearAllMonster(scene)
        SetCopySceneParam(scene, x020085_g_CSParamIdxCurStage, 3)
        ShowSJCSEnd(scene, false)
    end
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020085_g_AdapteLvl then
        nAdaptedLvl = x020085_g_AdapteLvl
    end
    if (tickCount == 20) then
        ChangeAllMonsterCamp(scene, 3)
    end
    --if tickCount == 0 then
    --    SetSceneBuff(scene, 4702, x020085_g_TpPosList[1][1][1], x020085_g_TpPosList[1][1][2], 0)
    --    SetSceneBuff(scene, 4702, x020085_g_TpPosList[1][2][1], x020085_g_TpPosList[1][2][2], 0)
    --end
    local ZhobjId1 = GetObjIdByRoleBase(scene, x020085_g_BossId[1][nAdaptedLvl])
    local Hp = CalculatePercenHp(scene, ZhobjId1)
    local NewTick = GetCopySceneParam(scene, x020085_g_OldTick)
    if Hp < x020085_g_ZHHp and Hp ~= -1 and NewTick == 0 then
        x020085_CreateMonsterJuFeng(scene, tickCount, 1, nAdaptedLvl)
        SetCopySceneParam(scene, x020085_g_CreateCount, 1)
        BroadCastBossTips(scene, x020085_g_BossTips[1][2], x020085_g_BossTips[1][1], x020085_g_BossId[1][nAdaptedLvl])
    end

    if NewTick > 0 and NewTick == tickCount then
        local stage = GetCopySceneParam(scene, x020085_g_CreateCount) + 1
        if stage > #x020085_g_JuFengIdCs[1] then
            stage = 1
        end
        SetCopySceneParam(scene, x020085_g_CreateCount, stage)
        x020085_CreateMonsterJuFeng(scene, tickCount, stage, nAdaptedLvl)
    end

    if curStage == 0 then
        x020085_Stage_0(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 1 then
        x020085_Stage_1(scene, curStage, curSubStage, nAdaptedLvl)
    elseif curStage == 2 then
        x020085_Stage_2(scene, curStage, curSubStage)
    end
end

function x020085_Stage_0(scene, stage, substage, nlv)
    if ((substage == x020085_g_Movparm and GetCopySceneParam(scene, 13) == 0) or GetCopySceneParam(scene, 13) == 1) then
        SetCopySceneParam(scene, 13, 2)
        SetCopySceneParam(scene, x020085_g_CSParamIdxCurStage, 1)
        SetCopySceneParam(scene, x020085_g_CSParamIdxCurSubStage, 0)

        FeiLianFengYuLog(scene, 2, GetCopySceneParam(scene, 13))
    end
end

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

        FeiLianFengYuLog(scene, 1, 0)
    end
end

function x020085_ClearAllMonster(scene)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020085_g_AdapteLvl then
        nAdaptedLvl = x020085_g_AdapteLvl
    end
    DeleMonsterByRoleId(scene, x020085_g_BossId[1][nAdaptedLvl])
end

function x020085_Stage_2(scene, curStage, curSubStage)
    local nCurStage = GetCopySceneParam(scene, x020085_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020085_g_CSParamIdxCurStage, nCurStage + 1)
    SetCopySceneParam(scene, x020085_g_CSParamIdxCurSubStage, 0)
    ShowSJCSEnd(scene, true)
    x020085_Success(scene)

    FeiLianFengYuLog(scene, 5, 0)
end

function x020085_Success(scene)
    for i = 1, #x020085_g_JuFengIdCs[1] do
        DeleMonsterByRoleId(scene, x020085_g_JuFengIdCs[1][i])
    end
    AccoutByCopyScene(scene)
    SetCopySceneSuccess(scene)
end

function x020085_OnObjDie(scene, objId, rolebaseId, killerId)
    local nCurStage = GetCopySceneParam(scene, x020085_g_CSParamIdxCurStage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    if nAdaptedLvl > x020085_g_AdapteLvl then
        nAdaptedLvl = x020085_g_AdapteLvl
    end
    x020085_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
    if rolebaseId == x020085_g_BossId[1][nAdaptedLvl] and nCurStage < 3 then
        SetCopySceneParam(scene, x020085_g_CSParamIdxCurStage, 2)
        SetCopySceneParam(scene, x020085_g_CSParamIdxCurSubStage, 0)

        FeiLianFengYuLog(scene, 4, 0)
    end
end

function x020085_OnDieCountDown1(scene, rolebaseId, nlv)
    if rolebaseId == x020085_g_BossId[1][nlv] then
        local OldValue = GetCopySceneParam(scene, x020085_g_CSParamIdxrandtime)
        SetCopySceneParam(scene, x020085_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 x020085_Stage_1(scene, stage, substage, nlv)
    if substage == 1 then
        CreateMonster(scene, x020085_g_BossId[1][nlv], x020085_g_BossPosList[1][1][3], x020085_g_BossPosList[1][1][1], x020085_g_BossPosList[1][1][2])
        TellPlayerAutoCombat(scene, true)

        FeiLianFengYuLog(scene, 3, 0)
        for i = 1, 2 do
            CreateMonster(scene, x020085_g_YuansuIdCs + (nlv - 1) * 10, x020085_g_TpPosList[1][i][3], x020085_g_TpPosList[1][i][1], x020085_g_TpPosList[1][i][2])
        end
    end
end

function x020085_CreateMonsterJuFeng(scene, tickCount, stage, nlv)
    local num = x020085_g_OneCreateJuFeng
    if stage > 1 then
        num = #x020085_g_JuFengIdCs[1]
    end
    for i = 1, num do
        local MonId = CreateMonster(scene, x020085_g_JuFengIdCs[1][stage], x020085_g_TpPosListJuFeng[stage][i][3], x020085_g_TpPosListJuFeng[stage][i][1], x020085_g_TpPosListJuFeng[stage][i][2])
        NpcStartPatrol(scene, MonId, x020085_g_MoveListId[stage][i])--怪物寻路
        SendImpactToAllByRBID(scene, x020085_g_JuFengIdCs[1][stage], x020085_g_JuFengAttrBuffId)
    end
    SetCopySceneParam(scene, x020085_g_OldTick, tickCount + 12)
end

function x020085_OnObjPatrolEnd(scene, objId)
    DeleMonsterByObjId(scene, objId)
end