View Full Version : Price of an item in my own mall shop
StoreKeeper
09-24-2010, 07:06 PM
Is there any function/script to return the current price of an item I have in my own mall store? I went looking for it and have not found anything that will return my store's price.
mredge73
03-01-2011, 08:29 PM
I am working on this but I need some help on the matcher. I had to create 3 matchers and I am unhappy with the results.
Here is a function that just returns the price:
int ShopPrice(item Widget)
{
matcher shopmatch;
//matcher for single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(1).to_int();
//matcher for multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(2).to_int();
//matcher for multiple at limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find()) return shopmatch.group(2).to_int();
return 0;
}
I am working on a complete parser, I want it to parse amount, price, and limit. (I know that shop_amount() exists)
I am having trouble with getting the limit.
Here is what I am working on, consider this to be a rough, rough, rough draft:
record shopinfo
{
int amount;
int price;
int limit;
};
string storecache= visit_url("managestore.php");
storecache=substring(storecache,index_of(storecach e,"Store Inventory:")+202);
int ShopPrice(item Widget)
{
matcher shopmatch;
//matcher for single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(1).to_int();
//matcher for multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(2).to_int();
//matcher for multiple at limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find()) return shopmatch.group(2).to_int();
return 0;
}
shopinfo ShopInfo(item Widget)
{
shopinfo thingy;
matcher shopmatch;
//match single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy.amount=1;
thingy.price=shopmatch.group(1).to_int();
thingy.limit=0;
return thingy;
}
//match multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy.amount=shopmatch.group(1).to_int();
thingy.price=shopmatch.group(2).to_int();
thingy.limit=0;
return thingy;
}
//match limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find())
//{
// thingy.amount=shopmatch.group(1).to_int();
// thingy.price=shopmatch.group(2).to_int();
// thingy.limit=shopmatch.group(3).to_int();
// return thingy;
//}
return thingy;
}
shopinfo[item] ShopParse()
{
shopinfo[item] thingy;
matcher shopmatch;
boolean done=false;
foreach i in $items[]
{
if(is_tradeable(i) && shop_amount(i)>0)
{
done=false;
if(!done)
{
shopmatch = create_matcher( "<td>"+i+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy[i].amount=1;
thingy[i].price=shopmatch.group(1).to_int();
thingy[i].limit=0;
done=true;
}
}
if(!done)
{
shopmatch = create_matcher( "<td>"+i+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy[i].amount=shopmatch.group(1).to_int();
thingy[i].price=shopmatch.group(2).to_int();
thingy[i].limit=0;
done=true;
}
}
//if(!done)
//{
// shopmatch = create_matcher( "<td>"+i+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
// if (shopmatch.find())
// {
// thingy[i].amount=shopmatch.group(1).to_int();
// thingy[i].price=shopmatch.group(2).to_int();
// thingy[i].limit=shopmatch.group(3).to_int();
// done=true;
// }
//}
}
}
return thingy;
}
void main()
{
//single request test
item dude=$item[hamethyst];
print("Test1","blue");
print("The shop price for a "+dude+" = "+ShopPrice(dude));
print("");
//parse test
print("Test2","blue");
shopinfo [item] MyShop= ShopParse();
map_to_file(MyShop, "MyShop.txt");
print("Check MyShop.txt in your data folder","blue");
dude=$item[mr. accessory];
print(dude);
print("amount="+myshop[dude].amount);
print("price="+myshop[dude].price);
print("limit="+myshop[dude].limit);
}
The idea here is to get a snapshot of what you currently have in your shop with the current pricing and limit information.
*I will be very embarrassed if this functionality is already built into ash or if I overlooked it somewhere.
Winterbay
03-01-2011, 09:11 PM
I don't know if this is useful in your case but it does go through yoru store and saves it as a snapshot. That could be further used I guess.
http://kolmafia.us/showthread.php?5654-Zeroing-out-entries-in-the-session-log-via-a-script&p=41497&viewfull=1#post41497
StDoodle
03-01-2011, 09:53 PM
Man, I feel like a moron now... I was in the middle of re-writing the exact same functionality to help out. But who posted the linked-to script? Doh!
Edit: I really should clean that up, add limit info, and give it its own thread...
Winterbay
03-02-2011, 05:17 AM
Heh :)
I like it even though I've done some small changes to adapt it to my use of it.
StDoodle
03-02-2011, 01:52 PM
Please, do share. That script was rather hastily thrown together* more to answer another player's question than to be a full-fledged informational script. I certainly wouldn't be against combining efforts and releasing a more "definitive" mall store script.
* Though it has nothing on my Hardcore Skill Analysis script for hastily-thrown-togetherness. ;)
mredge73
03-02-2011, 03:04 PM
Thanks for the link but it does not parse in the limit either.
I really don't understand StDoodle's regex but it appears to get the same results, unfortunately he needed 3 matchers too.
I a looking forward for the cleaned up version in its own thread.
StDoodle
03-02-2011, 03:27 PM
A bit more regex, and still not all that clean, but now with limits!
mredge73
03-02-2011, 06:36 PM
Thanks for the help.
I edited it into a function for my purposes. (I also changed the return type).
record mall_item {
item thing;
int price;
int qty;
int limit;
};
int parse_num(string n) {
string t; matcher m;
t = replace_string(n, ",", "").to_string();
m = create_matcher("\\d{1,9}",t);
if (m.find()) return t.to_int();
return -1;
}
int limit_parse(string l) {
if (!contains_text(l, ">(unlimited)<"))
return (is_integer(l)) ? l.to_int() : 0;
return 0;
}
mall_item[item] ShopParse()
{
//define return value
mall_item [item] my_mallstore;
//clip page
string page = visit_url("managestore.php");
matcher m1 = create_matcher("<div.+?><b>Store Inventory:</b>(.+?)</table></div>",page);
if (m1.find())
{
page = m1.group(1);
matcher m2 = create_matcher("<tr><td><img.+?></td><td>(.+?(?:\\s\\(\\d{1,3}(?:,\\d{3}){0,2}\\))?)</td><td>(\\d{1,3}(?:,\\d{3}){0,2})</td><td>(.+?)</td>.+?</tr>",page);
matcher m3;
item thing;
int qty;
while (m2.find())
{
//print(m2.group(1),"blue"); print(m2.group(2));
m3 = create_matcher("(.+?)\\s\\((\\d{1,9})\\)", m2.group(1));
if (m3.find())
{
thing = m3.group(1).to_item();
qty = parse_num(m3.group(2));
}
else
{
thing = m2.group(1).to_item();
qty = 1;
}
my_mallstore[thing].price = parse_num(m2.group(2));
my_mallstore[thing].qty=qty;
my_mallstore[thing].limit= limit_parse(m2.group(3));
} // while loop through ea. line of store stuff / qty
//save map
if (map_to_file(my_mallstore, my_name().to_lower_case() + "_mall.txt")) print("Store snapshot saved.", "green");
else print("Error saving store snapshot; please try again.", "red");
}
else { print("Unable to find any mall items.","red");}
return my_mallstore;
}
//Test
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
mall_item [item] myshop = ShopParse();
int totalvalue=0;
print("Your Shop Contains","blue");
foreach i in myshop
{
if(myshop[i].limit>0) print(i+" ("+myshop[i].qty+" limit "+myshop[i].limit+" @ "+myshop[i].price+")");
else print(i+" ("+myshop[i].qty+" @ "+myshop[i].price+")");
totalvalue=totalvalue+(myshop[i].price*myshop[i].qty);
}
print("Total Shop Value= "+totalvalue,"blue");
Edit: Super useful helper function
int ShopPrice(item widget)
{
mall_item [item] myshop = ShopParse();
if (myshop contains widget) return myshop[widget].price;
return 0;
}
Powered by vBulletin® Version 4.2.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.