Path of Exile Wiki

Wiki поддерживается сообществом, поэтому подумайте над тем, чтобы внести свой вклад.

ПОДРОБНЕЕ

Path of Exile Wiki
Path of Exile Wiki
52 180
страниц
(Infobox formatting fix for weapon DPS)
Строка 80: Строка 80:
 
end
 
end
 
end
 
end
+
-- Weapons also get DPS fields
 
if dcl_args._table == 'weapons' then
 
if dcl_args._table == 'weapons' then
for _, dps_data in ipairs(core.dps_map) do
+
for _, dps_data in pairs(core.dps_map) do
 
for _, range_fields in ipairs(c.range_fields) do
 
for _, range_fields in ipairs(c.range_fields) do
 
-- since there is no parent, the default is float
 
-- since there is no parent, the default is float
Строка 691: Строка 691:
 
for _, range_field in ipairs(c.range_fields) do
 
for _, range_field in ipairs(c.range_fields) do
 
local field_name = stat_data.field .. range_field.field
 
local field_name = stat_data.field .. range_field.field
 
 
local data = {
 
local data = {
 
no_copy = true,
 
no_copy = true,
Строка 700: Строка 699:
 
type = range_field.type or field_data.type,
 
type = range_field.type or field_data.type,
 
}
 
}
 
 
c.cargo_tables[table_name].fields[field_name] = data
 
c.cargo_tables[table_name].fields[field_name] = data
 
core.map[field_name] = data
 
core.map[field_name] = data
Строка 708: Строка 706:
 
end
 
end
 
if table_name == 'weapons' then
 
if table_name == 'weapons' then
for _, dps_data in ipairs(core.dps_map) do
+
for _, dps_data in pairs(core.dps_map) do
 
for _, range_field in ipairs(c.range_fields) do
 
for _, range_field in ipairs(c.range_fields) do
 
local field_name = dps_data.field .. range_field.field
 
local field_name = dps_data.field .. range_field.field
 
 
local data = {
 
local data = {
 
no_copy = true,
 
no_copy = true,
Строка 719: Строка 716:
 
type = range_field.type or 'Float',
 
type = range_field.type or 'Float',
 
}
 
}
 
 
c.cargo_tables[table_name].fields[field_name] = data
 
c.cargo_tables[table_name].fields[field_name] = data
 
core.map[field_name] = data
 
core.map[field_name] = data

Версия 22:07, 9 июля 2021

Документация модуля[просмотр] [править] [история] [очистить]

This submodule exports functions for item table declaration. It also contains functions for use in Module:Item2 related to cargo tables.

-------------------------------------------------------------------------------
-- 
-- Cargo table declaration for Module:Item2
-- 
-------------------------------------------------------------------------------

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

-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox()

local core = use_sandbox and require('Module:Item2/core/sandbox') or require('Module:Item2/core')

local c = {}

c.range_fields = {
    {
        field = '_range_minimum',
        type = nil,
    },
    {
        field = '_range_maximum',
        type = nil,
    },
    {
        field = '_range_average',
        type = nil,
    },
        {
        field = '_range_text',
        type = 'Text',
    },
    {
        field = '_range_colour',
        type = 'String',
    },
    {
        field = '_html',
        type = 'Text',
    },
}

-- ----------------------------------------------------------------------------
-- Helper functions
-- ----------------------------------------------------------------------------

local h = {}

