boolean take_shop(int i, item it) {
int qty = shop_amount(it);
if(!have_shop()) {
print("You don't have a shop, so you can't take stuff from it!","red");
return false;
}
if(qty < 1) {
print("You don't have any "+it.to_plural()+" in your store!","red");
return false;
}
if(i > qty || i < 1) {
print("You can't take that many "+it.to_plural()+" from your store!","red");
return false;
}
if(i == 1) {
visit_url("managestore.php?action=take&whichitem="+it.to_int());
return true;
}
if(i == qty) {
visit_url("managestore.php?action=takeall&whichitem="+it.to_int());
return true;
}
buffer mall;
mall.append(visit_url("managestore.php"));
mall.delete(0, mall.index_of("Store Inventory:")+154);
mall.delete(mall.index_of("</table>"), mall.length());
string str = mall.substring(mall.index_of(it.to_string()),mall.length());
str = str.substring(str.index_of("</td><td>")+9,str.index_of("</td></tr>"));
string price = str.substring(0, str.index_of("</td><td>"));
string lim = str.substring(str.index_of("</td><td>")+9, str.index_of("</td><td><a href="));
if(lim=="<font size=1>(unlimited)</font> ") lim = "0";
visit_url("managestore.php?action=takeall&whichitem="+it.to_int());
return put_shop( price.to_int(), lim.to_int(), qty-i, it );
}