annotate Modules/ArkInventoryRules.lua @ 82:e9f7bc9199ca release 2010-08-05

Fixed Bug 23 - When you purchase multiple stacks of the same item and it is one you have not invested in yet, ItemAuditor mistakenly counted items you have not yet pulled from the mail as items you already owned. This resulted in those items being counted twice.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 05 Aug 2010 22:20:44 -0700
parents 71de6e86a1a4
children 2112f71c4237
rev   line source
Asa@74 1
Asa@69 2
Asa@69 3 local ItemAuditor = select(2, ...)
Asa@69 4 local ArkInventory = ItemAuditor:NewModule("ArkInventory")
Asa@69 5
Asa@69 6 function ArkInventory:OnEnable( )
Asa@74 7 if ArkInventoryRules then
Asa@74 8 ItemAuditor:Print('Registering with ArkInventory')
Asa@74 9 ArkInventoryRules.Register(self, "itemauditor", ArkInventory.Execute)
Asa@74 10 end
Asa@69 11 end
Asa@69 12
Asa@69 13 function ArkInventory.Execute( ... )
Asa@69 14
Asa@69 15 -- always check for the hyperlink and that it's an actual item, not a spell (pet/mount)
Asa@69 16 if not ArkInventoryRules.Item.h or ArkInventoryRules.Item.class ~= "item" then
Asa@69 17 return false
Asa@69 18 end
Asa@69 19
Asa@69 20 local fn = "test" -- your rule name, needs to be set so that error messages are readable
Asa@69 21
Asa@69 22 local ac = select( '#', ... )
Asa@69 23
Asa@69 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
Asa@69 25 if ac == 0 then
Asa@69 26 error( string.format( ArkInventory.Localise["RULE_FAILED_ARGUMENT_NONE_SPECIFIED"], fn ), 0 )
Asa@69 27 end
Asa@69 28
Asa@69 29 for ax = 1, ac do -- loop through the supplied ... arguments
Asa@69 30
Asa@69 31 local arg = select( ax, ... ) -- select the argument were going to work with
Asa@69 32
Asa@69 33 -- this code checks item quality, either as text or as a number
Asa@69 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
Asa@69 35 -- all you have to do is ensure that you return true (matched your criteria) or false (failed to match)
Asa@69 36
Asa@69 37 if type( arg ) == "string" then
Asa@69 38 local link = ArkInventoryRules.Item.h
Asa@69 39
Asa@69 40 local itemName = GetItemInfo(link)
Asa@69 41
Asa@69 42 if string.lower( strtrim( arg ) ) == 'profitable' then
Asa@69 43
Asa@69 44 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@69 45
Asa@69 46 if investedTotal > 0 then
Asa@69 47 local ap = ItemAuditor:GetAuctionPrice(link)
Asa@69 48 local keep = 1 - ItemAuditor:GetAHCut()
Asa@69 49
Asa@69 50 if ap ~= nil then
Asa@69 51
Asa@69 52 if ap > ceil(investedPerItem/keep) then
Asa@69 53 return true
Asa@69 54 end
Asa@69 55 end
Asa@69 56 end
Asa@69 57 return false
Asa@69 58 elseif string.lower( strtrim( arg ) ) == 'qa' then
Asa@69 59 if ItemAuditor:IsQAEnabled() then
Asa@69 60 local groupName = QAAPI:GetItemGroup(link)
Asa@69 61 if groupName then
Asa@69 62 return true
Asa@69 63 end
Asa@69 64 end
Asa@69 65 return false
Asa@69 66 end
Asa@69 67
Asa@69 68 else
Asa@69 69
Asa@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 )
Asa@69 71
Asa@69 72 end
Asa@69 73
Asa@69 74 end
Asa@69 75
Asa@69 76 return false
Asa@69 77
Asa@69 78 end
Asa@69 79