ItemDataCache v1.12

This addon is both a static database and active scanner for item data. Note, this addon does not display gathered data by itself - it supplies data to other addons. For example if you want to see "sell to vendor" prices you've gathered, you have to install Informant from Auctioneer package.

Features:
- Static "sell to vendor" prices database for ~16300 items.
- Active "sell to vendor" scanner that will save unknown or new prices for all items in your bags every time you visit a merchant.

Notes:
- Since this addon is currently in active development, there's no interface option yet to turn off messages, however ItemDataCache should report every item only once, so that shouldn't be much of a problem.
- *** WARNING! *** If you get repeated messages about same item on every visit to the vendor, that most likely means you've found some error in the scanner. Please report to me name of affected item and what properties (soulbound/quest/charges/etc) it has.
- If you really want to disable those messages, even considering that with current size of database you'll probably will not even see one in a week, you can use "/script ItemDataCacheLocal.Settings.noNewDataMessages=true" and "/script ItemDataCacheLocal.Settings.noUpdatedDataMessages=true" commands to do that. Note, however, that bug reports without information from those messages are much less useful to me and it will take more time to find and fix them, unless you'll be able to turn messages on again and reproduce the bug.
- This addon does nothing with collected data by itself, so you will most likely want to install one of addons that can display data collected by ItemDataCache or use it in its calculations:
 * Informant from Auctioneer package: Informant's own database is updated periodically, but there are always some new unknown items or price changes. ItemDataCache hooks Informant.GetItem and inserts its own "sell to vendor" values. This allows Informant to display correct updated and previously unknown prices.
 * BottomScanner from Auctioneer package: just like with Informant, BottomScanner's database sometimes do not have most recent prices. ItemDataCache will provide BottomScanner with prices it knows.
 * Titan Panel - Itemized Deductions (ReBorn): this addon, created to help you free space in your bags by selling junk, dropping cheap items or combining incomplete stacks, uses ItemDataCache as primary source of prices. In fact ItemDataCache was written specifically to replace Itemized Deductions' old database and everything else is just a nice side effect. :)
 * MobInfo-2: tracks information about monsters you fight, like their HP or what items they drop. ItemDataCache is one of alternative sources for item prices data displayed in tooltips and used in calculating total monster value for this addon.
 * Greyprice: minimal solution to track your looting progress. This addon displays a small window with total cost of all the junk loot in your bags.
 * SwitchRod: uses ItemDataCache class data to find fishing pole in bags and equip it on command or switches your equipment back.
 * Additionally, any addon that uses either Informant (for example: GarbageFu) or GetSellValue API (for example: VendorBait) for item prices will work with ItemDataCache too.

Changes:
v1.12
- Added 870 items to "sell to vendor" DB, item count is now 16276. 34 old entries were updated.
- Added direct hooking of BottomScanner from Auctioneer package. BottomScanner gets prices from Informant only if they are not available in its own internal database and previously would only benefit from Informant hooking only on unknown prices. Now it gets price updates for known but old prices too.
- Both Informant and BtmScan now can be hooked both if they're loaded before or after ItemDataCache. This will stop ItemDataCache from forcing Informant to load even if user prefers it to load on demand.
- GetSellValue API now returns 0 instead of nil when item can't be sold to vendor according to clarification in specification. Only unknown prices will yield nil. After this change GetSellValue returns exactly same values as ItemDataCache.Get.ByID_selltovendor.
- Added two settings without UI that you can set manually to disable "new data" and "updated data" messages. You are advised not to use them, though, as bug reports without information of scanner activity will be much less useful.

