forked from Rhyono/CraftStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCraftStore_Helpers.lua
230 lines (201 loc) · 5.38 KB
/
CraftStore_Helpers.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
CraftStoreFixedAndImprovedLongClassName = {}
local CS = CraftStoreFixedAndImprovedLongClassName
function CS.SplitLink(link,nr)
local split = {SplitString(':', link)}
if split[nr] then return tonumber(split[nr]) else return false end
end
function CS.SetLinkValue(link,nr,value)
local split = {SplitString(':', link)}
if split[nr+2] then
split[nr+2] = value
end
return table.concat(split, ":")
end
function CS.ToChat(message)
local chat = CHAT_SYSTEM.textEntry:GetText()
StartChatInput(chat..message)
end
function CS.Set(list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
function CS.StripLink(link)
if CanItemLinkBeVirtual(link) then return CS.NakedLink(link) end
local split = {SplitString(':', link)}
--Highlight
if split[1] then
split[1] = "|H0"
end
--Crafted
if split[19] then
split[19] = 0
end
--Bound
if split[20] then
split[20] = 0
end
--Stolen
if split[21] then
split[21] = 0
end
--Durability
if split[22] then
split[22] = "0"
end
return table.concat(split, ":")
end
function CS.NakedLink(link)
local split = {SplitString(':', link)}
return "|H0:item:"..split[3]..":0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h"
end
function CS.Texture(link,width,height)
width = width == nil and 18 or width
height = height == nil and width or height
return '|t'..width..':'..height..':'..link..'|t'
end
function CS.UpdateMatsInfo(link)
local itemType = GetItemLinkItemType(link)
if CS.RawItemTypes[itemType] and not CS.Account.materials[link] then
local refinedLink = CS.NakedLink(GetItemLinkRefinedMaterialItemLink(link,0))
CS.Account.materials[link] = {raw=true,link=refinedLink}
CS.Account.materials[refinedLink] = {raw=false,link=link}
end
end
function CS.Switch(t)
t.case = function (self,x)
local f=self[x] or self.default
if f then
if type(f)=="function" then
f(x,self)
else
error("case "..tostring(x).." not a function")
end
end
end
return t
end
-- checks if a value is nil, returns default if it is
function CS.NilCheck(root,default,...)
local args = {...}
for i=1,#args do
if root[args[i]] == nil then return default end
root = root[args[i]]
end
return root
end
-- checks if a value is nil and sets it regardless
function CS.NilCheckSet(root,set,...)
local args = {...}
for i=1,#args do
if root[args[i]] == nil then
root[args[i]] = i ~= #args and {} or set
end
if i == #args then
root[args[i]] = set
return root[args[i]]
end
root = root[args[i]]
end
return root
end
-- checks if a value is nil and sets default if it is
function CS.NilCheckSetIfNil(root,default,...)
local args = {...}
for i=1,#args do
if root[args[i]] == nil then
root[args[i]] = i ~= #args and {} or default
end
if i == #args then
return root[args[i]]
end
root = root[args[i]]
end
return root
end
function CS.IsPublishedItem(itemId)
local itemName = GetItemLinkName(('|H1:item:%u:6:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h'):format(itemId))
return itemName ~= nil and itemName ~= ''
end
function CS.IsPublishedAchievement(achievementId)
local achievementName = GetAchievementName(achievementId)
return achievementName ~= nil and achievementName ~= ''
end
function CS.FilterPublishedItems(itemIds)
local publishedItemIds = {}
for i,itemId in pairs(itemIds) do
if CS.IsPublishedItem(itemId) then
table.insert(publishedItemIds, itemId)
end
end
return publishedItemIds
end
CS.Chat = {}
function CS.Chat:Print(str)
if str == nil then return end
d("|cEEEE00[CraftStore]|r ".. str)
end
-- use libchatmessage if available
if LibChatMessage then
CS.Chat = LibChatMessage("CraftStore", "CS")
end
-- utility function for finding furnishing recipes
function CS.FindUnidentifiedFurnishingRecipes(startIndex, endIndex)
local exists = {}
for i=1, #CS.Furnisher.recipelist do
exists[CS.Furnisher.recipelist[i]]=true
end
local unknown = {}
local j=1
local suffix = ":" .. 364 .. ":" .. 50 .. ":0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:10000:0|h|h"
d("Searching in range "..startIndex.." .. "..endIndex)
for i=startIndex, endIndex do
local isUnknown = false
if exists[i] == nil then
local link= "|H1:item:" .. i .. suffix
local name=GetItemLinkName(link)
if string.find(name, "Praxis:") then
isUnknown = true
elseif string.find(name, "Blueprint:") then
isUnknown = true
elseif string.find(name, "Diagram:") then
isUnknown = true
elseif string.find(name, "Pattern:") then
isUnknown = true
elseif string.find(name, "Formula:") then
isUnknown = true
elseif string.find(name, "Sketch:") then
isUnknown = true
elseif string.find(name, "Design:") then
isUnknown = true
elseif string.find(name, "Recipe:") then
isUnknown = true
end
end
if isUnknown then
d(i .. " - " .. link)
unknown[j]=i
j = j + 1
end
end
if #unknown > 1 then
local unknownIds = ""
for i=1, #unknown do
unknownIds = unknownIds .. unknown[i] ..","
end
d(unknownIds)
else
d("No unknown furnishing recipes found in range.")
end
end
function CS.ListWayshrines(startIndex, endIndex)
startIndex = startIndex or 1
endIndex = endIndex or GetNumFastTravelNodes()
if endIndex > GetNumFastTravelNodes() then
endIndex = GetNumFastTravelNodes()
end
for i=startIndex, endIndex do
local known,name = GetFastTravelNodeInfo(i)
d(i .. ": " .. name)
end
end