function h.declare_factory(data)
    -- Returns a function that can be called by templates to declare cargo tables
    --
    --  data: data table
    --   table: name of cargo table
    --   fields: associative table with:
    --    field: name of the field to declare
    --    type: type of the field
    return function(frame)
        local tpl_args = getArgs(frame, {
            parentFirst = true
        })
        frame = m_util.misc.get_frame(frame)
        
        local dcl_args = {}
        dcl_args._table = data.table
        for key, field_data in pairs(data.fields) do
            if field_data.field then
                dcl_args[field_data.field] = field_data.type
                for _, stat_data in pairs(core.stat_map) do
                    if stat_data.field == key then
                        for _, range_fields in ipairs(c.range_fields) do
                            -- if the type is nil, use the parent type
                            -- so this is set integer/float values correctly
                            dcl_args[stat_data.field .. range_fields.field] = range_fields.type or field_data.type
                        end
                        break
                    end
                end
            end
        end
        -- Weapons also get DPS fields
        if dcl_args._table == 'weapons' then
            for _, dps_data in pairs(core.dps_map) do
                for _, range_fields in ipairs(c.range_fields) do
                    -- since there is no parent, the default is float
                    dcl_args[dps_data.field .. range_fields.field] = range_fields.type or 'Float'
                end
            end
        end
        if tpl_args.debug then
            mw.logObject(dcl_args)
        end
        return m_cargo.declare(frame, dcl_args)
    end
end

-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------

c.cargo_tables = {}

c.cargo_tables.items = {
    table = 'items',
    fields = {
        html = core.map.html,
        html_extra = core.map.html_extra,
        implicit_stat_text = core.map.implicit_stat_text,
        explicit_stat_text = core.map.explicit_stat_text,
        stat_text = core.map.stat_text,
        class = core.map.class,
        class_id = core.map.class_id,
        rarity = core.map.rarity,
        rarity_id = core.map.rarity_id,
        name = core.map.name,
        size_x = core.map.size_x,
        size_y = core.map.size_y,
        drop_enabled = core.map.drop_enabled,
        drop_level = core.map.drop_level,
        drop_level_maximum = core.map.drop_level_maximum,
        drop_leagues = core.map.drop_leagues,
        drop_areas = core.map.drop_areas,
        drop_areas_html = core.map.drop_areas_html,
        drop_monsters = core.map.drop_monsters,
        drop_text = core.map.drop_text,
        -- sightly different because of strange DB issues
        drop_rarity_ids = core.map.drop_rarities_ids,
        required_level = core.map.required_level,
        required_level_final = core.map.required_level_final,
        required_dexterity = core.map.required_dexterity,
        required_strength = core.map.required_strength,
        required_intelligence = core.map.required_intelligence,
        inventory_icon = core.map.inventory_icon,
        alternate_art_inventory_icons = core.map.alternate_art_inventory_icons,
        buff_icon = core.map.buff_icon,
        cannot_be_traded_or_modified = core.map.cannot_be_traded_or_modified,
        help_text = core.map.help_text,
        flavour_text = core.map.flavour_text,
        flavour_text_id = core.map.flavour_text_id,
        tags = core.map.tags,
        metadata_id = core.map.metadata_id,
        influences = core.map.influences,
        is_fractured = core.map.is_fractured,
        is_synthesised = core.map.is_synthesised,
        is_veiled = core.map.is_veiled,
        is_replica = core.map.is_replica,
        is_corrupted = core.map.is_corrupted,
        is_relic = core.map.is_relic,
        is_fated = core.map.is_fated,
        is_drop_restricted = core.map.is_drop_restricted,
        quality = core.map.quality,
        base_item = core.map.base_item,
        base_item_id = core.map.base_item_id,
        base_item_page = core.map.base_item_page,
        frame_type = core.map.frame_type,
        name_list = core.map.name_list,
        description = core.map.description,
        release_version = core.map.release_version,
        removal_version = core.map.removal_version,
    },
}

c.cargo_tables.item_sell_prices = {
    table = 'item_sell_prices',
    fields = {
        amount = {
            field = 'amount',
            type = 'Integer',
        },
        name = {
            field = 'name',
            type = 'String',
        },
    },
}

c.cargo_tables.item_purchase_costs = {
    table = 'item_purchase_costs',
    fields = {
        amount = {
            field = 'amount',
            type = 'Integer',
        },
        name = {
            field = 'name',
            type = 'String',
        },
        rarity = {
            field = 'rarity',
            type = 'String',
        },
    },
}

