Functions to exchange two sets of arbitrary items.<<set
$inventory = {
"gold": 0,
"muffin vouchers": 3,
"muffins": 0
};
$standard = {"muffin vouchers": 1};
$greedy = {"muffin vouchers": 2};
>>[[Notes]]!! Notes
This began as a demonstration of a player inventory that could hold multiple items of the same type.
It gradually expanded to include some functions for exchanging arbitrary lists of items.
The original idea was to make a crafting system, but you could build a conventional shop by limiting your requirements to gold or some other currency.
The requirements and rewards are just objects with strings as keys and integers as values:
{{{
$inventory = {"muffin vouchers":3};
$muffin_requirement = {"muffin vouchers" : 1};
$muffin_reward = {"muffins": 1};
$setup.craft($muffin_requirement, $muffin_reward, $inventory);
}}}
<<return>><<include Inventory>>
<<include "Coupon Exchange">>
<<include "Greedy Coupon Exchange">>
<<include "Generous Coupon Exchange">>!! Inventory
<nobr><table>
<<for _item, _qty range $inventory>>
<<if _item == "gold" or _qty > 0>><tr><td>_qty</td><td>_item</td></tr><</if>>
<</for>></table></nobr>!! Coupon Exchange
Exchange vouchers for muffins here.
<<if setup.hasEnough($standard, $inventory);>>\
<<button "Trade 1 to 1">>\
<<run
setup.craft({"muffin vouchers": 1}, {"muffins":1}, $inventory);
Engine.play(passage());>>
<</button>><<else>><button class="macro-button" title="You need a voucher to get a muffin." disabled>Trade</button><</if>>!! Greedy Coupon Exchange
Exchange vouchers for muffins here.
<<if setup.hasEnough($greedy, $inventory);>>\
<<button "Trade 2 to 1">>\
<<run
setup.craft({"muffin vouchers": 2}, {"muffins":1}, $inventory);
Engine.play(passage());>>
<</button>><<else>><button class="macro-button" title="You need TWO vouchers to get a muffin." disabled>Trade</button><</if>>!! Generous Coupon Exchange
Exchange vouchers for muffins here.
<<if setup.hasEnough($standard, $inventory);>>\
<<button "Trade 1 to 2">>\
<<run
setup.craft({"muffin vouchers": 1}, {"muffins":2}, $inventory);
Engine.play(passage());>>
<</button>><<else>><button class="macro-button" title="You need a voucher to get two muffins." disabled>Trade</button><</if>>