wx020068_g_scriptId = 020068

x020068_g_AdapteLvl = 30  --   每个怪物的自适应等级套数  必须随适应等级的变化而改变
x020068_g_BeginLvl = 30--开始的等级，功能开放等级/10
--以上为波次刷怪的波次适应等级  编号1代表第一波怪的自适应等级    编号1里第一个中括号表示第一波第一个怪物的自适应等级套数  依次类推

x020068_g_YuansuId = {}
x020068_g_YuansuId[1] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[2] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[3] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[4] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[5] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[6] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[7] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[8] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[9] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[10] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[11] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[12] = { 540030, 541330, 540230, 541430, 540430, 541530 }
x020068_g_YuansuId[13] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[14] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[15] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[16] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[17] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[18] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[19] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[20] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[21] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[22] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[23] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[24] = { 540030, 540130, 540230, 540330, 540430, 540530 }
x020068_g_YuansuId[25] = { 540630, 540730, 540830, 540930, 541030, 541130 }

x020068_g_YuansuPosList = {}
x020068_g_YuansuPosList[1] = { { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 }, { 13.75, 64.36, 1.33 } }    -- 坐标控制数量，多少个坐标一次刷多少个
x020068_g_YuansuPosNum = 25

x020068_g_DropId = {}
x020068_g_DropId[1] = { 290001, 290002, 290003, 290004 }   -- 对应下边的ID段进行掉落

x020068_g_MonstIndex = {}
x020068_g_MonstIndex[1] = { 540030, 540130, 540230, 540330, 540430, 540530 }   -- 小怪对应掉落包
x020068_g_MonstIndex[2] = { 541330, 541430, 541530 }    -- 精英
x020068_g_MonstIndex[3] = { 540630, 540730, 540830, 540930, 541030, 541130 }  -- boss对应掉落包
x020068_g_MonstIndex[4] = { 541230 }   -- 黄金boss


x020068_g_CreateTime = 5-- 废弃
x020068_g_StageCreateTime = 1 -- 废弃

x020068_g_TotalNum = 120 -- 刷怪等待时间
x020068_g_TotalStage = 6 -- 总波次

x020068_g_DingShengBuff = 72034
x020068_g_GroupIdS = 900
x020068_g_GroupIdE = 926

x020068_g_TowerId = 541630
x020068_g_TowerId2 = 541730

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

x020068_g_AddMoneyMonestId = {}
x020068_g_AddMoneyMonestId[1] = { 540030, 540130, 540230, 540330, 540430, 540530, 541330, 541430, 541530, 540630, 540730, 540830, 540930, 541030, 541130 }

x020068_g_AddMoneyMonestNum = {}
x020068_g_AddMoneyMonestNum[1] = { 1, 1, 1, 1, 1, 1, 5, 5, 5, 10, 10, 10, 10, 10, 10 }

x020068_g_BossId = 541230
x020068_g_BossPosList = {}
x020068_g_BossPosList[1] = { { 13.75, 64.36, 1.33 } }    --  Boss 坐标

x020068_g_TpPosList = {}
x020068_g_TpPosList[1] = { { 13.75, 64.36, 1.33 }, { 11.17, 18.39, 3.16 } }
x020068_g_CSParamIdxCurStage = 0                     -- 场景切换波数
x020068_g_CSParamIdxCurSubStage = 1                   -- 同一场景中的时间点
x020068_g_CSParamIdxrandtime = 2                       -- 记录击杀了几个攻城小怪
x020068_g_CSParamIdxrandtime2 = 3                   -- 记录击杀了几个攻城小怪
x020068_g_CSParamIdLastBattleTime = 4               -- 上一次结束战斗的时间戳
x020068_g_CSParamIdxCurStageSumMon = 5               -- 当前波次的总怪物数量

function x020068_OnCopySceneOpen(scene)
    --print("!!!!!!!!")
    SyncJuHunCSDate(scene)
    --CreateGroupPoint(scene, 371, 43, 14, 1.57)
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurStageSumMon, x020068_g_YuansuPosNum)
    StoryAnimation(scene, 6023)
    --	for i = x020068_g_GroupIdS, x020068_g_GroupIdE do
    --		CreateGroupPointById(scene, i)
    --	end
