Mercurial > wow > itemauditor
comparison Modules/ArkInventoryRules.lua @ 69:4ae431c98059
Added integration with ArkInventory. You can set up rules that use "itemauditor('profitable')" or "itemauditor('qa')" to find items managed by QuickAuctions
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Wed, 28 Jul 2010 21:27:39 -0700 |
| parents | |
| children | 71de6e86a1a4 |
comparison
equal
deleted
inserted
replaced
| 68:2d65db19d3ce | 69:4ae431c98059 |
|---|---|
| 1 if not ArkInventoryRules then | |
| 2 return | |
| 3 end | |
| 4 | |
| 5 local ItemAuditor = select(2, ...) | |
| 6 local ArkInventory = ItemAuditor:NewModule("ArkInventory") | |
| 7 | |
| 8 function ArkInventory:OnEnable( ) | |
| 9 ItemAuditor:Print('Registering with ArkInventory') | |
| 10 ArkInventoryRules.Register(self, "itemauditor", ArkInventory.Execute) | |
| 11 end | |
| 12 | |
| 13 function ArkInventory.Execute( ... ) | |
| 14 | |
| 15 -- always check for the hyperlink and that it's an actual item, not a spell (pet/mount) | |
| 16 if not ArkInventoryRules.Item.h or ArkInventoryRules.Item.class ~= "item" then | |
| 17 return false | |
| 18 end | |
| 19 | |
| 20 local fn = "test" -- your rule name, needs to be set so that error messages are readable | |
| 21 | |
| 22 local ac = select( '#', ... ) | |
| 23 | |
| 24 -- if you need at least 1 argument, this is how you check, if you dont need or care then you can remove this part | |
| 25 if ac == 0 then | |
| 26 error( string.format( ArkInventory.Localise["RULE_FAILED_ARGUMENT_NONE_SPECIFIED"], fn ), 0 ) | |
| 27 end | |
| 28 | |
| 29 for ax = 1, ac do -- loop through the supplied ... arguments | |
| 30 | |
| 31 local arg = select( ax, ... ) -- select the argument were going to work with | |
| 32 | |
| 33 -- this code checks item quality, either as text or as a number | |
| 34 -- your best bet is to check the existing system rules to find one thats close to what you need an modify it to suit your needs | |
| 35 -- all you have to do is ensure that you return true (matched your criteria) or false (failed to match) | |
| 36 | |
| 37 if type( arg ) == "string" then | |
| 38 local link = ArkInventoryRules.Item.h | |
| 39 | |
| 40 local itemName = GetItemInfo(link) | |
| 41 | |
| 42 if string.lower( strtrim( arg ) ) == 'profitable' then | |
| 43 | |
| 44 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) | |
| 45 | |
| 46 if investedTotal > 0 then | |
| 47 local ap = ItemAuditor:GetAuctionPrice(link) | |
| 48 local keep = 1 - ItemAuditor:GetAHCut() | |
| 49 | |
| 50 if ap ~= nil then | |
| 51 | |
| 52 if ap > ceil(investedPerItem/keep) then | |
| 53 return true | |
| 54 end | |
| 55 end | |
| 56 end | |
| 57 return false | |
| 58 elseif string.lower( strtrim( arg ) ) == 'qa' then | |
| 59 if ItemAuditor:IsQAEnabled() then | |
| 60 local groupName = QAAPI:GetItemGroup(link) | |
| 61 if groupName then | |
| 62 return true | |
| 63 end | |
| 64 end | |
| 65 return false | |
| 66 end | |
| 67 | |
| 68 else | |
| 69 | |
| 70 error( string.format( ArkInventory.Localise["RULE_FAILED_ARGUMENT_IS_INVALID"], fn, ax, string.format( "%s or %s", ArkInventory.Localise["STRING"], ArkInventory.Localise["NUMBER"] ) ), 0 ) | |
| 71 | |
| 72 end | |
| 73 | |
| 74 end | |
| 75 | |
| 76 return false | |
| 77 | |
| 78 end | |
| 79 |