c.cargo_tables.item_mods = {
    table = 'item_mods',
    fields = {
        id = {
            field = 'id',
            type = 'String',
        },
        stat_text = {
            field = 'text',
            type = 'Text',
        },
        is_implicit = {
            field = 'is_implicit',
            type = 'Boolean',
        },
        is_random = {
            field = 'is_random',
            type = 'Boolean',
        },
    },
}

c.cargo_tables.item_stats = {
    table = 'item_stats',
    fields = {
        id = {
            field = 'id',
            type = 'String',
        },
        min = {
            field = 'min',
            type = 'Integer',
        },
        max = {
            field = 'max',
            type = 'Integer',
        },
        avg = {
            field = 'avg',
            type = 'Integer',
        },
        is_implicit = {
            field = 'is_implicit',
            type = 'Boolean',
        },
        is_random = {
            field = 'is_random',
            type = 'Boolean',
        },
    },
}

-- There probably will be a table named "buffs" in the future, so "item_buffs" is the best solution here
c.cargo_tables.item_buffs = {
    table = 'item_buffs',
    fields = {
        id = core.map.buff_id,
        buff_values = core.map.buff_values,
        stat_text = core.map.buff_stat_text,
        icon = core.map.buff_icon,
    },
}

c.cargo_tables.amulets = {
    table = 'amulets',
    fields = {
        is_talisman = core.map.is_talisman,
        talisman_tier = core.map.talisman_tier,
    },
}

c.cargo_tables.flasks = {
    table = 'flasks',
    fields = {
        -- All flasks
        duration = core.map.flask_duration,
        charges_max = core.map.charges_max,
        charges_per_use = core.map.charges_per_use,
        -- Life/Mana/Hybrid flasks
        life = core.map.flask_life,
        mana = core.map.flask_mana,
    },
}

c.cargo_tables.weapons = {
    table = 'weapons',
    fields = {
        critical_strike_chance = core.map.critical_strike_chance,
        attack_speed = core.map.attack_speed,
        weapon_range = core.map.weapon_range,
        physical_damage_min = core.map.physical_damage_min,
        physical_damage_max = core.map.physical_damage_max,
        physical_damage_html = core.map.physical_damage_html,
        fire_damage_html = core.map.fire_damage_html,
        cold_damage_html = core.map.cold_damage_html,
        lightning_damage_html = core.map.lightning_damage_html,
        chaos_damage_html = core.map.chaos_damage_html,
        damage_avg = core.map.damage_avg,
        damage_html = core.map.damage_html,
        
        -- Values added via stat population
        fire_damage_min = core.map.fire_damage_min,
        fire_damage_max = core.map.fire_damage_max,
        cold_damage_min = core.map.cold_damage_min,
        cold_damage_max = core.map.cold_damage_max,
        lightning_damage_min = core.map.lightning_damage_min,
        lightning_damage_max = core.map.lightning_damage_max,
        chaos_damage_min = core.map.chaos_damage_min,
        chaos_damage_max = core.map.chaos_damage_max,
    },
}

c.cargo_tables.armours = {
    table = 'armours',
    fields = {
        armour = core.map.armour,
        energy_shield = core.map.energy_shield,
        evasion = core.map.evasion,
        movement_speed = core.map.movement_speed,
    },
}

c.cargo_tables.shields = {
    table = 'shields',
    fields = {
        block = core.map.block,
    }
}

c.cargo_tables.skill_gems = {
    table = 'skill_gems',
    fields = {
        gem_description = core.map.gem_description,
        dexterity_percent = core.map.dexterity_percent,
        strength_percent = core.map.strength_percent,
        intelligence_percent = core.map.intelligence_percent,
        primary_attribute = core.map.primary_attribute,
        gem_tags = core.map.gem_tags,
        -- Support Skill Gems
        support_gem_letter = core.map.support_gem_letter,
        support_gem_letter_html = core.map.support_gem_letter_html,
    },
}

