evil-morfar / RCLootCouncil2

RCLootCouncil - addon for World of Warcraft
https://rclootcouncil.com
GNU Lesser General Public License v3.0
19 stars 29 forks source link

RCItemUtils Library #164

Closed SafeteeWoW closed 4 years ago

SafeteeWoW commented 6 years ago

I create a RCItemUtil library to manage the code to fetch item information The purpose of this library.

It is still incomplete. But can you read this file and give me some suggestions? Sorry for lack of code comments.

The main idea is that you can use GetItemAttr to get one attribute of the item, for example GetItemAttr(ItemString, "name"). CacheItem(item) will cache all item attributes in a table, so we no longer needs to call any APIs in GetItemAttr. I have also defined some functions to conveniently define item attributes.


New discovery: The api DoesItemContainSpec(itemLink, classID, [specID]) and GetItemSpecInfo gives item spec information. This api eliminates the need to export trinket data and all other hardcode stuffs for autopassing This API also works for artifact relics and armor tokens. The former is a bit buggy if the item is not in the encounter journal(but it does work for armor tokens), for example, artifact weapon, but I think it should not matter. The latter only returns spec in the player's class. Not sure why don't I know this before. Are these added recently?

SafeteeWoW commented 6 years ago

Btw, this does not have memory problems. Caching all items in my full bags and bank takes 3MegaBytes, about 300 items. The next step is to remove caching in OnCommReceived to fix #160

SafeteeWoW commented 6 years ago

Due to the complete code restructure, this will be in v2.9, and I will need to write a separate test lua file to make sure nothing is wrong. This will be a big step towards version 3.0. Version3 will remove all stuffs in the lootTable that can be fetched from disk through API. This PR will keep those for v2.x backward compatibility. My plan is to modulize important components in v2.9 one-by-one, including communications, widgets, rightclick menus, loot handling, etc.

SafeteeWoW commented 6 years ago

This PR will deprecate all of following entries in the loot table. name, quality, ilvl, equipLoc, subType, texture, boe, relic, token, typeID, subTypeID, classes. and client side no longer needs to cache items to fix #160

ML still needs to cache items before sending lootTable. I temporarily remove the ML caching requirement for testing purposes. WIP. I expect the final PR makes ~3000 lines of change. TODO: Delay autopass until items are cached.

SafeteeWoW commented 6 years ago

Can you help to make sure how DoesItemContainSpec(itemLink/ID, classID, [specID]) works? Return value: true if the item is in the lootspec of the given class/spec. false otherwise Arguments:

  1. itemLink/ID: Required. Accept item link/string/id
  2. classID: Required. Class id number ranged from 1-12 (1 is warrior and 12 is demon hunter)
  3. specID: Optional. If nil, API returns true if any spec of the class can loot the item. Otherwise, only check the given specID. specID is a three-digit number.

Script I used
```
local t = {}
for id in pairs(_G.RCTokenTable) do
    t[id] = DoesItemContainSpec(id, 11)
    GetItemInfo(id)
end

C_Timer.After(20, function() print("time is up");
    for id in pairs(_G.RCTokenTable) do
        local c = DoesItemContainSpec(id, 11)
        if  not (c == t[id]) then
            print(id, t[id], c)
        end
    end end
)
````
The only print is "time is up". ~~~So I think this API does not have caching requirement~~~. 

Nah. Checked by two characters. Caching is still needed. It seems if the item is invalid or uncached, this API always returns true.
evil-morfar commented 6 years ago

DoesItemContainSpec seems to have been in the game at least since 7.0.3.

I once again find myself with very limited time for WoW, so I probably won't be of much help until next week, but it seems like you figured it out?

evil-morfar commented 6 years ago

Also, when you say "3 MB" is that the total memory usage of RCLootCouncil, or just the items? If the latter, 300 items at 3 MB that's 10 kB each, which is a lot.