Module:Quest reward

From Path of Exile 2 Wiki
Revision as of 17:26, 28 April 2018 by >OmegaK2
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]


Lua logo

This module depends on the following other modules:

Module for handling quest reward related data.

Subpages

--
-- Module for bestiary templates
--

local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs

local p = {}

-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------

local i18n = {
    errors = {
        invalid_table = 'Invalid table selected. Valid choices are either quest or vendor',
    },
    messages = {
        storage = 'Attempted to store rows %s to %s in "%s_rewards" table',
    },
}

-- ----------------------------------------------------------------------------
-- Cargo
-- ----------------------------------------------------------------------------

local tables = {}

tables.quest_rewards = {
    table = 'quest_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'Integer',
        },
        -- still needed?
        act = {
            field = 'act',
            type = 'Integer',
        },
        classes = {
            field = 'classes',
            type = 'String',
        },
        sockets = {
            field = 'sockets',
            type = 'Integer',
        },
        item_level = {
            field = 'item_level',
            type = 'Integer',
        },
        rarity = {
            field = 'rarity',
            type = 'String',
        },
        reward = {
            field = 'reward',
            type = 'Page',
        },
    },
}

tables.vendor_rewards = {
    table = 'vendor_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'Integer',
        },
        act = {
            field = 'act',
            type = 'Integer',
        },
        reward = {
            field = 'reward',
            type = 'Page',
        },
        npc = {
            field = 'npc',
            type = 'String',
        },
        classes = {
            field = 'classes',
            type = 'String',
        },
    }
}

-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------

-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_quest_rewards = m_util.cargo.declare_factory{data=tables.quest_rewards}
p.table_vendor_rewards = m_util.cargo.declare_factory{data=tables.vendor_rewards}

function p.store_data(frame)
    -- Get args
    tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    if tables[tpl_args.tbl .. '_rewards'] == nil then
        error(i18n.errors.invalid_table)
    end
    
    -- mw.loadData has some problems...
    local data = require(string.format('Module:Quest reward/data/%s', tpl_args.tbl))
    local imin = tpl_args.index_start or 1
    local imax = tpl_args.index_end or #data 
    for i=imin, imax or #data do 
        local row = data[i]
        if row == nil then
            break
        end
        -- get full table name
        row._table = tables[tpl_args.tbl .. '_rewards'].table
        m_util.cargo.store(frame, row)
    end
    
    return string.format(i18n.messages.storage, imin, imax, tpl_args.tbl)
end

-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------

return p