Module:Item table

From bg3.wiki
Jump to navigation Jump to search

Display a table of items queried from the weapons or equipment Cargo tables.

File tree

Usage

table (required)
Specify which Cargo table you are querying from. This is either weapons or equipment. Weapon and equipment tables have their own set of columns (see below).
where (required)
The SQL where clause to select items from the specified table.
columns (optional)
A comma-separated list of columns for the output table. The available options depend on whether this is an equipment table or weapon table.
For weapons tables
Default value: name_fancy, enchantment, damage, damage_type, weight, price, special
Available columns:
  • name: Simple, no-frills name.
  • name_fancy: Name and icon with a rarity colour-coded frame.
  • enchantment: The weapon's enchantment level (+1/+2/+3).
  • properties: The basic weapon properties like one-handed, finesse, reach, etc.
  • damage: Simple damage type display with colour-coded damage text, but no fancy templates.
  • damage_type: Damage type display with colour-coded text. Meant to be paired with damage.
  • damage_combined: A fancier damage display that combines the damage value and type into a single column.
  • damage_fancy: Like damage_combined, except it also shows damage dice and the total damage range of the weapon.
  • weight: The weight of the weapon in both kg and lb.
  • price: The base cost of the weapon (i.e. before any vendor price modifiers).
  • special: Special properties of the weapon such as passives or unique weapon actions.
  • where_to_find: Location(s) where this weapon can be found.
  • bugs: List any bugs associated with the weapon. For use on bug list pages.
For equipment tables
Default value: name_fancy, type, weight, price, special
Available columns:
  • name: Simple, no-frills name.
  • name_fancy: Name and icon with a rarity colour-coded frame.
  • type: The type of item (e.g. ring, medium armour, cloak, etc.). This also lists the required armour proficiency if it is not obvious from the item type.
  • enchantment: The weapon's enchantment level (+1/+2/+3).
  • armour_class: The AC of the item. This can be the base AC of an armour or the bonus AC from an item like a shield or magic robes.
  • stealth_disadvantage: Whether the item imposes disadvantage on stealth checks. This is only relevant for armours.
  • weight: The weight of the weapon in both kg and lb.
  • price: The base cost of the weapon (i.e. before any vendor price modifiers).
  • special: Special properties of the weapon such as passives or unique weapon actions.
  • where_to_find: Location(s) where this item can be found.
  • bugs: List any bugs associated with the item. For use on bug list pages.
order by (optional)
Default value: rarity_order, name
Set the default sort order of the table. This is a comma separated list of Cargo field names. The user is free to sort the table using the arrows on each column.
default (optional)
Default value: "No items found."
Text to insert in place of an empty table if the query returns no results.
limit (optional)
Set the max size of the table. If it exceeds this number, it will add a "View more" link to paginate the table.
offset (optional)
Default value: 0
Skip the first n results of the query. This is usually used with limit.

Weapon examples

Default table format

Markup
{{#invoke: Item table | main
| table = weapons
| where = name = "Nyrulna" OR name = "Voss' Silver Sword"
}}
Renders as
ItemEnch.DamageDamage
type
WeightPriceSpecial
Voss' Silver Sword+21d8 + 2
1d4
Slashing
Psychic
1.35 kg
2.7 lb
630
Interplanar Slayer
This weapon grants a +1d4 bonus to damage and Attack rollAttack rolls against githyanki, aberrations, fiends, and elementals.
Wrathful SmiteWrathful Smite (Action + Bonus Action)
Cast as a level 1 spell (Recharge: Long rest Recharge: Long rest.)
Nyrulna+31d6 + 3
1d6
Piercing
Thunder
1.8 kg
3.6 lb
840
Zephyr Connection
This weapon will return to your hand when thrown. You cannot be forced to drop the trident. When thrown, the weapon creates an explosion that deals 3d4ThunderThunder damage in a 6 m / 20 ft⁠6 m / 20 ft blast centered on the target.
Veil of the Wind
You gain a +3 m / 10 ft bonus to movement speed and jump distance. Equipping this weapon gives you Immunity to falling damage.
Nyrulna: GlowingNyrulna: Glowing
This object shines with a glowing light in a radius of 6 m / 20 ft⁠6 m / 20 ft.
Zephyr FlashZephyr Flash (Action)
Rush forward, creating an air vortex that blasts foes and possibly inflicts Bleeding Bleeding. (Recharge: Short rest Recharge: Short rest.)
Zephyr BreakZephyr Break (Action)
Zephyr Break imitates the effects of the spell Gust of Wind Gust of Wind while dealing thunder damage. (Recharge: Short rest Recharge: Short rest.)

