The work on item value functions was interrupted with the flurry of activity about the change to floats, and then by the conspiracy of illness and other things to prevent me from playing KoL. I even missed out on limited content! Lord Flamewho? Sucks.
Anyway, I'm trying to climb back on top of things, and I've got two functions (technically 8 due to overloading) which I believe cover all the bases:
int mall_val(item it, [ float expirydays ], [ boolean combatsafe ] )
int sell_val(item it, [ float expirydays ], [ boolean combatsafe ] )
First,
mall_val() is a wrapper for ASH's
mall_price() and
historical_price(). In fact, calling this function with neither of the optional parameters is identical to calling
mall_price(), since
expirydays defaults to 0 and
combatsafe defaults to false. In practice, though, you'll probably be calling it with one of the optional parameters, but not both.
How does it work? It returns the value of the item in the mall, preferring
historical_price() if it exists and isn't outdated (as specified by
expirydays). Omitting expirydays will skip checking the historical price and always check mall_price(), and specifying expirydays of 100 or greater means it will always use historical price if it exists regardless of age (necessary since I observed
historical_age() returning 9223372036854775807 on some occasions). Specifying
combatsafe as true overrides
expirydays, as it will avoid calling
mall_price() and thus prefer historical price no matter the age, returning 0 if there is no
historical_price().
The second function,
sell_val(), is more concerned with the meat you could realistically make from selling that item. It consults the first function, and returns that value if it is more than mall minimum. Otherwise, it returns the autosell value. It has the same parameters as the first.
Thus, with these flexible functions we can handily accomplish the functionality of all of the functions posted previously and then some!
In case you read ASH better than English -- or conversely, in case I write ASH more clearly than I do English explaining ASH -- here they are:
PHP:
int mall_val(item it, float expirydays, boolean combatsafe) {
if (!is_tradeable(it)) return 0;
if (historical_price(it) > 0 && (combatsafe || expirydays > 99 || historical_age(it) < expirydays)) return historical_price(it);
return combatsafe ? 0 : mall_price(it);
}
int mall_val(item it, float expirydays) { return mall_val(it,expirydays,false); }
int mall_val(item it, boolean combatsafe) { return mall_val(it,0,combatsafe); }
int mall_val(item it) { return mall_val(it,0,false); }
int sell_val(item it, float expirydays, boolean combatsafe) {
int mall = mall_val(it,expirydays,combatsafe);
if (mall > max(100,2*autosell_price(it))) return mall;
return autosell_price(it);
}
int sell_val(item it, float expirydays) { return sell_val(it,expirydays,false); }
int sell_val(item it, boolean combatsafe) { return sell_val(it,0,combatsafe); }
int sell_val(item it) { return sell_val(it,0,false); }
I'll give these functions a day or two to percolate and get thumbs of approval, critiques of usefulness, or insults of scathingness, and if they make it through either unscathed or improved, we'll spin a ZLib update including these and the
rnum() fix, which means we can then spin the long-awaited BatBrain update at the same time.