forked from Auctionator/Auctionator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuctionatorItemLink.lua
executable file
·137 lines (106 loc) · 3.24 KB
/
AuctionatorItemLink.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Auctionator.ItemLink = {
item_link = '',
item_string = nil,
parsed_item_link = nil,
item_id_string = nil,
pet_id_string = nil,
bonus_ids = nil,
stage = nil,
tier = nil
}
ITEM_ID_VERSION = "3.2.6"
function Auctionator.ItemLink:new( options )
-- Auctionator.Debug.Message( 'ItemLink:new', options.item_link )
options = options or {}
setmetatable( options, self )
self.__index = self
return options
end
function Auctionator.ItemLink:ItemString()
if not self.item_string then
_, _, self.item_string = self.item_link:find( '^|c%x+|H(.+)|h%[.*%]' )
end
return self.item_string
end
function Auctionator.ItemLink:ParsedItemLink()
if not self.parsed_item_link and self:ItemString() then
self.parsed_item_link = { strsplit( ':', self:ItemString() ) }
end
return self.parsed_item_link
end
function Auctionator.ItemLink:GetField( field_id )
local field_value = (self:ParsedItemLink() or {})[ field_id ]
if field_value == nil or field_value == '' then
return 0
else
return field_value
end
end
function Auctionator.ItemLink:IdString()
local item_type = self:GetField( Auctionator.Constants.ItemLink.TYPE )
if item_type == 'item' then
return self:ItemIdString()
elseif item_type == 'battlepet' then
return self:BattlePetIdString()
end
end
function Auctionator.ItemLink:ItemIdString()
if not self.item_id_string then
self.item_id_string = self:GetField( Auctionator.Constants.ItemLink.ID ) .. ':' ..
self:Tier() .. ':' .. self:Stage() .. ':' .. self:Suffix() .. ':' ..
self:GetField( Auctionator.Constants.ItemLink.BONUS_ID_1 )
end
return self.item_id_string
end
function Auctionator.ItemLink:Bonuses()
if not self.bonus_ids then
self.bonus_ids = {}
for bonus_id = 1, self:BonusIdCount() do
local bonus_value = tonumber(
self:GetField( bonus_id + Auctionator.Constants.ItemLink.BONUS_ID_1 - 1 )
)
self.bonus_ids[ bonus_value ] = true
end
end
return self.bonus_ids
end
function Auctionator.ItemLink:Tier()
if not self.tier then
self.tier = 0
for tier_id, description in pairs( Auctionator.Constants.ItemLink.Tiers ) do
if self:Bonuses()[ tier_id ] then
self.tier = tier_id
end
end
end
return self.tier
end
function Auctionator.ItemLink:Stage()
if not self.stage then
self.stage = 0
for stage_id, stage in pairs( Auctionator.Constants.ItemLink.Stages ) do
if self:Bonuses()[ stage_id ] then
self.stage = stage
end
end
end
return self.stage
end
function Auctionator.ItemLink:Suffix()
return self:GetField( Auctionator.Constants.ItemLink.SUFFIX_ID )
end
function Auctionator.ItemLink:BattlePetIdString()
if not self.pet_id_string then
self.pet_id_string = self:GetField( Auctionator.Constants.ItemLink.ID ) ..
':' .. self:GetField( Auctionator.Constants.ItemLink.PET_LEVEL )
Auctionator.Util.Print( self.parsed_item_link, self.pet_id_string )
end
return self.pet_id_string
end
function Auctionator.ItemLink:BonusIdCount()
return tonumber( self:GetField( Auctionator.Constants.ItemLink.BONUS_ID_COUNT ) )
end
function Auctionator.ItemLink:IsBattlePet()
local item_type = self:GetField( Auctionator.Constants.ItemLink.TYPE )
return item_type == 'battlepet'
end