Alternative table format

Markup
{{#invoke: Item table | main
| table = weapons
| where = name = "Nyrulna" OR name = "Voss' Silver Sword"
| columns = name_fancy, properties, enchantment, damage_combined, weight, price, special 
}}
Renders as
ItemPropertiesEnch.DamageWeightPriceSpecial
Voss' Silver SwordMartial
Versatile
+2
1d8 + 2SlashingSlashing
+ 1d4PsychicPsychic
1.35 kg
2.7 lb
630
Interplanar Slayer
This weapon grants a +1d4 bonus to damage and Attack rollAttack rolls against githyanki, aberrations, fiends, and elementals.
Wrathful SmiteWrathful Smite (Action + Bonus Action)
Cast as a level 1 spell (Recharge: Long rest Recharge: Long rest.)
NyrulnaMartial
Versatile
Thrown
+3
1d6 + 3PiercingPiercing
+ 1d6ThunderThunder
1.8 kg
3.6 lb
840
Zephyr Connection
This weapon will return to your hand when thrown. You cannot be forced to drop the trident. When thrown, the weapon creates an explosion that deals 3d4ThunderThunder damage in a 6 m / 20 ft⁠6 m / 20 ft blast centered on the target.
Veil of the Wind
You gain a +3 m / 10 ft bonus to movement speed and jump distance. Equipping this weapon gives you Immunity to falling damage.
Nyrulna: GlowingNyrulna: Glowing
This object shines with a glowing light in a radius of 6 m / 20 ft⁠6 m / 20 ft.
Zephyr FlashZephyr Flash (Action)
Rush forward, creating an air vortex that blasts foes and possibly inflicts Bleeding Bleeding. (Recharge: Short rest Recharge: Short rest.)
Zephyr BreakZephyr Break (Action)
Zephyr Break imitates the effects of the spell Gust of Wind Gust of Wind while dealing thunder damage. (Recharge: Short rest Recharge: Short rest.)

Comparison of different damage column options

Markup
{{#invoke: Item table | main
| table = weapons
| where = name = "Nyrulna" OR name = "Voss' Silver Sword"
| columns = name_fancy, damage, damage_type, damage_combined, damage_fancy
}}
Renders as
ItemDamageDamage
type
DamageDamage
Voss' Silver Sword1d8 + 2
1d4
Slashing
Psychic
1d8 + 2SlashingSlashing
+ 1d4PsychicPsychic
Damage: 4~14
1d8 + 2SlashingSlashing
+ 1d4PsychicPsychic
Nyrulna1d6 + 3
1d6
Piercing
Thunder
1d6 + 3PiercingPiercing
+ 1d6ThunderThunder
Damage: 5~15
1d6 + 3PiercingPiercing
+ 1d6ThunderThunder

Bug list example

Markup
{{#invoke: Item table | main
| table = weapons
| where = bugs IS NOT NULL AND (rarity = "legendary")
| columns = name_fancy, bugs
}}
Renders as
ItemBugs
Crimson Mischief
  • Despite being classed solely as a Shortsword, Scimitar proficiency also allows one to wield this weapon proficiently.

Equipment examples

Default table format

