Module:Item2/cargo/sandbox

From Path of Exile Wiki
Jump to navigation Jump to search

This is the module sandbox page for Module:Item2/cargo (diff).

Module documentation[view] [edit] [history] [purge]


Lua logo

This module depends on the following other modules:

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 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('Item2')

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 = m_util.misc.get_args_raw(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_field 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_field.field] = range_field.type or field_data.type or 'Integer'
                        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_field in ipairs(c.range_fields) do
                    -- since there is no parent, the default is float
                    dcl_args[dps_data.field .. range_field.field] = range_field.type or 'Float'
                end
            end
        end

        if tpl_args.debug then
            mw.logObject(dcl_args)
        end
        return m_cargo.declare(dcl_args)
    end
end

-- ----------------------------------------------------------------------------
-- Cargo table schema
-- ----------------------------------------------------------------------------

c.schema = {}

c.schema.items = {
    table = 'items',
    fields = {
        html = core.map.html,
        infobox_html = core.map.infobox_html,
        metabox_html = core.map.metabox_html,
        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,
        is_in_game = core.map.is_in_game,
        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,
        acquisition_tags = core.map.acquisition_tags,
        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,
        is_account_bound = core.map.is_account_bound,
        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_searing_exarch_item = core.map.is_searing_exarch_item,
        is_eater_of_worlds_item = core.map.is_eater_of_worlds_item,
        is_veiled = core.map.is_veiled,
        is_replica = core.map.is_replica,
        is_corrupted = core.map.is_corrupted,
        is_unmodifiable = core.map.is_unmodifiable,
        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.schema.item_sell_prices = {
    table = 'item_sell_prices',
    fields = {
        amount = {
            field = 'amount',
            type = 'Integer',
        },
        name = {
            field = 'name',
            type = 'String',
        },
    },
}

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

c.schema.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_explicit = {
            field = 'is_explicit',
            type = 'Boolean',
        },
        is_map_fragment_bonus = {
            field = 'is_map_fragment_bonus',
            type = 'Boolean',
        },
        is_random = {
            field = 'is_random',
            type = 'Boolean',
        },
    },
}

c.schema.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',
        },
        mod_id = {
            field = 'mod_id',
            type = 'String',
        },
    },
}

-- There probably will be a table named "buffs" in the future, so "item_buffs" is the best solution here
c.schema.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.schema.amulets = {
    table = 'amulets',
    fields = {
        is_talisman = core.map.is_talisman,
        talisman_tier = core.map.talisman_tier,
    },
}

c.schema.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.schema.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.schema.armours = {
    table = 'armours',
    fields = {
        armour = core.map.armour,
        armour_min = core.map.armour_min,
        armour_max = core.map.armour_max,
        evasion = core.map.evasion,
        evasion_min = core.map.evasion_min,
        evasion_max = core.map.evasion_max,
        energy_shield = core.map.energy_shield,
        energy_shield_min = core.map.energy_shield_min,
        energy_shield_max = core.map.energy_shield_max,
        ward = core.map.ward,
        ward_min = core.map.ward_min,
        ward_max = core.map.ward_max,
        movement_speed = core.map.movement_speed,
    },
}

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

c.schema.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,
        is_vaal_skill_gem = core.map.is_vaal_skill_gem,
        vaal_variant_id = core.map.vaal_variant_id,
        support_gem_letter = core.map.support_gem_letter,
        support_gem_letter_html = core.map.support_gem_letter_html,
        is_awakened_support_gem = core.map.is_awakened_support_gem,
        awakened_variant_id = core.map.awakened_variant_id,
    },
}

c.schema.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.schema.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.schema.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.schema.stackables = {
    table = 'stackables',
    fields = {
        stack_size = core.map.stack_size,
        stack_size_currency_tab = core.map.stack_size_currency_tab,
    },
}

c.schema.cosmetic_items = {
    table = 'cosmetic_items',
    fields = {
        cosmetic_type = core.map.cosmetic_type,
        theme = core.map.cosmetic_theme,
        target = core.map.cosmetic_target,
    },
}

c.schema.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.schema.blight_items = {
    table = 'blight_items',
    fields = {
        tier = core.map.blight_item_tier,
    },
}

c.schema.hideout_doodads = {
    table = 'hideout_doodads',
    fields = {
        is_master_doodad = core.map.is_master_doodad,
        variation_count = core.map.variation_count,
    },
}

c.schema.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.schema.tattoos = {
    table = 'tattoos',
    fields = {
        target = core.map.tattoo_target,
        tribe = core.map.tattoo_tribe,
        tattoo_limit = core.map.tattoo_limit,
        min_adjacent = core.map.tattoo_min_adjacent,
        max_adjacent = core.map.tattoo_max_adjacent,
        skill_id = core.map.tattoo_skill_id,
    },
}

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

c.schema.jewels = {
    table = 'jewels',
    fields = {
        jewel_limit = core.map.jewel_limit,
        radius_html = core.map.jewel_radius_html,
    },
}