end
function x020068_OnObjEnter(scene, objId)
    SyncJuHunCSDate(scene)
    SynCsStageData(scene, objId, true)
    AutoCombat(scene, objId, true)
    --AutoCombat(scene,objId,true)
end
function x020068_CsCountDownJugle(scene, tickCount)
    local LastBattleTime = GetCopySceneParam(scene, x020068_g_CSParamIdLastBattleTime)
    local CurCSStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage) + 1
    local TimeTick = x020068_g_TotalNum
    if (CurCSStage ~= 1) then
        TimeTick = 1
    end

    if (CurCSStage <= 12) and (CurCSStage % 2 == 1) and (tickCount == LastBattleTime + TimeTick) then
        --print(CurCSStage)
        SetCopySceneParam(scene, x020068_g_CSParamIdxCurStage, CurCSStage)
        SetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage, 0)
        SetCopySceneParam(scene, x020068_g_CSParamIdLastBattleTime, -1)
        --print("倒計時開始出怪")
        SyncJuHunCSDate(scene)
    end
end
function x020068_StartBattle(scene)
    local nUserCount = GetSceneUserCount(scene)
    for i = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, i)
        AutoCombat(scene, nUserObjId, true)
    end
    local CurCSStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage) + 1
    if (CurCSStage <= 12) and (CurCSStage % 2 == 1) then
        SetCopySceneParam(scene, x020068_g_CSParamIdxCurStage, CurCSStage)
        SetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage, 0)
        SetCopySceneParam(scene, x020068_g_CSParamIdLastBattleTime, -1)
        --SetMissionMD(scene)
        --print("手動開始出怪")
        SyncJuHunCSDate(scene)
    end
end
function x020068_OnStoryEventEnd(scene, nStoryId, nAnimationId)
    BroadCastBossTips(scene, 60606, 86020, 541630)
end
function x020068_DingShenBuff(scene)
    -- 买定身
    --print("花錢定身")

    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    nAdaptedLvl = nAdaptedLvl - x020068_g_BeginLvl
    if nAdaptedLvl > x020068_g_AdapteLvl then
        nAdaptedLvl = x020068_g_AdapteLvl
    end
    if (nAdaptedLvl < 0) then
        nAdaptedLvl = 0
    end
    for i = 1, x020068_g_YuansuPosNum do
        for j = 1, x020068_g_TotalStage do
            SendImpactToAllByRBID(scene, x020068_g_YuansuId[i][j] + nAdaptedLvl, x020068_g_DingShengBuff)
        end
    end
    SendImpactToAllByRBID(scene, x020068_g_BossId + nAdaptedLvl, x020068_g_DingShengBuff)
end
function x020068_CreatHuangJingBoss(scene)
    -- 买boss
    --print("花錢買boss")

    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    nAdaptedLvl = nAdaptedLvl - x020068_g_BeginLvl
    if nAdaptedLvl > x020068_g_AdapteLvl then
        nAdaptedLvl = x020068_g_AdapteLvl
    end
    if (nAdaptedLvl < 0) then
        nAdaptedLvl = 0
    end
    BroadCastTips(scene, 86011)
    local Id = CreateMonster(scene, x020068_g_BossId + nAdaptedLvl, x020068_g_BossPosList[1][1][3], x020068_g_BossPosList[1][1][1], x020068_g_BossPosList[1][1][2])
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurStageSumMon, x020068_g_YuansuPosNum + 1)
    NpcStartPatrol(scene, Id, 2300)
