· 5 months ago · Apr 23, 2025, 11:55 PM
1function dumpItem(item)
2 if not item then
3 print("Item is nil, exiting function.")
4 return
5 end
6
7 -- Check if the provided item is a container
8 if item.InventoryOwner or getName(item) == "Traveler's Chest" then
9 print("Item is a container, exiting function.")
10 return
11 end
12
13 -- Define a key table for matching StatsId to folder names
14 local statsIdToFolder = {
15 LOOT = "Loot",
16 TOOL = "Tools",
17 FOOD = "Food",
18 Key = "Keys",
19 Scroll = "Scrolls",
20 Arrow = "Arrows",
21 Ingredient = "Ingredients",
22 Herbs = "Ingredients",
23 BOOK = "Books"
24 }
25
26 -- Define a table for mapping specific folder names to more general categories
27 local folderMapping = {
28 Body = "Clothing",
29 Breast = "Clothing",
30 Ring = "Rings",
31 Grenade = "Grenades",
32 Potion = "Potions",
33 Scroll = "Scrolls",
34 Amulet = "Amulets",
35 Footwear = "Boots",
36 Helmet = "Helmets",
37 Cloak = "Cloaks"
38 }
39
40 -- Define a table for armor types that should be grouped under "Armor"
41 local armorTypes = {
42 Helmets = true,
43 Clothing = true,
44 LightArmor = true,
45 MediumArmor = true,
46 HeavyArmor = true,
47 Boots = true,
48 Cloaks = true,
49 Rings = true,
50 Amulets = true,
51 Gloves = true,
52 Shields = true
53 }
54
55 local campClothes = {
56 VanityBody = true,
57 VanityBoots = true,
58 Underwear = true
59 }
60
61 print("Dumping ".. getName(item))
62
63 -- Get the ProficiencyGroup component if it exists
64 local proficiencyGroup = item:GetComponent("ProficiencyGroup")
65 local proficiencyFlags
66
67 if proficiencyGroup then
68 proficiencyFlags = proficiencyGroup.Flags
69 --print("ProficiencyGroup found. Flags: " .. tostring(proficiencyFlags))
70 else
71 --print("No ProficiencyGroup found.")
72 end
73
74 -- Determine folder1 and folder2 based on the flags
75 local folder1, folder2
76
77 if proficiencyFlags then
78 --print("Checking proficiency flags for folder1...")
79 for _, flag in ipairs(proficiencyFlags) do
80 --print("Checking proficiency flag: " .. flag)
81 if flag == "MartialWeapons" or flag == "SimpleWeapons" then
82 folder1 = flag
83 --print("Folder1 set by proficiency flag: " .. folder1)
84 break
85 end
86 end
87
88 if not folder1 and #proficiencyFlags > 0 then
89 folder1 = proficiencyFlags[1]
90 --print("Folder1 not set; using the first proficiency flag: " .. folder1)
91 end
92
93 if folder1 then
94 for _, flag in ipairs(proficiencyFlags) do
95 if flag ~= folder1 then
96 folder2 = flag
97 --print("Folder2 set by proficiency flag: " .. folder2)
98 break
99 end
100 end
101 end
102 end
103
104 if not folder1 then
105 local slot = item.Equipable and item.Equipable.Slot
106 if slot then
107 folder1 = slot
108 end
109 end
110
111 -- Check other sources if folder1 was not set by proficiency flags
112 if not folder1 then
113 -- Check if statsId matches any keyword in statsIdToFolder
114 local statsId = item.Data and item.Data.StatsId
115 if statsId then
116 --print("Checking statsId for matches: " .. statsId)
117 for key in pairs(statsIdToFolder) do
118 if statsId:match(key) then
119 folder1 = statsIdToFolder[key]
120 --print("Folder1 set from statsId match with keyword: " .. key)
121 break
122 end
123 end
124
125 if not folder1 then
126 --print("No match found in statsId.")
127 end
128 else
129 --print("StatsId is nil.")
130 end
131
132 -- Check icon for matches if folder1 is still not set
133 if not folder1 then
134 local icon = item.GameObjectVisual and item.GameObjectVisual.Icon
135 if icon then
136 --print("Checking icon for matches: " .. icon)
137 for key in pairs(statsIdToFolder) do
138 if icon:match(key) then
139 folder1 = statsIdToFolder[key]
140 --print("Folder1 set from icon match with keyword: " .. key)
141 break
142 end
143 end
144
145 if not folder1 then
146 --print("No match found in icon.")
147 end
148 else
149 --print("Icon is nil or not found.")
150 end
151 end
152 end
153
154 if not folder1 then
155 local usetype = item.Use and item.Use.ItemUseType
156 if usetype then
157 folder1 = usetype
158 end
159 end
160
161 -- Set folder1 to "Uncategorized" only if it hasn't been set by now
162 if not folder1 then
163 folder1 = "Uncategorized"
164 --print("Folder1 not set by any sources; using 'Uncategorized'.")
165 end
166
167 -- Check and apply folder mapping for specific cases
168 if folderMapping[folder1] then
169 --print("Folder1 matched in folderMapping. Changing folder1 to: " .. folderMapping[folder1])
170 folder1 = folderMapping[folder1]
171 end
172
173 -- Check if folder1 should be grouped under "Armor"
174 if armorTypes[folder1] then
175 --print("Folder1 is an armor type. Grouping under 'Armor'.")
176 folder2 = folder1
177 folder1 = "Armor"
178 end
179
180 if campClothes[folder1] then
181 folder2 = folder1
182 folder1 = "Camp Clothes"
183 end
184
185 folder1 = tostring(folder1)
186 if folder2 then
187 folder2 = tostring(folder2)
188 end
189
190 -- Create the folder path
191 local path = "/ItemDumps/" .. folder1
192 if folder2 and folder2 ~= "Uncategorized" then
193 path = path .. "/" .. folder2
194 end
195 --print("Folder path created: " .. path)
196 local Uuid = tostring(item.Uuid.EntityUuid)
197 -- Save the item to the corresponding folder
198 local itemName = getName(item) or "UnknownItem"
199 --print("Saving item to path: " .. path .. "/" .. itemName .. " - ".. Uuid ..".json")
200 Ext.IO.SaveFile(path .. "/" .. itemName .. " - ".. Uuid ..".json", Ext.DumpExport(item:GetAllComponents()))
201end