-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
188 lines (155 loc) · 4.9 KB
/
main.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
ILC = LibStub("AceAddon-3.0"):NewAddon("ILC", "AceConsole-3.0", "AceEvent-3.0")
function ILC:OnInitialize()
---------------------------------------
-- Global variable initialization
---------------------------------------
self.db = LibStub("AceDB-3.0"):New("InspectListCreatorDb", defaults)
ILC:RegisterChatCommand('ilc', 'HandleChatCommand');
if (UseCSV == nil) then
UseCSV = false
end
if not InspectFrame then
LoadAddOn("Blizzard_InspectUI")
end
local btn = CreateFrame('Button', nil, InspectFrame, 'UIPanelButtonTemplate')
btn:SetPoint('BOTTOM', 0, 438)
btn:SetText('Create list')
btn:SetWidth(100)
btn:SetHeight(25)
btn:SetScript('OnClick', function()
ILC:Generatelist()
end)
btn:RegisterEvent("PLAYER_LOGIN")
end
function ILC:BoolText(input)
local booltext = 'False'
if (input) then
booltext = 'True'
end
return booltext
end
function ILC:Generatelist()
local characterSlots = {"Head", "Neck", "Shoulder", "Shirt", "Chest", "Waist", "Legs", "Feet", "Wrist", "Hands", "Finger 1", "Finger 2", "Trinket 1", "Trinket 2", "Back", "Main hand", "Off hand", "Ranged"}
local InspectItems = ILC:GetTargetItems()
local itemlistsort = {}
local exportString = ''
local wowheadlink = ''
local gametimehours, gametimeminutes = GetGameTime()
local servertime = string.format("%02d", gametimehours) .. '.' .. string.format("%02d", gametimeminutes)
if (UseCSV) then
exportString = date("%d.%m.%Y ") .. ',' .. servertime .. ',' .. UnitName('target') .. ', \n'
else
exportString = 'Inspect list updated on ' .. date("%d.%m.%Y ") .. servertime .. ' server time\nCharacter: ' .. UnitName('target') .. '\n\n'
end
local itemCounter = ''
for i = 1, 18 do
if (UseCSV) then
if (InspectItems[i].itemID > 0) then
wowheadlink = 'https://classic.wowhead.com/item=' .. InspectItems[i].itemID
else
wowheadlink = ''
end
itemCounter = string.format("%d", InspectItems[i].count)
exportString = exportString .. characterSlots[i] .. ',' .. InspectItems[i].itemName .. ',' .. itemCounter .. ',' .. wowheadlink ..'\n'
else
if (InspectItems[i].itemID > 0) then
wowheadlink = ' https://classic.wowhead.com/item=' .. InspectItems[i].itemID
else
wowheadlink = ''
end
if (InspectItems[i].count > 0) then
itemCounter = ' (' .. InspectItems[i].count .. ') '
else
itemCounter = ' '
end
exportString = exportString .. characterSlots[i] .. ': ' .. InspectItems[i].itemName .. itemCounter .. wowheadlink ..'\n'
end
end
ILC:DisplayExportString(exportString)
end
function ILC:GetTargetItems()
local InspectItems = {}
for slot = 1, 18 do
local itemID = GetInventoryItemID("target", slot)
local sName = "Empty slot"
local sLink = 0
local iRarity = 0
local iLevel = 0
local iMinLevel = 0
local sType = 0
local sSubType = 0
local count = 0
if (itemID == nil) then
itemID = 0
end
if (itemID > 0) then
sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, count = GetItemInfo(itemID)
end
if (UseCSV) then
if (count == nil) then
count = 0
end
if ((sName == nil) or (sName == 'Empty slot')) then
sName = ""
end
else
if ((count == nil) or (count == 1)) then
count = 0
end
if (sName == nil) then
sName = "Empty slot"
end
end
InspectItems[#InspectItems + 1] = {
itemslot = slot,
itemName = sName,
itemID = itemID,
count = count
}
end
return InspectItems
end
function ILC:DisplayExportString(str)
InspectLCFrame:Show();
InspectLCFrameScroll:Show()
InspectLCFrameScrollText:Show()
InspectLCFrameScrollText:SetText(str)
InspectLCFrameScrollText:HighlightText()
InspectLCFrameButton:SetScript("OnClick", function(self)
InspectLCFrame:Hide();
end
);
end
function ILC:HandleChatCommand(input)
local lcinput = string.lower(input)
local gotcommands = false
---------------------------------------
-- Display help
---------------------------------------
if (string.match(lcinput, "help")) then
ILC:Print('Inspect List Creator Help')
ILC:Print('Usage:')
ILC:Print('Inspect target player and press Create list button')
ILC:Print('/ilc -- Manually initialize list creation of inspected player')
ILC:Print('/ilc csv true -- Output list in CSV format')
ILC:Print('/ilc csv false -- Output list in original format')
gotcommands = true
end
if (string.match(lcinput, "csv")) then
if (string.match(lcinput, "csv true")) then
ILC:Print('Outputting in CSV format')
UseCSV = true
end
if (string.match(lcinput, "csv false")) then
ILC:Print('Outputting in original format')
UseCSV = false
end
gotcommands = true
end
---------------------------------------
-- Generate list
---------------------------------------
if (not gotcommands) then
ILC:Generatelist()
end
end