end
function x020068_OnCopySceneTick(scene, tickCount)
    --副本阶段
    x020068_CsCountDownJugle(scene, tickCount)

    x020068_TickRemoveGroupPoint(scene)
    local curStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage) + 1
    local curSubStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage) + 1
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage, curSubStage)
    --print(curStage)
    if (tickCount == 0) then
        --SetSceneBuff(scene,4700,x020068_g_TpPosList[1][1][1],x020068_g_TpPosList[1][1][2],0)
        --SetSceneBuff(scene,4701,x020068_g_TpPosList[1][2][1],x020068_g_TpPosList[1][2][2],0)
    end
    --x020068_OpenAutoCombat(scene)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    nAdaptedLvl = nAdaptedLvl - x020068_g_BeginLvl
    if nAdaptedLvl > x020068_g_AdapteLvl then
        nAdaptedLvl = x020068_g_AdapteLvl
    end
    if (nAdaptedLvl < 0) then
        nAdaptedLvl = 0
    end

    if curStage <= 2 * x020068_g_TotalStage and curStage % 2 == 0 then
        local nUserCount = GetSceneUserCount(scene)
        for i = 0, nUserCount - 1 do
            local nUserObjId = GetUserObjIdByIdx(scene, i)
            --	AutoCombat(scene,nUserObjId,true)
        end
        x020068_CreateMonster(scene, 1, 3, nAdaptedLvl, tickCount, curStage)
    elseif curStage == x020068_g_TotalStage * 2 + 1 then
        x020068_Stage_2(scene, curStage, curSubStage)
    end
end
function x020068_Stage_2(scene, curStage, curSubStage)
    -- body
    local nCurStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurStage, nCurStage + 1)
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage, 0)
    --ShowSJCSEnd(scene, true)
    ShowJuHunCsEnd(scene, true)
    x020068_Success(scene)
end
function x020068_Success(scene)
    --print("結束了")
    AccoutByCopyScene(scene)
    local nUserCount = GetSceneUserCount(scene)
    for i = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, i)
        --	AwardCSItemBox(scene,nUserObjId,x020068_g_IdCSxiayiBox, x020068_g_IdCSItemBox)
    end
    SetCopySceneSuccess(scene)
end

function x020068_OnObjDie(scene, objId, rolebaseId, killerId)
    local MonCount = GetHostileMonsterCount(scene)
    local nCurStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage)
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    nAdaptedLvl = nAdaptedLvl - x020068_g_BeginLvl
    if nAdaptedLvl > x020068_g_AdapteLvl then
        nAdaptedLvl = x020068_g_AdapteLvl
    end
    if (nAdaptedLvl < 0) then
        nAdaptedLvl = 0
    end
    local nUserCount = GetSceneUserCount(scene)
    for i = 1, 4 do
        local MonCount = #x020068_g_MonstIndex[i]
        for j = 1, MonCount do
            --	print("死亡統計怪物ID")
            --	print(rolebaseId+nAdaptedLvl)
            --	print("目標ID")
            --	print(x020068_g_MonstIndex[i][j])
            if x020068_g_MonstIndex[i][j] + nAdaptedLvl == rolebaseId then

                for k = 0, nUserCount - 1 do
                    local nUserObjId = GetUserObjIdByIdx(scene, k)
                    --	print("獲得掉落")
                    --	print(x020068_g_DropId[1][i])
                    CreatDropBox(scene, nUserObjId, x020068_g_DropId[1][i], objId)
                end
            end
        end
    end

    local OldValue = GetCopySceneParam(scene, x020068_g_CSParamIdxrandtime)
    --	for i = 1, x020068_g_YuansuPosNum do
    --		for j = 1, x020068_g_TotalStage do
    --			if(rolebaseId == (x020068_g_YuansuId[i][j] + nAdaptedLvl))or (rolebaseId == x020068_g_BossId +nAdaptedLvl) then
    if rolebaseId > 100 then
        AddJuHunCSExp(scene, rolebaseId)
        OldValue = OldValue + 1
        SetCopySceneParam(scene, x020068_g_CSParamIdxrandtime, OldValue)
        --break
    end

    local countM = #x020068_g_AddMoneyMonestId[1]
    for i = 1, countM do
        if rolebaseId == x020068_g_AddMoneyMonestId[1][i] + nAdaptedLvl then
            AddCopySceneScore(scene, x020068_g_AddMoneyMonestNum[1][i])
        end

    end
    --			end
    ---        end
    --	end
    x020068_JugleComplete(scene, OldValue)