c.cargo_tables.maps = {
    table = 'maps',
    fields = {
        tier = core.map.map_tier,
        guild_character = core.map.map_guild_character,
        unique_guild_character = core.map.unique_map_guild_character,
        area_id = core.map.map_area_id,
        unique_area_id = core.map.unique_map_area_id,
        series = core.map.map_series,
        
        -- REMOVE?
        area_level = core.map.map_area_level,
        unique_area_level = core.map.unique_map_area_level,
    },
}

c.cargo_tables.atlas_maps = {
    table = 'atlas_maps',
    fields = {
        x = core.map.atlas_x,
        y = core.map.atlas_y,
        region_id = core.map.atlas_region_id,
        region_minimum = core.map.atlas_region_minimum,
        x0 = core.map.atlas_x0,
        x1 = core.map.atlas_x1,
        x2 = core.map.atlas_x2,
        x3 = core.map.atlas_x3,
        x4 = core.map.atlas_x4,
        y0 = core.map.atlas_y0,
        y1 = core.map.atlas_y1,
        y2 = core.map.atlas_y2,
        y3 = core.map.atlas_y3,
        y4 = core.map.atlas_y4,
        map_tier0 = core.map.atlas_map_tier0,
        map_tier1 = core.map.atlas_map_tier1,
        map_tier2 = core.map.atlas_map_tier2,
        map_tier3 = core.map.atlas_map_tier3,
        map_tier4 = core.map.atlas_map_tier4,
    },
}

c.cargo_tables.atlas_connections = {
    table = 'atlas_connections',
    fields = {
        map1 = {
            field = 'map1',
            type = 'String',
        },
        map2 = {
            field = 'map2',
            type = 'String',
        },
        region0 = {
            field = 'region0',
            type = 'Boolean',
        },
        region1 = {
            field = 'region1',
            type = 'Boolean',
        },
        region2 = {
            field = 'region2',
            type = 'Boolean',
        },
        region3 = {
            field = 'region3',
            type = 'Boolean',
        },
        region4 = {
            field = 'region4',
            type = 'Boolean',
        },
    },
}

c.cargo_tables.stackables = {
    table = 'stackables',
    fields = {
        stack_size = core.map.stack_size,
        stack_size_currency_tab = core.map.stack_size_currency_tab,
        cosmetic_type = core.map.cosmetic_type,
    },
}

c.cargo_tables.essences = {
    table = 'essences',
    fields = {
        level_restriction = core.map.essence_level_restriction,
        level = core.map.essence_level,
        type = core.map.essence_type,
        category  = core.map.essence_category,
    },
}

c.cargo_tables.blight_items = {
    table = 'blight_items',
    fields = {
        tier = core.map.blight_item_tier,
    },
}

c.cargo_tables.hideout_doodads = {
    table = 'hideout_doodads',
    fields = {
        is_master_doodad = core.map.is_master_doodad,
        master = core.map.master,
        master_level_requirement = core.map.master_level_requirement,
        master_favour_cost = core.map.master_favour_cost,
        variation_count = core.map.variation_count,
    },
}

c.cargo_tables.prophecies = {
    table = 'prophecies',
    fields = {
        prophecy_id = core.map.prophecy_id,
        prediction_text = core.map.prediction_text,
        seal_cost = core.map.seal_cost,
        objective = core.map.prophecy_objective,
        reward = core.map.prophecy_reward,
    },
}

c.cargo_tables.divination_cards = {
    table = 'divination_cards',
    fields = {
        card_art = core.map.card_art,
    },
}

c.cargo_tables.jewels = {
    table = 'jewels',
    fields = {
        item_limit = core.map.item_limit,
        radius_html = core.map.jewel_radius_html,
    },
}

c.cargo_tables.incubators = {
    table = 'incubators',
    fields = {
        effect = core.map.incubator_effect,
    },
}

