Module:Item/cargo: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
No edit summary  | 
				Mefisto1029 (talk | contribs)   (inherent_skills table)  | 
				||
| (52 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
-------------------------------------------------------------------------------  | -------------------------------------------------------------------------------  | ||
--    | --    | ||
-- Cargo table declaration for Module:  | -- Cargo table declaration for Module:Item  | ||
--    | --    | ||
-------------------------------------------------------------------------------  | -------------------------------------------------------------------------------  | ||
local m_util = require('Module:Util')  | local m_util = require('Module:Util')  | ||
local m_cargo = require('Module:Cargo')  | local m_cargo = require('Module:Cargo')  | ||
-- Should we use the sandbox version of our submodules?  | -- Should we use the sandbox version of our submodules?  | ||
local use_sandbox = m_util.misc.maybe_sandbox('  | local use_sandbox = m_util.misc.maybe_sandbox('Item')  | ||
local core = use_sandbox and require('Module:  | local core = use_sandbox and require('Module:Item/core/sandbox') or require('Module:Item/core')  | ||
local c = {}  | local c = {}  | ||
| Line 31: | Line 30: | ||
         {  |          {  | ||
         field = '_range_text',  |          field = '_range_text',  | ||
         type = '  |          type = 'String',  | ||
     },  |      },  | ||
     {  |      {  | ||
| Line 58: | Line 57: | ||
     --    type: type of the field  |      --    type: type of the field  | ||
     return function(frame)  |      return function(frame)  | ||
         local tpl_args   |          local tpl_args = m_util.misc.get_args_raw(frame)  | ||
         local dcl_args = {}  |          local dcl_args = {}  | ||
         dcl_args._table = data.table  |          dcl_args._table = data.table  | ||
| Line 70: | Line 65: | ||
                 for _, stat_data in pairs(core.stat_map) do  |                  for _, stat_data in pairs(core.stat_map) do  | ||
                     if stat_data.field == key then  |                      if stat_data.field == key then  | ||
                         for _,   |                          for _, range_field in ipairs(c.range_fields) do  | ||
                             -- if the type is nil, use the parent type  |                              -- if the type is nil, use the parent type  | ||
                             -- so this is set integer/float values correctly  |                              -- so this is set integer/float values correctly  | ||
                             dcl_args[stat_data.field ..   |                              dcl_args[stat_data.field .. range_field.field] = range_field.type or field_data.type or 'Integer'  | ||
                         end  |                          end  | ||
                         break  |                          break  | ||
| Line 83: | Line 78: | ||
         if dcl_args._table == 'weapons' then  |          if dcl_args._table == 'weapons' then  | ||
             for _, dps_data in pairs(core.dps_map) do  |              for _, dps_data in pairs(core.dps_map) do  | ||
                 for _,   |                  for _, range_field in ipairs(c.range_fields) do  | ||
                     -- since there is no parent, the default is float  |                      -- since there is no parent, the default is float  | ||
                     dcl_args[dps_data.field ..   |                      dcl_args[dps_data.field .. range_field.field] = range_field.type or 'Float'  | ||
                 end  |                  end  | ||
             end  |              end  | ||
         end  |          end  | ||
         if tpl_args.debug then  |          if tpl_args.debug then  | ||
             mw.logObject(dcl_args)  |              mw.logObject(dcl_args)  | ||
         end  |          end  | ||
         return m_cargo.declare(  |          return m_cargo.declare(dcl_args)  | ||
     end  |      end  | ||
end  | end  | ||
| Line 106: | Line 102: | ||
     fields = {  |      fields = {  | ||
         html = core.map.html,  |          html = core.map.html,  | ||
         infobox_html = core.map.infobox_html,  | |||
        metabox_html = core.map.metabox_html,  | |||
         implicit_stat_text = core.map.implicit_stat_text,  |          implicit_stat_text = core.map.implicit_stat_text,  | ||
         explicit_stat_text = core.map.explicit_stat_text,  |          explicit_stat_text = core.map.explicit_stat_text,  | ||
         stat_text = core.map.stat_text,  |          stat_text = core.map.stat_text,  | ||
        class_id = core.map.class_id,  | |||
         class = core.map.class,  |          class = core.map.class,  | ||
         is_in_game = core.map.is_in_game,  | |||
        rarity_id = core.map.rarity_id,  | |||
         rarity = core.map.rarity,  |          rarity = core.map.rarity,  | ||
         name = core.map.name,  |          name = core.map.name,  | ||
         size_x = core.map.size_x,  |          size_x = core.map.size_x,  | ||
| Line 125: | Line 123: | ||
         drop_monsters = core.map.drop_monsters,  |          drop_monsters = core.map.drop_monsters,  | ||
         drop_text = core.map.drop_text,  |          drop_text = core.map.drop_text,  | ||
         drop_rarity_ids = core.map.drop_rarities_ids,  |          drop_rarity_ids = core.map.drop_rarities_ids,  | ||
         required_level_base = core.map.required_level,  | |||
         required_level = core.map.required_level_final,  | |||
         required_dexterity = core.map.required_dexterity,  |          required_dexterity = core.map.required_dexterity,  | ||
         required_strength = core.map.required_strength,  |          required_strength = core.map.required_strength,  | ||
| Line 134: | Line 131: | ||
         inventory_icon = core.map.inventory_icon,  |          inventory_icon = core.map.inventory_icon,  | ||
         alternate_art_inventory_icons = core.map.alternate_art_inventory_icons,  |          alternate_art_inventory_icons = core.map.alternate_art_inventory_icons,  | ||
         cannot_be_traded_or_modified = core.map.cannot_be_traded_or_modified,  |          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,  |          help_text = core.map.help_text,  | ||
         flavour_text = core.map.flavour_text,  |          flavour_text = core.map.flavour_text,  | ||
         tags = core.map.tags,  |          tags = core.map.tags,  | ||
         metadata_id = core.map.metadata_id,  |          metadata_id = core.map.metadata_id,  | ||
| Line 144: | Line 140: | ||
         is_fractured = core.map.is_fractured,  |          is_fractured = core.map.is_fractured,  | ||
         is_synthesised = core.map.is_synthesised,  |          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_veiled = core.map.is_veiled,  | ||
         is_replica = core.map.is_replica,  |          is_replica = core.map.is_replica,  | ||
         is_corrupted = core.map.is_corrupted,  |          is_corrupted = core.map.is_corrupted,  | ||
         is_unmodifiable = core.map.is_unmodifiable,  | |||
         is_drop_restricted = core.map.is_drop_restricted,  |          is_drop_restricted = core.map.is_drop_restricted,  | ||
         quality = core.map.quality,  |          quality = core.map.quality,  | ||
| Line 176: | Line 173: | ||
}  | }  | ||
c.schema.item_purchase_costs = {  | --[[c.schema.item_purchase_costs = {  | ||
     table = 'item_purchase_costs',  |      table = 'item_purchase_costs',  | ||
     fields = {  |      fields = {  | ||
| Line 192: | Line 189: | ||
         },  |          },  | ||
     },  |      },  | ||
}  | }--]]  | ||
c.schema.item_mods = {  | c.schema.item_mods = {  | ||
| Line 201: | Line 198: | ||
             type = 'String',  |              type = 'String',  | ||
         },  |          },  | ||
         text = {  | |||
             field = 'text',  |              field = 'text',  | ||
             type = 'Text',  |              type = 'Text',  | ||
| Line 207: | Line 204: | ||
         is_implicit = {  |          is_implicit = {  | ||
             field = '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',  |              type = 'Boolean',  | ||
         },  |          },  | ||
| Line 235: | Line 240: | ||
             type = 'Integer',  |              type = 'Integer',  | ||
         },  |          },  | ||
         mod_id = {  | |||
             field = '  |              field = 'mod_id',  | ||
             type = '  |              type = 'String',  | ||
         },  |          },  | ||
     },  |      },  | ||
| Line 268: | Line 269: | ||
     table = 'flasks',  |      table = 'flasks',  | ||
     fields = {  |      fields = {  | ||
         duration = core.map.flask_duration,  |          duration = core.map.flask_duration,  | ||
         charges_max = core.map.charges_max,  |          charges_max = core.map.charges_max,  | ||
         charges_per_use = core.map.charges_per_use,  |          charges_per_use = core.map.charges_per_use,  | ||
         life = core.map.flask_life,  |          life = core.map.flask_life,  | ||
         mana = core.map.flask_mana,  |          mana = core.map.flask_mana,  | ||
| Line 284: | Line 283: | ||
         attack_speed = core.map.attack_speed,  |          attack_speed = core.map.attack_speed,  | ||
         weapon_range = core.map.weapon_range,  |          weapon_range = core.map.weapon_range,  | ||
        reload_time = core.map.reload_time,  | |||
         physical_damage_min = core.map.physical_damage_min,  |          physical_damage_min = core.map.physical_damage_min,  | ||
         physical_damage_max = core.map.physical_damage_max,  |          physical_damage_max = core.map.physical_damage_max,  | ||
| Line 293: | Line 293: | ||
         damage_avg = core.map.damage_avg,  |          damage_avg = core.map.damage_avg,  | ||
         damage_html = core.map.damage_html,  |          damage_html = core.map.damage_html,  | ||
        spirit = core.map.spirit,  | |||
         -- Values added via stat population  |          -- Values added via stat population  | ||
| Line 310: | Line 311: | ||
     fields = {  |      fields = {  | ||
         armour = core.map.armour,  |          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 = 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 = core.map.ward,  | ||
        ward_min = core.map.ward_min,  | |||
        ward_max = core.map.ward_max,  | |||
         movement_speed = core.map.movement_speed,  |          movement_speed = core.map.movement_speed,  | ||
     },  |      },  | ||
| Line 333: | Line 342: | ||
         primary_attribute = core.map.primary_attribute,  |          primary_attribute = core.map.primary_attribute,  | ||
         gem_tags = core.map.gem_tags,  |          gem_tags = core.map.gem_tags,  | ||
         gem_tier = core.map.gem_tier,  | |||
        equipment_requirement = core.map.equipment_requirement,  | |||
        support_gem_category = core.map.support_gem_category,  | |||
        is_vaal_skill_gem = core.map.is_vaal_skill_gem,  | |||
        vaal_variant_id = core.map.vaal_variant_id,  | |||
         is_awakened_support_gem = core.map.is_awakened_support_gem,  | |||
         awakened_variant_id = core.map.awakened_variant_id,  | |||
     },  |      },  | ||
}  | |||
c.schema.inherent_skills = {  | |||
    table = 'inherent_skills',  | |||
    fields = {  | |||
        inherent_skills_text = core.map.inherent_skills_text,  | |||
        inherent_skills_ids = core.map.inherent_skills_ids,  | |||
    }  | |||
}  | }  | ||
| Line 419: | Line 440: | ||
         stack_size = core.map.stack_size,  |          stack_size = core.map.stack_size,  | ||
         stack_size_currency_tab = core.map.stack_size_currency_tab,  |          stack_size_currency_tab = core.map.stack_size_currency_tab,  | ||
    },  | |||
}  | |||
c.schema.map_fragments = {  | |||
    table = 'map_fragments',  | |||
    fields = {  | |||
        map_fragment_limit = core.map.map_fragment_limit,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 426: | Line 454: | ||
     fields = {  |      fields = {  | ||
         cosmetic_type = core.map.cosmetic_type,  |          cosmetic_type = core.map.cosmetic_type,  | ||
        theme = core.map.cosmetic_theme,  | |||
        target = core.map.cosmetic_target,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 439: | Line 469: | ||
}  | }  | ||
c.schema.  | c.schema.liquid_emotions = {  | ||
     table = '  |      table = 'liquid_emotions',  | ||
     fields = {  |      fields = {  | ||
         tier = core.map.  |          tier = core.map.liquid_emotion_tier,  | ||
        modifier = core.map.liquid_emotion_mod,  | |||
        stat_text = core.map.liquid_emotion_stat_text,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 450: | Line 482: | ||
     fields = {  |      fields = {  | ||
         is_master_doodad = core.map.is_master_doodad,  |          is_master_doodad = core.map.is_master_doodad,  | ||
         variation_count = core.map.variation_count,  |          variation_count = core.map.variation_count,  | ||
     },  |      },  | ||
| Line 465: | Line 494: | ||
         objective = core.map.prophecy_objective,  |          objective = core.map.prophecy_objective,  | ||
         reward = core.map.prophecy_reward,  |          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,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 472: | Line 513: | ||
     fields = {  |      fields = {  | ||
         card_art = core.map.card_art,  |          card_art = core.map.card_art,  | ||
        card_background = core.map.card_background,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 478: | Line 520: | ||
     table = 'jewels',  |      table = 'jewels',  | ||
     fields = {  |      fields = {  | ||
         jewel_limit = core.map.jewel_limit,  | |||
         radius_html = core.map.jewel_radius_html,  |          radius_html = core.map.jewel_radius_html,  | ||
     },  |      },  | ||
}  | }  | ||
| Line 522: | Line 557: | ||
         required_job_id = core.map.heist_required_job_id,  |          required_job_id = core.map.heist_required_job_id,  | ||
         required_job_level = core.map.heist_required_job_level,  |          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.allflame_embers = {  | |||
    table = 'allflame_embers',  | |||
    fields = {  | |||
        pack_id = core.map.pack_id,  | |||
        pack_size = core.map.pack_size,  | |||
        pack_min_size = core.map.pack_min_size,  | |||
        pack_max_size = core.map.pack_max_size,  | |||
        pack_leader_chance = core.map.pack_leader_chance,  | |||
     },  |      },  | ||
}  | }  | ||
| Line 530: | Line 598: | ||
         recipe_id = {  |          recipe_id = {  | ||
             field = 'recipe_id',  |              field = 'recipe_id',  | ||
             type = 'Integer',  |              type = 'Integer',  | ||
         },  |          },  | ||
| Line 560: | Line 624: | ||
         part_id = {  |          part_id = {  | ||
             field = 'part_id',  |              field = 'part_id',  | ||
             type = 'Integer',  |              type = 'Integer',  | ||
         },  |          },  | ||
         item_id = {  |          item_id = {  | ||
             field = 'item_id',  |              field = 'item_id',  | ||
             type = 'String',  |              type = 'String',  | ||
         },  |          },  | ||
| Line 674: | Line 730: | ||
p.table_items = h.declare_factory(c.schema.items)  | 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_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_purchase_costs = h.declare_factory(c.schema.item_purchase_costs)  | ||
p.table_item_mods = h.declare_factory(c.schema.item_mods)  | 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_stats = h.declare_factory(c.schema.item_stats)  | ||
| Line 684: | Line 740: | ||
p.table_shields = h.declare_factory(c.schema.shields)  | p.table_shields = h.declare_factory(c.schema.shields)  | ||
p.table_skill_gems = h.declare_factory(c.schema.skill_gems)  | p.table_skill_gems = h.declare_factory(c.schema.skill_gems)  | ||
p.table_inherent_skills = h.declare_factory(c.schema.inherent_skills)  | |||
p.table_maps = h.declare_factory(c.schema.maps)  | p.table_maps = h.declare_factory(c.schema.maps)  | ||
p.table_atlas_maps = h.declare_factory(c.schema.atlas_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_atlas_connections = h.declare_factory(c.schema.atlas_connections)  | ||
p.table_stackables = h.declare_factory(c.schema.stackables)  | p.table_stackables = h.declare_factory(c.schema.stackables)  | ||
p.table_map_fragments = h.declare_factory(c.schema.map_fragments)  | |||
p.table_cosmetic_items = h.declare_factory(c.schema.cosmetic_items)  | p.table_cosmetic_items = h.declare_factory(c.schema.cosmetic_items)  | ||
p.table_essences = h.declare_factory(c.schema.essences)  | p.table_essences = h.declare_factory(c.schema.essences)  | ||
p.  | p.table_liquid_emotions = h.declare_factory(c.schema.liquid_emotions)  | ||
p.table_hideout_doodads = h.declare_factory(c.schema.hideout_doodads)  | p.table_hideout_doodads = h.declare_factory(c.schema.hideout_doodads)  | ||
p.table_prophecies = h.declare_factory(c.schema.prophecies)  | 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_divination_cards = h.declare_factory(c.schema.divination_cards)  | ||
p.table_jewels = h.declare_factory(c.schema.jewels)  | p.table_jewels = h.declare_factory(c.schema.jewels)  | ||
p.table_harvest_seeds = h.declare_factory(c.schema.harvest_seeds)  | 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_harvest_plant_boosters = h.declare_factory(c.schema.harvest_plant_boosters)  | ||
p.table_heist_equipment = h.declare_factory(c.schema.heist_equipment)  | 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_allflame_embers = h.declare_factory(c.schema.allflame_embers)  | |||
p.table_acquisition_recipes = h.declare_factory(c.schema.acquisition_recipes)  | 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_acquisition_recipe_parts = h.declare_factory(c.schema.acquisition_recipe_parts)  | ||
| Line 704: | Line 765: | ||
p.table_vendor_rewards = h.declare_factory(c.schema.vendor_rewards)  | p.table_vendor_rewards = h.declare_factory(c.schema.vendor_rewards)  | ||
function p.append_schema(tpl_args  | function p.append_schema(tpl_args, tables)  | ||
     --[[  |      --[[  | ||
     This function adds specified table names to core.map. The range fields for    |      This function adds specified table names to core.map. The range fields for    | ||
| Line 749: | Line 810: | ||
             end  |              end  | ||
         end  |          end  | ||
     end  |      end  | ||
end  | end  | ||
return p  | return p  | ||
Latest revision as of 07:45, 8 September 2025
This submodule exports functions for item table declaration. It also contains functions for use in Module:Item related to cargo tables.
The above documentation is transcluded from Module:Item/cargo/doc. 
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-------------------------------------------------------------------------------
-- 
-- Cargo table declaration for Module:Item
-- 
-------------------------------------------------------------------------------
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('Item')
local core = use_sandbox and require('Module:Item/core/sandbox') or require('Module:Item/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 = 'String',
    },
    {
        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_id = core.map.class_id,
        class = core.map.class,
        is_in_game = core.map.is_in_game,
        rarity_id = core.map.rarity_id,
        rarity = core.map.rarity,
        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,
        drop_rarity_ids = core.map.drop_rarities_ids,
        required_level_base = core.map.required_level,
        required_level = 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,
        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,
        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',
        },
        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 = {
        duration = core.map.flask_duration,
        charges_max = core.map.charges_max,
        charges_per_use = core.map.charges_per_use,
        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,
        reload_time = core.map.reload_time,
        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,
        spirit = core.map.spirit,
        
        -- 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,
        gem_tier = core.map.gem_tier,
        equipment_requirement = core.map.equipment_requirement,
        support_gem_category = core.map.support_gem_category,
        is_vaal_skill_gem = core.map.is_vaal_skill_gem,
        vaal_variant_id = core.map.vaal_variant_id,
        is_awakened_support_gem = core.map.is_awakened_support_gem,
        awakened_variant_id = core.map.awakened_variant_id,
    },
}
c.schema.inherent_skills = {
    table = 'inherent_skills',
    fields = {
        inherent_skills_text = core.map.inherent_skills_text,
        inherent_skills_ids = core.map.inherent_skills_ids,
    }
}
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.map_fragments = {
    table = 'map_fragments',
    fields = {
        map_fragment_limit = core.map.map_fragment_limit,
    },
}
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.liquid_emotions = {
    table = 'liquid_emotions',
    fields = {
        tier = core.map.liquid_emotion_tier,
        modifier = core.map.liquid_emotion_mod,
        stat_text = core.map.liquid_emotion_stat_text,
    },
}
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.allflame_embers = {
    table = 'allflame_embers',
    fields = {
        pack_id = core.map.pack_id,
        pack_size = core.map.pack_size,
        pack_min_size = core.map.pack_min_size,
        pack_max_size = core.map.pack_max_size,
        pack_leader_chance = core.map.pack_leader_chance,
    },
}
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_inherent_skills = h.declare_factory(c.schema.inherent_skills)
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_map_fragments = h.declare_factory(c.schema.map_fragments)
p.table_cosmetic_items = h.declare_factory(c.schema.cosmetic_items)
p.table_essences = h.declare_factory(c.schema.essences)
p.table_liquid_emotions = h.declare_factory(c.schema.liquid_emotions)
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_allflame_embers = h.declare_factory(c.schema.allflame_embers)
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
return p