TaskInfo.lua 2.12 KB
cc.exports.TaskInfo = {}

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

local taskMap = {};

--任务配置表信息
local function init()
    local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/task_daily.xml");
    local data = xml.parse(configStr, false, true);

    for i,v in pairs(data) do
        if v.tag == "game" then
            local taskList = taskMap[v.attr.id];
            if not taskList then
                taskList = {};
                taskMap[v.attr.id] = taskList;
            end
            for ii,vv in pairs(v) do
                if vv.tag == "task" then
                    print("task:"..json.encode(vv.attr));
                    local taskInfo = {};
                    taskInfo.id = tonumber(vv.attr.id);
                    taskInfo.name = vv.attr.name;
                    taskInfo.pic = vv.attr.pic;
                    taskInfo.desc = vv.attr.desc;
                    taskInfo.steps = {};
                    for iii,vvv in pairs(vv) do
                        if vvv.tag == "step" then
                            local stepInfo = {};
                            stepInfo.id = tonumber(vvv.attr.id);
                            stepInfo.reward = vvv.attr.reward;
                            taskInfo.steps[#taskInfo.steps + 1] = stepInfo;
--                            print("step:"..json.encode(stepInfo));
                        end
                    end
                    table.sort(taskInfo.steps,function (aa,bb)
                        return aa.id<bb.id;
                    end);
                    taskList[#taskList+1] = taskInfo;
                end
            end
        end
    end
end
init();

function TaskInfo.getTaskListByGameID(game_id)
    local taskList = {};
    if taskMap[tostring(game_id)] then
        taskList = taskMap[tostring(game_id)];
    end
    return taskList;
end

function TaskInfo.getInfoByGameIDAndTaskID(game_id,task_id)
    local info = nil;
    local _list = TaskInfo.getTaskListByGameID(game_id);
    for i,v in ipairs(_list) do
        if v.id == task_id then
            info = v;
            break;
        end
    end
    return info;
end

return TaskInfo