c.cargo_tables.harvest_seeds = {
    table = 'harvest_seeds', 
    fields = {
        effect = core.map.seed_effect,
        type_id = core.map.seed_type_id,
        type = core.map.seed_type,
        tier = core.map.seed_tier,
        growth_cycles = core.map.seed_growth_cycles,
        required_nearby_seed_tier = core.map.seed_required_nearby_seed_tier,
        required_nearby_seed_amount = core.map.seed_required_nearby_seed_amount,
        consumed_wild_lifeforce_percentage = core.map.seed_consumed_wild_lifeforce_percentage,
        consumed_vivid_lifeforce_percentage = core.map.seed_consumed_vivid_lifeforce_percentage,
        consumed_primal_lifeforce_percentage = core.map.seed_consumed_primal_lifeforce_percentage,
        granted_craft_option_ids = core.map.seed_granted_craft_option_ids,
    },
}

c.cargo_tables.harvest_plant_boosters = {
    table = 'harvest_plant_boosters',
    fields = {
        radius = core.map.plant_booster_radius,
        lifeforce = core.map.plant_booster_lifeforce,
        additional_crafting_options = core.map.plant_booster_additional_crafting_options,
        extra_chances = core.map.plant_booster_extra_chances,
    },
}

c.cargo_tables.heist_equipment = {
    table = 'heist_equipment',
    fields = {
        required_job_id = core.map.heist_required_job_id,
        required_job_level = core.map.heist_required_job_level,
    },
}

c.cargo_tables.upgraded_from_sets = {
    table = 'upgraded_from_sets',
    fields = {
        set_id = {
            field = 'set_id',
            type = 'Integer',
        },
        text = {
            field = 'text',
            type = 'Text',
        },
        automatic = {
            field = 'automatic',
            type = 'Boolean',
        },
    }
}

c.cargo_tables.upgraded_from_groups = {
    table = 'upgraded_from_groups',
    fields = {
        group_id = {
            field = 'group_id',
            type = 'Integer',
        },
        set_id = {
            field = 'set_id',
            type = 'Integer',
        },
        item_id = {
            field = 'item_id',
            type = 'String',
        },
        item_name = {
            field = 'item_name',
            type = 'String',
        },
        item_page = {
            field = 'item_page',
            type = 'Page',
        },
        integer = {
            field = 'amount',
            type = 'Integer',
        },
        notes = {
            field = 'notes',
            type = 'Text',
        },
    }
}

c.cargo_tables.quest_rewards = {
    table = 'quest_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'String',
        },
        -- still needed?
        act = {
            field = 'act',
            type = 'Integer',
        },
        classes = {
            field = 'classes',
            type = 'List (,) of String',
        },
        class_ids = {
            field = 'class_ids',
            type = 'List (,) of String',
        },
        sockets = {
            field = 'sockets',
            type = 'Integer',
        },
        item_level = {
            field = 'item_level',
            type = 'Integer',
        },
        rarity = {
            field = 'rarity',
            type = 'String',
        },
        notes = {
            field = 'notes',
            type = 'Text',
        },
    },
}

