annotate Modules/ArkInventoryRules.lua @ 137:526036e4358f

Ticket 42 - In order to fix an issue with having multiple items that are the same base item with different enchants, all costs are now tracked against the base item instead of the exact item.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 02 Oct 2010 19:21:56 -0700
parents 09a38a382194
children
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@88 50 if ap == nil or ap > ceil(investedPerItem/keep) then
Asa@88 51 return true
Asa@69 52 end
Asa@69 53 end
Asa@69 54 return false
Asa@69 55 elseif string.lower( strtrim( arg ) ) == 'qa' then
Asa@115 56 if ItemAuditor:IsQACompatible() then
Asa@69 57 local groupName = QAAPI:GetItemGroup(link)
Asa@69 58 if groupName then
Asa@69 59 return true
Asa@69 60 end
Asa@69 61 end
Asa@69 62 return false
Asa@69 63 end
Asa@69 64
Asa@69 65 else
Asa@69 66
Asa@69 67 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 68
Asa@69 69 end
Asa@69 70
Asa@69 71 end
Asa@69 72
Asa@69 73 return false
Asa@69 74
Asa@69 75 end
Asa@69 76