dp宠物合成(宠物融合)卷

-- 宠物合成/融合券 获得高品阶宠物
item_handler[2023061230] = function(user, item_id)
    -- 定义五阶宠物ID,0、1、2、3,4区分品阶(稀有、神器、传说、史诗、神话) 
    local pet_map = {
        [400990104] = 0, 
        [400990132] = 0,
        [400990235] = 0, 
        [400990236] = 0, 
        [400990170] = 0, 
        [400990171] = 0,
        [400990446] = 0, 
        [400990447] = 0, 
        [100330533] = 0,
        [100330531] = 0,
        [2023521061] = 1,
        [2023521065] = 1,
        [2023521093] = 1, 
        [2023521097] = 1, 
        [2023521069] = 1, 
        [2023521073] = 1,
        [2023521089] = 1, 
        [2023521085] = 1, 
        [2023521077] = 1, 
        [2023521081] = 1,
        [2023521062] = 2, 
        [2023521066] = 2,
        [2023521094] = 2, 
        [2023521098] = 2, 
        [2023521070] = 2, 
        [2023521074] = 2,
        [2023521090] = 2, 
        [2023521086] = 2, 
        [2023521078] = 2, 
        [2023521082] = 2,
        [2023521063] = 3, 
        [2023521067] = 3,
        [2023521095] = 3, 
        [2023521099] = 3, 
        [2023521071] = 3, 
        [2023521075] = 3,
        [2023521091] = 3,
        [2023521087] = 3,
        [2023521079] = 3,
        [2023521083] = 3,
        [2023521064] = 4,
        [2023521068] = 4,
        [2023521096] = 4,
        [2023521100] = 4,
        [2023521072] = 4,
        [2023521076] = 4,
        [2023521092] = 4,
        [2023521088] = 4,
        [2023521080] = 4,
        [2023521084] = 4,
    }


    local pet_item1 = dpx.item.info(user.cptr, 7, 0)-- 获取背包中宠物第一格的信息
    local pet_item2 = dpx.item.info(user.cptr, 7, 1)-- 获取背包中宠物第二格的信息
    if pet_item1 and pet_item2 then
        local pet_id1 = pet_item1.id
        local pet_id2 = pet_item2.id
        local num1 = pet_map[pet_id1]
        local num2 = pet_map[pet_id2]
        if num1 and  num2  then
                    --前四阶宠物0,1,2,3 的合成概率分别为0.1,0.2,0.3,0.4 例如 0(稀有)+1(神器)的合成概率为0.3
            local prob = 0.1 * (num1 == 0 and 1 or 0) +0.1 * (num2 == 0 and 1 or 0) -- 计算0的概率
            + 0.2 * (num1 == 1 and 1 or 0) + 0.2 *(num2 == 1 and 1 or 0) -- 计算1的概率
            + 0.3 * (num1 == 2 and 1 or 0) + 0.3 * (num2 == 2 and 1 or 0) -- 计算2的概率
            + 0.4 * (num1 == 3 and 1 or 0) + 0.4 *(num2 == 3 and 1 or 0) -- 计算3的概率
        math.randomseed(tostring(os.time()):reverse():sub(1, 7))
            local rand = math.random() -- 生成一个 0~1 的随机数
               local math_max = require("math").max
            finalnum = math_max(num1,num2) + 1

            if finalnum <= 4 then
                if rand <= prob then -- 如果随机数小于等于概率,则合成成功
                    local finalpets = {}--保存高品阶宠物ID
                    for k, val in pairs (pet_map) do
                        if val == finalnum then
                            table.insert(finalpets, k)
                        end
                    end
                    -- 删除背包中的宠物
                    dpx.item.delete(user.cptr, 7, 0, 1)
                    dpx.item.delete(user.cptr, 7, 1, 1)
                    dpx.item.add(user.cptr, finalpets[math.random(1, #finalpets)], 1) --获得随机一个高品阶宠物
                    user:SendNotiPacketMessage("恭喜你合成成功!获得更高品级宠物!", 1)
                else -- 否则合成失败,仅保留第一格宠物!
                    dpx.item.delete(user.cptr, 7, 1, 1)
                    user:SendNotiPacketMessage("合成失败,仅保留第一格宠物!", 1)
                end
            else
                dpx.item.add(user.cptr, item_id)
                user:SendNotiPacketMessage("最高阶宠物已无法合成!", 1)    
            end
        else
            -- 回收券返回背包
            dpx.item.add(user.cptr, item_id)
            user:SendNotiPacketMessage("请正确放置宠物!注意部分宠物不能回收!", 1)
        end
    else
        dpx.item.add(user.cptr, item_id)
        user:SendNotiPacketMessage("请确保宠物栏第一、第二格有可回收宠物!", 1)
    end
end

 

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容