c.schema.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.schema.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.schema.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.schema.sentinels = {
    table = 'sentinels',
    fields = {
        duration = core.map.sentinel_duration,
        empowers = core.map.sentinel_empowers,
        empowerment = core.map.sentinel_empowerment,
        charge = core.map.sentinel_charge,
        monster = core.map.sentinel_monster,
        monster_level = core.map.sentinel_monster_level,
    },
}

c.schema.corpse_items = {
    table = 'corpse_items',
    fields = {
        tier = core.map.corpse_tier,
        monster_category = core.map.monster_category,
        monster_category_html = core.map.monster_category_html,
        monster_abilities = core.map.monster_abilities,
    },
}

c.schema.acquisition_recipes = {
    table = 'acquisition_recipes',
    fields = {
        recipe_id = {
            field = 'recipe_id',
            type = 'Integer',
        },
        result_amount = {
            field = 'result_amount',
            type = 'Integer',
        },
        description = {
            field = 'description',
            type = 'Text',
        },
        automatic = {
            field = 'automatic',
            type = 'Boolean',
        },
    }
}

c.schema.acquisition_recipe_parts = {
    table = 'acquisition_recipe_parts',
    fields = {
        recipe_id = {
            field = 'recipe_id',
            type = 'Integer',
        },
        part_id = {
            field = 'part_id',
            type = 'Integer',
        },
        item_id = {
            field = 'item_id',
            type = 'String',
        },
        item_name = {
            field = 'item_name',
            type = 'String',
        },
        item_page = {
            field = 'item_page',
            type = 'Page',
        },
        amount = {
            field = 'amount',
            type = 'Integer',
        },
        notes = {
            field = 'notes',
            type = 'Text',
        },
    }
}

c.schema.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.schema.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.schema.items)
p.table_item_sell_prices = h.declare_factory(c.schema.item_sell_prices)
p.table_item_purchase_costs = h.declare_factory(c.schema.item_purchase_costs)
p.table_item_mods = h.declare_factory(c.schema.item_mods)
p.table_item_stats = h.declare_factory(c.schema.item_stats)
p.table_item_buffs = h.declare_factory(c.schema.item_buffs)
p.table_amulets = h.declare_factory(c.schema.amulets)
p.table_flasks = h.declare_factory(c.schema.flasks)
p.table_weapons = h.declare_factory(c.schema.weapons)
p.table_armours = h.declare_factory(c.schema.armours)
p.table_shields = h.declare_factory(c.schema.shields)
p.table_skill_gems = h.declare_factory(c.schema.skill_gems)
p.table_maps = h.declare_factory(c.schema.maps)
p.table_atlas_maps = h.declare_factory(c.schema.atlas_maps)
p.table_atlas_connections = h.declare_factory(c.schema.atlas_connections)
p.table_stackables = h.declare_factory(c.schema.stackables)
p.table_cosmetic_items = h.declare_factory(c.schema.cosmetic_items)
p.table_essences = h.declare_factory(c.schema.essences)
p.table_blight_items = h.declare_factory(c.schema.blight_items)
p.table_hideout_doodads = h.declare_factory(c.schema.hideout_doodads)
p.table_prophecies = h.declare_factory(c.schema.prophecies)
p.table_tattoos = h.declare_factory(c.schema.tattoos)
p.table_divination_cards = h.declare_factory(c.schema.divination_cards)
p.table_jewels = h.declare_factory(c.schema.jewels)
p.table_harvest_seeds = h.declare_factory(c.schema.harvest_seeds)
p.table_harvest_plant_boosters = h.declare_factory(c.schema.harvest_plant_boosters)
p.table_heist_equipment = h.declare_factory(c.schema.heist_equipment)
p.table_sentinels = h.declare_factory(c.schema.sentinels)
p.table_corpse_items = h.declare_factory(c.schema.corpse_items)
p.table_acquisition_recipes = h.declare_factory(c.schema.acquisition_recipes)
p.table_acquisition_recipe_parts = h.declare_factory(c.schema.acquisition_recipe_parts)
p.table_quest_rewards = h.declare_factory(c.schema.quest_rewards)
p.table_vendor_rewards = h.declare_factory(c.schema.vendor_rewards)

function p.append_schema(tpl_args, tables)
    --[[
    This function adds specified table names to core.map. The range fields for 
    those tables are also appended to core.map.
    --]]
    for _, table_name in ipairs(tables) do
        local field_keys = m_util.table.keys(c.schema[table_name].fields)
        for _, k in ipairs(field_keys) do
            local field_data = c.schema[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 = {
                            inherit = 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.schema[table_name].fields[field_name] = data -- We're not using the schema again, so there's no need to update the schema with the added fields
                        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 = {
                            inherit = true,
                            table = table_name,
                            field = field_name,
                            -- dps values are floating points
                            type = range_field.type or 'Float',
                        }
                        -- c.schema[table_name].fields[field_name] = data
                        core.map[field_name] = data
                    end
                end
            end
        end
    end
end

--
-- Debug
--

function p.debug_print_tables(frame)
    for key, data in pairs(c.schema) do
        mw.logObject(data.table)
    end
end

return p