Markup
{{#invoke: Item table | main
| table = equipment
| where = rarity = "legendary" AND legacy IS NULL
}}
Renders as
ItemTypeWeightPriceSpecial
Gloves of Soul CatchingGloves0.5 kg
1 lb
960
Soul Fist
Your unarmed attacks deal an additional 1d10ForceForce damage.
Soul Catching
Once per turn, on an unarmed hit, you regain 10hit pointshit points. Alternatively, you may forego healing to gain a +5 bonus on an Attack rollAttack roll or Saving throwSaving throw until the end of your next turn.[See: Bugs]
Helldusk ArmourHeavy Armour20 kg
40 lb
8000
FlyFly (Bonus Action)
Cast as a level 3 spell (Recharge: Long rest Recharge: Long rest.)
Helldusk Armour
You are considered Proficient with this armour while wearing it.
Infernal Retribution
When you succeed a Saving throwSaving throw, the caster receives Burning (Orthonic)Burning (Orthonic) for 3 turns.
Prime Aegis of Fire
You have Resistance to FireFire damage and cannot be BurnedBurned. You take 3 less damage from all sources.
Helm of BalduranHelmets
(Medium Armour)
2 kg
4 lb
760
Balduran's Vitality
The helmet heals you 2hit pointshit points at the beginning of every turn.
Balduran's Favour
You have a +1 bonus to Armour ClassArmour Class and Saving throwSaving throws.
Stun Immunity
You can't be StunnedStunned.
Mask of the ShapeshifterHelmets0.5 kg
1 lb
1
Disguise Self Disguise Self (Action)
Cast as a level 1 spell at will.
Viconia's Walking FortressShields2.7 kg
5.4 lb
760
Bulwark Rebuke Bulwark Rebuke (Reaction)
When a foe hits you with a melee attack, deal it 2d4ForceForce and possibly knock it Prone Prone.
Reflective Shell Reflective Shell (Bonus Action)
A protective shell envelops you. It reflects any projectiles targeted at you back to their point of origin. ( Recharge: Short rest.)
Warding Bond Warding Bond (Action)
Cast as a level 2 spell ( Recharge: Long rest.)
Spellguard
You gain AdvantageAdvantage on Saving throwSaving throws against spells. Spell Attack Rolls against you have DisadvantageDisadvantage.

Armour example

