GiftInfo.lua 1.54 KB
cc.exports.GiftInfo = {}

local xml = require("core.utils.pl.xml")

local itemMap = {};
local create_reward = "";

--奖励配置表信息
local function init()
    local itemStr = cc.FileUtils:getInstance():getStringFromFile("res/config/role_reward.txt");
    local function readLineFun(lineStr)
        local contents = StringUtil.split(lineStr,'\t');
        if #contents > 1 then
            local info = {};
            info.id = tonumber(contents[1]);
            info.reward = contents[2];
            itemMap[tostring(info.id)] = info;
        end
    end

    local index = 1;
    local function readLine(str)
        local a,b = string.find(str,"\r\n");
        if a then
            local lineStr = string.sub(str,1,a-1);
            if index > 2 then
                readLineFun(lineStr);
            end

            index = index + 1;
            str = string.sub(str,b+1);
            readLine(str);
        else
            readLineFun(str);
        end
    end
    readLine(itemStr);
end
init();

function initCreateRewardConfig()
    local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/create_reward.xml");
    local data = xml.parse(configStr, false, true);

    for k,v in pairs(data) do
        if k ~= "attr" and k ~= "tag" then
            create_reward = v.attr.item;
        end
    end
end
initCreateRewardConfig();

--通过ID获取奖励信息
function GiftInfo.getGiftInfo(id)
    return itemMap[tostring(id)];
end

--通过ID创建角色奖励
function GiftInfo.getCreateRewardStr()
    return create_reward;
end

return GiftInfo