From Dark and Darker Wiki

(Added logic to generate tables with a manually provided list of items. This is used in template:craftable)
(Updated to us item property incraftingrecipe)
Line 1: Line 1:
<includeonly><!--
<includeonly><!--


Create the crafting rows and store them in the var:rows
If @arg:2 has text
-->{{#arraydefine:craftables|{{Merchant Data|{{{1}}}|Crafts|All}} }}<!--
-->{{#if:{{{2|}}}<!--
-->{{#if:{{{2|}}}|{{#arraydefine:craftables|{{{2}}}}} }}<!--
Use @arg:2
-->{{#vardefine:rows|<!--
-->|{{#arraydefine:craftables|{{{2}}}}}<!--
Else if an @arg:ingredient was provided
-->|{{#if:{{{ingredient|}}}<!--
AND the @arg:ingredient is NOT used in a crafting recipe(s)
-->|{{#if:{{{{{ingredientcategory|Misc}}} Data|{{{ingredient|}}}|incraftingrecipe}}<!--
-->|{{#arraydefine:craftables|{{Merchant Data|{{{1}}}|Crafts|All}}}}<!--
Set the craftables array to empty
-->|{{#arraydefine:craftables|}}}}<!--
Otherwise use the entire crafts list for the given merchant
-->|{{#arraydefine:craftables|{{Merchant Data|{{{1}}}|Crafts|All}}}}}}}}<!--
 
--><table cellspacing="0" class="wikitable sortable jquery-tablesorter" style="width:70%; min-width:500px; text-align:center; vertical-align:middle; {{#ifeq:{{#arraysize:craftables}}|0|display:none;}}"><!--
--><tr><th style="width:3%">Name</th><th style="width:5%">Ingredients</th><th style="width:2%">Merchant</th></tr><!--
-->{{#loop:i|0|{{#arraysize:craftables}}<!--
-->{{#loop:i|0|{{#arraysize:craftables}}<!--
-->|{{#vardefine:craft|{{#arrayindex:craftables|{{#var:i}} }} }}<!--
-->|<tr><!-- Generate a crafting row for each element in @array:craftables
If the ingredient is in the list of ingredients for the craft
-->{{#vardefine:craft|{{#arrayindex:craftables|{{#var:i}}}}}}<!--
OR the ingredient is empty, generate the crafting row.
If @arg:ingredient is in the list of ingredients for @var:craft
-->{{#if:  {{#pos:{{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|ingredients}}|{{{ingredient|}}}}}<!--
OR @arg:ingredient is empty
-->{{#if:{{{ingredient|}}}||continue}}<!--
-->{{#if:  {{#pos:{{#vardefineecho:ingredients|{{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|ingredients}} }}|{{{ingredient| }}}}}<!--
-->|{{#arraydefine:ingredients|{{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|ingredients}} }}<!--
-->{{#if:{{{ingredient| }}}||continue}}<!--
-->{{#vardefine:rarity|{{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|rarity}} }}<!--
-->|{{#vardefine:rarity|{{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|rarity}} }}<!--
--><tr>
-->{{#arraydefine:ingredients|{{#var:ingredients}} }}<!--
<td>{{Iconbox|<!--
--><td>{{Iconbox<!--
-->{{#if:{{#pos:{{#var:craft}}|Potion}}<!--
-->|{{#if:{{#pos:{{#var:craft}}|Potion}}<!--
-->|{{#explode:{{#var:craft}}| |1|2}}<!--
-->|{{#explode:{{#var:craft}}| |1|2}}<!--
-->|{{#var:craft}} }}<!--
-->|{{#var:craft}} }}<!--
-->|size=x100px<!--
-->|size =x100px<!--
-->|amount={{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|quantity}}<!--
-->|amount ={{Merchant Data|{{{1}}}|Crafts|{{#var:craft}}|quantity}}<!--
-->|caption=<span class="colorrarity{{#var:rarity}}">{{#var:craft}}</span><!--
-->|caption =<span class="colorrarity{{#var:rarity}}">{{#var:craft}}</span><!--
-->|rarity={{#var:rarity}} }}</td>
-->|rarity ={{#var:rarity}} }}</td><!--
<td>{{#loop:i|0|{{#arraysize:ingredients}}<!--
--><td>{{#loop:i|0|{{#arraysize:ingredients}}<!--
-->|{{#vardefine:ingredient|{{#arrayindex:ingredients|{{#var:i}} }} }}<!--
-->|{{#vardefine:ingredient|{{#arrayindex:ingredients|{{#var:i}} }} }}<!--
-->{{Iconbox|<!--
-->{{Iconbox|<!--
-->{{#explode:{{#var:ingredient}}|-|1}}<!--
-->{{#explode:{{#var:ingredient}}|-|1}}<!--
-->|size=x100px<!--
-->|size =x100px<!--
-->|caption=no<!--
-->|caption =no<!--
-->|amount={{#explode:{{#var:ingredient}}|-|0}}<!--
-->|amount ={{#explode:{{#var:ingredient}}|-|0}}<!--
-->|rarity=<!--
-->|rarity=<!--
-->{{#if:{{#explode:{{#var:ingredient}}|-|2}}<!--
-->{{#if:{{#explode:{{#var:ingredient}}|-|2}}<!--
-->|{{#explode:{{#var:ingredient}}|-|2}}<!--
-->|{{#explode:{{#var:ingredient}}|-|2}}<!--
-->|{{Misc Data|{{#explode:{{#var:ingredient}}|-|1}}|Rarities}} }} }} }}</td>
-->|{{Misc Data|{{#explode:{{#var:ingredient}}|-|1}}|Rarities}} }} }} }}</td><!--
<td>[[{{{1}}}]]</td></tr>}} }} }}<!--
--><td>[[{{{1}}}]]</td>}}</tr>}}</table><!--
 
Use the var:rows to check if we want to display the table.
--><table cellspacing="0" class="wikitable sortable jquery-tablesorter" style="width:55%; min-width:500px; background:transparent; text-align:center; vertical-align:middle; {{#if:{{#var:rows}}||display:none;}}"><!--
--><tr style="font-weight:bold; {{#if:{{{header|}}}||display:none;}}"><th style="width:15%">Name</th><th style="width:25%">Ingredients</th><th style="width:10%">Trader</th></tr><!--
-->{{#var:rows}}</table><!--


--></includeonly><noinclude>
--></includeonly><noinclude>
==Example==
==Example==
<pre>{{GenerateCraftingTable|Weaponsmith|header=yes|ingredient=Cyclops's Club}}</pre>
<pre>{{GenerateCraftingTable|Weaponsmith|ingredient=Longsword|ingredientcategory=Weapon}}</pre>
{{GenerateCraftingTable|Weaponsmith|header=yes|ingredient=Cyclops's Club}}
{{GenerateCraftingTable|Weaponsmith|ingredient=Longsword|ingredientcategory=Weapon}}
==Example==
==Example==
<pre>{{GenerateCraftingTable|Weaponsmith|header=yes|Sterling Blade}}</pre>
<pre>{{GenerateCraftingTable|Weaponsmith|ingredient=Cyclops's Club}}</pre>
{{GenerateCraftingTable|Weaponsmith|header=yes|Sterling Blade}}
{{GenerateCraftingTable|Weaponsmith|ingredient=Cyclops's Club}}
==Example==
==Example==
<pre>{{GenerateCraftingTable|Alchemist|header=yes}}</pre>
<pre>{{GenerateCraftingTable|Weaponsmith|Sterling Blade}}</pre>
{{GenerateCraftingTable|Alchemist|header=yes}}
{{GenerateCraftingTable|Weaponsmith|Sterling Blade}}
==Example==
==Example==
<pre>{{GenerateCraftingTable|Alchemist}}</pre>
<pre>{{GenerateCraftingTable|Alchemist}}</pre>

Revision as of 03:48, 23 June 2024

Example

{{GenerateCraftingTable|Weaponsmith|ingredient=Longsword|ingredientcategory=Weapon}}

Example

{{GenerateCraftingTable|Weaponsmith|ingredient=Cyclops's Club}}

Example

{{GenerateCraftingTable|Weaponsmith|Sterling Blade}}
NameIngredientsMerchant
Longsword1
Silver Powder1
Weaponsmith

Example

{{GenerateCraftingTable|Alchemist}}
NameIngredientsMerchant
Iron Ore2
Alchemist
Copper Ore2
Alchemist
Cobalt Ore2
Alchemist
Rubysilver Ore2
Alchemist
Silver Coin45
Alchemist
Gold Ore2
Alchemist
Froststone Ore2
Alchemist
Cockatrice's Lucky Feather1
Wolf Fang2
Wolf Claw3
Gold Coin300
Alchemist
Gold Ingot1
Golden Teeth5
Gold Coin300
Alchemist
Frozen Heart1
Cobalt Ingot2
Gold Coin300
Alchemist
Lifeleaf1
Alchemist
Lifeleaf1
Alchemist
Lifeleaf1
Alchemist
Lifeleaf5
Alchemist
Phantom Flower1
Alchemist
Phantom Flower1
Alchemist
Phantom Flower1
Alchemist
Phantom Flower5
Alchemist
Wardweed1
Alchemist
Wardweed1
Alchemist
Wardweed1
Alchemist
Wardweed5
Alchemist
Lifeleaf1
Wardweed1
Alchemist
Lifeleaf1
Wardweed1
Alchemist
Lifeleaf1
Wardweed1
Alchemist
Phantom Flower1
Blue Eyeballs1
Alchemist
Lifeleaf1
Rotten Fluids1
Alchemist
Frozen Heart1
Glowing Blue Ice Eyes1
Alchemist
Demon Blood1
Armor Scrap2
Alchemist
Volcanic Ash1
Intact Skull6
Bone6
Alchemist
Token of Honor1
Rusty Broken Sword6
Bone6
Alchemist

Example

{{GenerateCraftingTable|Alchemist|ingredient=Silver Ore}}