Arguments:

 * String - An item key name from G.items
 * Integer - (Optional) Quantity

Returns:

  * Promise

List of available key names: show_json(Object.keys(G.items))

Example usages:

buy("shoes"); buy("hpot0",100); buy("coat").then(function(data){ game_log("Got a new coat at the "+data.num+"th inventory slot!"); }); buy("shoes").then( function(data){ game_log("New shoes!"); }, function(data){ game_log("Can't buy shoes :("); }, );

Promise Reference:

"resolve"
{ name: "coat", num: 0, // Inventory slot 0 q: 1, // Quantity cost: 6000, // Gold spent }
"reject"
{ reason: "distance", // Too far away from an NPC }
{ reason: "not_buyable", // Can't buy this from an NPC }
{ reason: "space", // No inventory space }
{ reason: "cost", // Don't have enough gold }
{ reason: "bank", // If operation isn't allowed inside }

"source"