end

function x020068_CreateMonster(scene, idx, camp, nlv, tickCount, stage)
    --刷怪（
    local CurTick = GetCopySceneParam(scene, x020068_g_CSParamIdxCurSubStage)
    local NowStage = math.ceil(stage / 2)
    --	print(CurTick)
    if (CurTick == 1) then
        AutoHuangJingBoss(scene)
        SyncJuHunCSDate(scene)
    end
    local count = #x020068_g_YuansuPosList[idx]
    for i = 1, count do
        if (CurTick == i * x020068_g_StageCreateTime) then

            local objId = CreateMonster(scene, x020068_g_YuansuId[i][NowStage] + nlv, x020068_g_YuansuPosList[idx][i][3], x020068_g_YuansuPosList[idx][i][1], x020068_g_YuansuPosList[idx][i][2])

            NpcStartPatrol(scene, objId, 2300)
        end
    end


end
function x020068_OnPickGroupPiont(scene, GroupId)
    --刷怪（
    local nAdaptedLvl = math.floor(GetAdaptLvl(scene) / 10)
    nAdaptedLvl = nAdaptedLvl - x020068_g_BeginLvl
    if nAdaptedLvl > x020068_g_AdapteLvl then
        nAdaptedLvl = x020068_g_AdapteLvl
    end
    if (nAdaptedLvl < 0) then
        nAdaptedLvl = 0
    end
    local MonRBId = x020068_g_TowerId + nAdaptedLvl
    local MonRBId2 = x020068_g_TowerId2 + nAdaptedLvl
    CreateTowerByGroupId(scene, GroupId, MonRBId, MonRBId2)

    --SetShowDamage(scene, true, ObjId)
end

function x020068_JugleComplete(scene, Old)
    --刷怪（
    local NowMonNum = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStageSumMon)
    local MaxNum = x020068_g_YuansuPosNum
    if NowMonNum >= MaxNum then
        MaxNum = NowMonNum
    end
    SyncJuHunCSDate(scene)
    --print("刷怪判斷當前數量")
    --print(Old)
    --print("刷怪判斷需要的數量")
    --print(MaxNum)
    if (Old >= MaxNum and GetHostileMonsterCount(scene) == 0) then
        --x020068_ClearAllMonster(scene)
        x020068_ChangeCSStage(scene)
    end
end
function x020068_ChangeCSStage(scene)
    -- 切换波次的回调
    local CurTick = GetCopySceneParam(scene, 9)
    local OldStage = GetCopySceneParam(scene, x020068_g_CSParamIdxCurStage)
    SetCopySceneParam(scene, x020068_g_CSParamIdxCurStage, OldStage + 1)

    if OldStage + 1 < 12 then
        SetCopySceneParam(scene, x020068_g_CSParamIdxrandtime, 0)
        SetCopySceneParam(scene, x020068_g_CSParamIdxCurStageSumMon, x020068_g_YuansuPosNum)
    end

    SetCopySceneParam(scene, x020068_g_CSParamIdLastBattleTime, CurTick)
    SyncJuHunCSDate(scene)
    --	x020068_g_CSParamIdxCurStageSumMon(scene)

end
function x020068_TickRemoveGroupPoint(scene)
    local nUserCount = GetSceneUserCount(scene)
    for i = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, i)
        local TowerNum = GetMissionMD(scene, nUserObjId, 1, 444)
        if TowerNum >= 10 then
            for i = x020068_g_GroupIdS, x020068_g_GroupIdE do
                RemoveSceneBuffById(scene, i)
            end
        end
    end


end
function x020068_OnObjPatrolEnd(scene, objId)
    --print("巡邏完成刪除怪物當前的消失怪物數量")


    -- body
    DeleMonsterByObjId(scene, objId)
    local OldValue = GetCopySceneParam(scene, x020068_g_CSParamIdxrandtime)
    --print(OldValue+1)
    SetCopySceneParam(scene, x020068_g_CSParamIdxrandtime, OldValue + 1)
    x020068_JugleComplete(scene, OldValue + 1)

end