Markup
{{#invoke: Item table | main
| table = equipment
| where = type LIKE "%Armour" AND legacy IS NULL and rarity = "very rare"
| columns = name_fancy, armour_class, stealth_disadvantage, weight, price, special
}}
Renders as
ItemArmour
Class
Stealth
disadvantage
WeightPriceSpecial
Adamantine Scale Mail16Yes12 kg
24 lb
1300
Magical Plate
All incoming damage is reduced by 1
Adamantine Backlash
When a melee attack hits you, the attacker is sent ReelingReeling for 2 turns.
Adamantine Splint Armour18Yes19 kg
38 lb
3800
Magical Plate
All incoming damage is reduced by 2.
Intense Adamantine Backlash
When a melee attack hits you, the Attacker is sent ReelingReeling for 3 turns.
Armour of Agility17No12 kg
24 lb
2900
Exotic Material
Add your full Dexterity Modifier to your Armour ClassArmour Class. Additionally, this armour does not impose DisadvantageDisadvantage on Stealth Ability Checks.
Armour of Landfall13No4.5 kg
9 lb
1700
Plant GrowthPlant Growth (Action)
Cast as a level 3 spell (Recharge: Short rest Recharge: Short rest.)
High Spellcasting
You gain a +1 bonus to Spell Save DC.
Green Bed Regeneration
When starting your turn on Plant GrowthPlant Growth or VinesVines regain 1d4hit pointshit points hit points.
Armour of Moonbasking11No4.5 kg
9 lb
1400
Lunar Bestial Vitality
You gain 22 temporary hit points 22 temporary hit points after casting Wild ShapeWild Shape. While those temporary hit points are active reduce all incoming damage by 1.
Lunar Bestial Fortitude
You have a +2 bonus to Armour ClassArmour Class. You also have AdvantageAdvantage on Saving throwSaving throws against spells. This effect persists while using your druidic Wild ShapeWild Shape ability.
Armour of Persistence20Yes20 kg
40 lb
6400
Magical Plate
All incoming damage is reduced by 2.
Legendary Persistence
You gain ResistanceResistance and Blade WardBlade Ward.
Armour of the Sporekeeper13No4.5 kg
9 lb
1050
Malefic Funghi
The wearer gains a +1 bonus to Spell Save DC and when dealing NecroticNecrotic damage, they deal an additional 1NecroticNecrotic Damage.
Spore Sacks
While imbued with Symbiotic EntitySymbiotic Entity, you can spread Bibberbang SporesBibberbang Spores, Timmask SporesTimmask Spores, and Haste SporesHaste Spores.
Bhaalist Armour14No5.85 kg
11.7 lb
2000
Aura of MurderAura of Murder
Enemies within 3 m / 10 ft become Vulnerable to PiercingPiercing damage, unless they are Immune to it.
Ambusher
Gain a +2 bonus to Initiative RollsInitiative Rolls.
Blackguard's Plate19Yes20 kg
40 lb
6400
Magical Plate
All incoming damage is reduced by 1
Dark Justiciar Half-Plate (Very Rare)17No12 kg
24 lb
2900
Shar's AegisShar's Aegis (Bonus Action)
Cast as a level 1 spell (Recharge: Long rest Recharge: Long rest.)
Shar's Umbrae
While obscured, the wearer has AdvantageAdvantage on Stealth Checks.
Shar's Protection
While the wearer has Shield of FaithShield of Faith active, reduce all incoming damage by 2 and reflect damage received back at the attacker, who takes 1d4NecroticNecrotic.
Elegant Studded Leather14No5.85 kg
11.7 lb
2000
Shield Shield (Reaction)
Cast as a level 1 spell ( Recharge: Short rest.)
Ambusher
Gain a +2 bonus to Initiative RollsInitiative Rolls.
Emblazoned Plate of the Marshal19Yes20 kg
40 lb
6400
Fire Shield Fire Shield (Action)
Cast as a level 4 spell ( Recharge: Long rest.)
Magical Plate
All incoming damage is reduced by 2.
Endurance by Fire
You have Resistance to FireFire damage and a +2 bonus to Saving throwSaving throws.
Flame Enamelled Armour16Yes12 kg
24 lb
2900
Fire Shield: Warm Fire Shield: Warm (Action)
Cast as a level 4 spell ( Recharge: Long rest.)
Seldom Caught Unawares
You gain a +2 bonus to Initiative rollsInitiative rolls.
Endurance by Fire
You have Resistance to FireFire damage and a +2 bonus to Saving throwSaving throws.
Reaper's Embrace19Yes20 kg
40 lb
6400
Howl of the Dead Howl of the Dead (Bonus Action)
Cast as a cantrip ( Recharge: Short rest.)
Magical Plate
All incoming damage is reduced by 2.
Reaper's RigidityReaper's Rigidity
When activated, you can't be moved against your will by any spell or action, but have DisadvantageDisadvantage on Dexterity Saving throwSaving throws.
Sharpened Snare Cuirass14No5.4 kg
10.8 lb
830
Exotic Material
Add your full Dexterity Modifier to your Armour ClassArmour Class. Additionally, this armour does not impose DisadvantageDisadvantage on Stealth Ability Checks.
Sharpened Snare
Creatures have DisadvantageDisadvantage on Saving throwSaving throws when resisting your attacks and spells that inflict RestrainedRestrained.

An item set example

Markup
{{#invoke: Item table | main
| table = equipment
| where = name LIKE "%Bonespike%"
| columns = name_fancy, type, special
}}
Renders as
ItemTypeSpecial
Bonespike BootsBoots
Brutal Leap Brutal Leap (Bonus Action + Movement Speed)
Leap at a target and possibly knock it Prone Prone. ( Recharge: Per turn.)
Evasive Instinct
You have a +1 bonus to Armour ClassArmour Class and Saving throwSaving throws as long as you are not wearing armour or holding a shield.
Refined Vaulting
JumpJump distance is increased by 1.5 m / 5 ft⁠1.5 m / 5 ft.
Bonespike GarbClothing
Slabjaw Determination
You gain 15 temporary hit points 15 temporary hit points whenever you RageRage.
Exoskeletal Endurance
Reduce all incoming damage by 2. When the wearer is struck by a melee attack, the attacker takes Constitution modifierPiercingPiercing damage.
Bonespike GlovesGloves
Exoskeletal Reinforcement
Your attacks ignore Resistance to SlashingSlashing, PiercingPiercing, and BludgeoningBludgeoning damage.
Bonespike HelmetHelmets
Menacing Attack (Melee)Menacing Attack (Melee) (Action)
Possibly Frighten Frighten your target. They'll have Disadvantage Icon.png Disadvantage on ability checks and Attack rolls and be unable to move. (Recharge: Per turn Recharge: Per turn.)
Fury In The Marrow
When you RageRage, hostile creatures in a 3 m / 10 ft radius must succeed a Weapon action DC Wisdom saving throwWisdom saving throw or take 2d4PsychicPsychic damage. The targets receive half damage on a save.