v1.11
- Updated TOC version to 20100.
- Added 1296 items to "sell to vendor" DB, item count is now 15406. 122 old entries were updated.
- Added base items for detecting class 1/1 - Container/Soul Bag.
- Added support for proposed common GetSellValue API (http://www.wowwiki.com/API_GetSellValue). Any addon that uses this API will now automatically work with ItemDataCache.

v1.10
- Added 649 items to "sell to vendor" DB, item count is now 14759.
- Temporarily removed ~30 entries with incorrectly retrieved huge prices, those will be restored with correct data in next release.
- Added rotation for list of items to update from server after each request to avoid getting stuck on some item that server can't process right now.
- Added saving of ID/name relations for item class/subclass to local cache. Since those are rarely ever change, saved values will provide reliable fallback for those short windows of time right after patch when all class/subclass relations have to be requested from server again.
- Added base items for detecting class 2/20 - Weapon/Fishing Pole.

v1.09
- Added 1317 items to "sell to vendor" DB, item count is now 14110. Several old entries were updated.

v1.08
- Added 382 item to "sell to vendor" DB, item count is now 12793.
- Added some lightweight tooltip scan functions to use when we only need to obtain some specific data and there's no point in performing full scan.
- Moved all "sell to vendor" price updates to same function and added saving obtained data to localized variables to prevent problems with OnUpdate hooks calling scanning function again and messing up state kept in persistent variables, making ItemDataCache save price for item to wrong item entry.

v1.07
- Added 151 item to "sell to vendor" DB, item count is now 12411.
- Fixed not detecting some charged items.
- Removed some unnecessary checks, localized some variables, eliminated extra table look-ups for small performance boost.

v1.06
- Added 535 items to "sell to vendor" DB, item count is now 12260. Several old entries were updated.
- Added more base items for detecting class 6/3 - Projectile/Bullet.
- Fixed money data initialization incorrectly placed after retrieval, always overwriting new data with "not found" value. Saving local "sell to vendor" prices should work correctly again.

v1.05
- Added 90 items to "sell to vendor" DB, item count is now 11725.
- Recipe entries that were incorrectly saved to "max charges" database is now purged on load.
- Throttle some class/sub-class requests and only request data for needed classes to prevent bad server responses. This will cause unavailable class data to be reinitialized slower and anyone using (not yet documented) ByID_class API must deal correctly with "false" values returned from init.

v1.04
- Added 878 items to "sell to vendor" DB, item count is now 11635.
- Added base items for detecting classes 11/2 - Quiver/Quiver and 11/3 - Quiver/Ammo pouch.
- Added (undocumented) item tooltip scanner.
- Properly record items without "sell to vendor" price, but with charges, instead of resetting it on every vendor scan, forever stuck in "We got no sell price, record price as 0 no matter what. Wait it have charges, reset recorded price, we don't handle charges." logic.

v1.03
- Added 2236 items to "sell to vendor" DB, item count is now 10757.
- Ignore damaged items in scan for "sell to vendor" price.
- Informant hook now returns nil if it got nil from Informant.
- Alchemy/enchanting/engineering recipes with charges listed for items they teach are no longer treated as items with charges for "sell to vendor" price scan.
- Added experimental and not yet documented functions to get locale-independent class and subclass ID for item (charged recipe ignore feature uses it, as well as latest version of Titan Panel - Itemized Deductions (ReBorn) - you can check those for examples). List of available IDs is limited right now and all of them will be added in later releases. This feature SHOULD work for anyone without problem, but in case I did something wrong it could cause disconnect on startup. If this happens, please disable ItemDataCache and report to me as soon as possible.

v1.02
- Added 723 items to "sell to vendor" DB, item count is now 8521.
- Added support for charged items ID saving. This was done to correctly ignore price changes for items with just one charge left, as they look like standard consumable items without any additional indication that they had more charges.
- Made capture transformation format for charges in scanner more universal, fixing issues with German client using slightly different string.
- Fixed scanner stopping after finding first item with charges in bags.
  Thanks to Dragzal and Abu-Dun for reporting issues with charges scanning and German client and for helping to test fixes.

v1.01
- Fixed stupid bug introduced in last minute changes before first public release that caused database cleaner remove all local gathered data on every startup.
- Cleaned static database from duplicates (just another thing that I forgot to do before release). Correct item count is 7798.
- Made scanner ignore items with spell charges until I decide how to better handle them.

Messages:
You may encounter following messages:
- "Found new data for table sometable [Item]: value."
 * This means that ItemDataCache scanner discovered some new data that it doesn't have. Since built-in static database with this version is not that big, you should see it often enough when you visit merchant with new items.
- "Found UPDATED data for table sometable [Item]: value."
 * This is more rare and interesting: scanner discovered data that doesn't match what it already knows. This may happen when Blizzard changes item prices, for example.
- "Resetting local data for table sometable item [Item]."
 * Local cache had some data for item that is no longer considered more recent than static cache and that data is now removed.
- "Finished local data purge for sometable. X entries matching static cache freed. Y entries with data more recent than static cache found."
 * This message appears on startup or UI reload (that includes continent changes and going into instance). X, number of matching entries tells you that your dynamic local cache (saved in your addon settings) had X entries that already exists in built-in static database and that those entries were freed to save memory, because there's no point to keep duplicate data. This number will often be 0 and should only change when you install new static database (with new version of addon, most likely). Y, number of more recent entries is number of entries in your local cache that are also present in static database, but have more accurate data in local cache because scanner updated it.

Tables
Two tables are available at present:
- ByID_selltovendor - table of prices for selling items to vendor. Values for this table are item worth in copper.
- ByID_maxcharges - table of items that can have charges. Values for this table are "true" if item with that ID can have charges or nil.

API:
If your addon deals with any data that can be provided by ItemDataCache you may want to use it as one of alternative sources.
Generally every table has two functions available: ItemDataCache.Get.TableName and ItemDataCache.OnUpdate.TableName. First function returns most recent value from all tables, giving priority to data in local cache. Second is a function that is called every time when data in that table is updated so you can hook it and act accordingly on every change. You may want to use it if you addon needs to update shown data on-the-fly, for example if it shows some tracking window or panel that is always on screen.
Example:
- ItemDataCache.Get.ByID_selltovendor(itemID)
 * Returns "sell to vendor" price of known item in copper or nil if price is unknown.
- ItemDataCache.OnUpdate.ByID_selltovendor()
 * Hook function that allows you to catch updates to prices as they happen, if you addon displays information in real-time (for example if it is plugin for Titan or any other panel addon). Hooking is done as usual:
	local hook=ItemDataCache.OnUpdate.ByID_selltovendor
	ItemDataCache.OnUpdate.ByID_selltovendor=function() MyAddon.UpdateFrames() return hook() end

Additonally ItemDataCache support GetSellValue API (http://www.wowwiki.com/API_GetSellValue) for values from "ByID_selltovendor" table. Please see WoWWiki page for more information.