c.cargo_tables.vendor_rewards = {
    table = 'vendor_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'String',
        },
        act = {
            field = 'act',
            type = 'Integer',
        },
        npc = {
            field = 'npc',
            type = 'String',
        },
        classes = {
            field = 'classes',
            type = 'List (,) of String',
        },
        class_ids = {
            field = 'class_ids',
            type = 'List (,) of String',
        },
    }
}

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_items = h.declare_factory(c.cargo_tables.items)
p.table_item_sell_prices = h.declare_factory(c.cargo_tables.item_sell_prices)
p.table_item_purchase_costs = h.declare_factory(c.cargo_tables.item_purchase_costs)
p.table_item_mods = h.declare_factory(c.cargo_tables.item_mods)
p.table_item_stats = h.declare_factory(c.cargo_tables.item_stats)
p.table_item_buffs = h.declare_factory(c.cargo_tables.item_buffs)
p.table_amulets = h.declare_factory(c.cargo_tables.amulets)
p.table_flasks = h.declare_factory(c.cargo_tables.flasks)
p.table_weapons = h.declare_factory(c.cargo_tables.weapons)
p.table_armours = h.declare_factory(c.cargo_tables.armours)
p.table_shields = h.declare_factory(c.cargo_tables.shields)
p.table_skill_gems = h.declare_factory(c.cargo_tables.skill_gems)
p.table_maps = h.declare_factory(c.cargo_tables.maps)
p.table_atlas_maps = h.declare_factory(c.cargo_tables.atlas_maps)
p.table_atlas_connections = h.declare_factory(c.cargo_tables.atlas_connections)
p.table_stackables = h.declare_factory(c.cargo_tables.stackables)
p.table_essences = h.declare_factory(c.cargo_tables.essences)
p.table_blight_items = h.declare_factory(c.cargo_tables.blight_items)
p.table_hideout_doodads = h.declare_factory(c.cargo_tables.hideout_doodads)
p.table_prophecies = h.declare_factory(c.cargo_tables.prophecies)
p.table_divination_cards = h.declare_factory(c.cargo_tables.divination_cards)
p.table_jewels = h.declare_factory(c.cargo_tables.jewels)
p.table_incubators = h.declare_factory(c.cargo_tables.incubators)
p.table_harvest_seeds = h.declare_factory(c.cargo_tables.harvest_seeds)
p.table_harvest_plant_boosters = h.declare_factory(c.cargo_tables.harvest_plant_boosters)
p.table_heist_equipment = h.declare_factory(c.cargo_tables.heist_equipment)
p.table_upgraded_from_sets = h.declare_factory(c.cargo_tables.upgraded_from_sets)
p.table_upgraded_from_groups = h.declare_factory(c.cargo_tables.upgraded_from_groups)
p.table_quest_rewards = h.declare_factory(c.cargo_tables.quest_rewards)
p.table_vendor_rewards = h.declare_factory(c.cargo_tables.vendor_rewards)

function p.build_cargo_data(tpl_args, frame, item_classes)
    for _, table_name in ipairs(item_classes[tpl_args.class_id].tables) do
        -- Need to clone the table here because we'll be changing the table as we run though
        -- TODO: Optimize this?
        for k, _ in pairs(mw.clone(c.cargo_tables[table_name].fields)) do
            field_data = c.cargo_tables[table_name].fields[k]
            field_data.table = table_name
            for _, stat_data in pairs(core.stat_map) do
                if stat_data.field == k then
                    for _, range_field in ipairs(c.range_fields) do
                        local field_name = stat_data.field .. range_field.field
                        local data = {
                            no_copy = true,
                            table = table_name,
                            field = field_name,
                            -- if the type is nil, use the parent type
                            -- this is set integer/float values correctly
                            type = range_field.type or field_data.type,
                        }
                        c.cargo_tables[table_name].fields[field_name] = data
                        core.map[field_name] = data
                    end
                    break
                end
            end
            if table_name == 'weapons' then
                for _, dps_data in pairs(core.dps_map) do
                    for _, range_field in ipairs(c.range_fields) do
                        local field_name = dps_data.field .. range_field.field
                        local data = {
                            no_copy = true,
                            table = table_name,
                            field = field_name,
                            -- dps values are floating points
                            type = range_field.type or 'Float',
                        }
                        c.cargo_tables[table_name].fields[field_name] = data
                        core.map[field_name] = data
                    end
                end
            end
        end
    end
end

--
-- Debug
--

function p.debug_print_tables(frame)
    frame = m_util.misc.get_frame(frame)
    for key, data in pairs(c.cargo_tables) do
        mw.logObject(data.table)
    end
end

function p.debug_attach_test(frame)
    frame = m_util.misc.get_frame(frame)
    for key, data in pairs(c.cargo_tables) do
        m_cargo.attach(frame, {_table=data.table})
    end
end

return p