Bug list example

Markup
{{#invoke: Item table | main
| table = equipment
| where = bugs IS NOT NULL AND (rarity = "legendary")
| columns = name_fancy, bugs
}}
Renders as
ItemBugs
Helldusk Armour
  • As stated above, this item does not have a Proficiency Group (in order for all classes to be 'proficient' with it). However, as a result, items such as Bracers of Defence, Bonespike Boots, and Corellon's Grace that are not supposed to give their bonuses while wearing armour still provide their benefits with the Helldusk Armour equipped. The extra movement speed granted to monks by Unarmoured MovementUnarmoured Movement is also not lost when wearing this armour.
  • The DefenceDefence fighting style can grant up to +2 AC when used with this armour. For the same reason as above, Defence does not normally work with the Helldusk Armour as it is not considered armour proper. To work around this, the armour has a hidden passive that grants +1 AC if the wearer has Defence. While this property is not a bug, if the wearer also has another piece of armour equipped (e.g. a helmet), the normal +1 AC from Defence is additionally applied for a total of +2 AC, and this likely is a bug.

Item location example

Markup
{{#invoke: Item table | main
| table = equipment
| where = name = "Amulet of Restoration"
| columns = name_fancy, where_to_find
}}
Renders as
ItemWhere to find
Amulet of Restoration

Source code


local p = {}

-- Strip leading/trailing whitespace
local function strip(s)
	return string.match(s, "^%s*(.-)%s*$")
end

-- Prepare the HTML element for the table ready to be filled with rows
local function prepare_table(columns, table_data)
	local table_outer = mw.html.create("table")
		:addClass("wikitable")
		:addClass("sortable")
	local table_header = table_outer:tag("tr")
	for _, column in ipairs(columns) do
		local column_name = table_data.columns[column].name
		table_header:tag("th"):wikitext(column_name)
	end
	return table_outer
end

-- Produce the comma separated list of the cargo fields that need to be queried to
-- fill out the specified columns. This is passed into the query function.
local function field_string(columns, table_data)
	local query_fields = {}
	-- Produce a set from potentially overlapping lists of cargo fields
	for _, column_name in ipairs(columns) do
		local column = table_data.columns[column_name]
		for _, field in ipairs(column.cargo_fields) do
			query_fields[field] = true
		end
	end
	local query_str = {}
	for field, _ in pairs(query_fields) do
		table.insert(query_str, field) 
	end
	return table.concat(query_str, ', ')	
end

function p.main(frame)
	local args = frame.args

	local table_definitions = nil
	if args["table"] == "weapons" then
		table_definitions = require("Module:Item table/weapon columns")
	elseif args["table"] == "equipment" then
		table_definitions = require("Module:Item table/equipment columns")
	else
		mw.addWarning("Invalid table specified. Expected 'weapons' or 'equipment'.")
		return ""
	end

	-- Use either user-defined set of columns (specified as a comma-separated list)
	-- or the default set of columns defined for that type of table.
	local columns = {}
	for column in string.gmatch(args.columns or "", "[^,]+") do
		column = strip(column)
		if table_definitions.columns[column] then
			table.insert(columns, column)
		else
			mw.addWarning(string.format("Unknown column %s; skipping", column))
		end
	end
	if #columns == 0 then
		columns = table_definitions.default
	end
	
	-- Arguments passed into the mw.ext.cargo.query function.
	-- They have a different name convention (camelcase vs lowercase with spaces)
	local query_args = {
		where = args["where"],
		limit = args["limit"],
		offset = args["offset"],
		orderBy = args["order by"] or "rarity_order, name"
	}
	
	local results = mw.ext.cargo.query(
		args["table"],
		field_string(columns, table_definitions),
		query_args
	)
	
	if #results > 0 then
		local output_table = prepare_table(columns, table_definitions)
		for _, item in ipairs(results) do
			local row = output_table:tag('tr')
			for _, column_name in ipairs(columns) do
				local column = table_definitions.columns[column_name]
				row:node(column.formatter(item))
			end
		end
		return output_table
	else
		return args["default"] or "<div><i>No items found.</i></div>"
	end
end

return p