Skip to content

Commit

Permalink
API Bump
Browse files Browse the repository at this point in the history
Adds the ability to deconstruct items
  • Loading branch information
Dolgubon committed May 26, 2024
1 parent 50be9af commit 3a462bb
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Enchanting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local function LLC_CraftEnchantingGlyphItemID(self, potencyItemID, essenceItemID

--sortCraftQueue()
if GetCraftingInteractionType()==CRAFTING_TYPE_ENCHANTING then
LibLazyCrafting.craftInteract(event, CRAFTING_TYPE_ENCHANTING)
LibLazyCrafting.craftInteract(event, CRAFTING_TYPE_ENCHANTING)
end
return requestTable
end
Expand Down
4 changes: 2 additions & 2 deletions LibLazyCrafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end

-- Initialize libraries
local libLoaded
local LIB_NAME, VERSION = "LibLazyCrafting", 4.004
local LIB_NAME, VERSION = "LibLazyCrafting", 4.009
local LibLazyCrafting, oldminor
if LibStub then
LibLazyCrafting, oldminor = LibStub:NewLibrary(LIB_NAME, VERSION)
Expand Down Expand Up @@ -819,7 +819,7 @@ local function CraftComplete(event, station)
end
end
end
LibLazyCrafting.SendCraftEvent( LLC_NO_FURTHER_CRAFT_POSSIBLE , station,addon , nil )
LibLazyCrafting.SendCraftEvent( LLC_NO_FURTHER_CRAFT_POSSIBLE , station,nil , nil )
end


Expand Down
8 changes: 4 additions & 4 deletions LibLazyCrafting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
; States and/or other countries. All rights reserved.
; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms

## APIVersion: 101041
## Title: LibLazyCrafting v4.005
## Version: 4.005
## AddOnVersion: 4005
## APIVersion: 101042
## Title: LibLazyCrafting v4.009
## Version: 4.009
## AddOnVersion: 4009
## Author: Dolgubon
## Contributors: ziggr
## OptionalDependsOn: pChat LibStub HomeStationMarker
Expand Down
2 changes: 1 addition & 1 deletion Provisioning.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ local function getRecipeItemIdFromResultItemId(resultId)
end

local function CompileProvisioningRequirements(request)
request.timesToMake = request.quantity or 1
request.timesToMake = request.timesToMake or request.quantity or 1
local requirements = {}
local _,_,numIngredients = GetRecipeInfo(request.recipeListIndex, request.recipeIndex)
if not GetRecipeInfo(request.recipeListIndex, request.recipeIndex) then -- is recipe known?
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Improve the item at the specified bag index and slot index to the specified qual
### AddGlyphToExistingGear(existingRequestTable, gearBag, gearSlot)
- Same as the above, but the gear already exists, and you're waiting on the glyph to be made

### DeconstructSmithingItem(bagIndex, slotIndex, autocraft, reference)
- Takes in the bag and slot indexes of an item, and will deconstruct that item. Checks for the unique id before deconstructing, but if item has moved in the meantime, then it will not deconstruct

## Provisioning and Furniture
The exact same functions are used by both provisioning and furniture, so they are combined here. You can use the AKA functions as your preference/use requires.
Expand Down
291 changes: 194 additions & 97 deletions Smithing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ local function InternalImproveSmithingItem(self, BagIndex, SlotIndex, newQuality
--sortCraftQueue()
if not IsPerformingCraftProcess() and GetCraftingInteractionType()~=0 and not LibLazyCrafting.isCurrentlyCrafting[1] then
LibLazyCrafting.craftInteract(nil, GetCraftingInteractionType())

end
return craftingRequestTable
end
Expand All @@ -793,6 +792,41 @@ local function LLC_AddExistingGlyphToGear(self, existingRequestTable, glyphBag,
return
end


local function LLC_DeconstructItem(self, bagIndex, slotIndex, autocraft, reference)
local station = nil
for i = 1, 7 do
if CanItemBeDeconstructed(bagIndex, slotIndex, i) then
station = i
end
end
if not station then
d(GetItemLink(bagIndex, slotIndex)+" cannot be deconstructed at any crafting station. It may not be possible to deconstruct this item")
end

local craftingRequestTable =
{
["reference"] = reference or "",
["autocraft"] = autocraft or true,
["ItemLink"] = GetItemLink(bagIndex, slotIndex),
["itemUniqueId"] = GetItemUniqueId(bagIndex, slotIndex),
['itemStringUniqueId'] = Id64ToString(GetItemUniqueId(bagIndex, slotIndex)),
["station"] = station,
["timestamp"] = LibLazyCrafting.GetNextQueueOrder(),
["slotIndex"] = slotIndex,
["bagIndex"] = bagIndex,
["Requester"] = self.addonName,
["type"] = "deconstruct"
}
table.insert(craftingQueue[self.addonName][station], craftingRequestTable)
if not IsPerformingCraftProcess() and GetCraftingInteractionType()~=0 and not LibLazyCrafting.isCurrentlyCrafting[1] then
LibLazyCrafting.craftInteract(nil, GetCraftingInteractionType())
end
return craftingRequestTable
end

LibLazyCrafting.functionTable.DeconstructSmithingItem = LLC_DeconstructItem

LibLazyCrafting.functionTable.AddExistingGlyphToGear = LLC_AddExistingGlyph

LibLazyCrafting.functionTable.ImproveSmithingItem = LLC_ImproveSmithingItem
Expand Down Expand Up @@ -871,113 +905,151 @@ local craftingSounds =

}

local hasNewItemBeenMade = false
local function LLC_Smithing_MinorModuleInteraction(station, earliest, addon, position)
local parameters = {
earliest.pattern,
earliest.materialIndex,
earliest.materialQuantity,
earliest.style,
earliest.trait,
earliest.useUniversalStyleItem,
1,
}
setCorrectSetIndex_ConsolidatedStation(earliest.setIndex)
if earliest.style == LLC_FREE_STYLE_CHOICE then
parameters[4] = maxStyle(earliest)
end
local setPatternOffset = {14, 15,[6]=6,[7]=2}
if earliest.setIndex~=INDEX_NO_SET then
parameters[1] = parameters[1] + setPatternOffset[station]
end
parameters[7] = math.min(GetMaxIterationsPossibleForSmithingItem(unpack(parameters)), earliest.smithingQuantity or 1)
if (earliest.smithingQuantity or 1) > GetMaxIterationsPossibleForSmithingItem(unpack(parameters)) then
d("Mismatch asked quantity: "..earliest.smithingQuantity.." actual max "..GetMaxIterationsPossibleForSmithingItem(unpack(parameters)))
end
if parameters[7] == 0 then
return
end
dbug("CALL:ZOCraftSmithing")

local function LLC_SmithingCraftInteraction( station, earliest, addon , position)
dbug("EVENT:CraftIntBegin")
--abc = abc + 1 if abc>50 then d("raft")return end
LibLazyCrafting.isCurrentlyCrafting = {true, "smithing", earliest["Requester"]}
LibLazyCrafting:setWatchingForNewItems (true)

local earliest, addon , position = LibLazyCrafting.findEarliestRequest(station)
if earliest and not IsPerformingCraftProcess() then
if earliest.type =="smithing" then

local parameters = {
earliest.pattern,
earliest.materialIndex,
earliest.materialQuantity,
earliest.style,
earliest.trait,
earliest.useUniversalStyleItem,
1,
}
setCorrectSetIndex_ConsolidatedStation(earliest.setIndex)
if earliest.style == LLC_FREE_STYLE_CHOICE then
parameters[4] = maxStyle(earliest)
end
local setPatternOffset = {14, 15,[6]=6,[7]=2}
if earliest.setIndex~=INDEX_NO_SET then
parameters[1] = parameters[1] + setPatternOffset[station]
end
parameters[7] = math.min(GetMaxIterationsPossibleForSmithingItem(unpack(parameters)), earliest.smithingQuantity or 1)
if (earliest.smithingQuantity or 1) > GetMaxIterationsPossibleForSmithingItem(unpack(parameters)) then
d("Mismatch asked quantity: "..earliest.smithingQuantity.." actual max "..GetMaxIterationsPossibleForSmithingItem(unpack(parameters)))
end
if parameters[7] == 0 then
return
end
dbug("CALL:ZOCraftSmithing")
hasNewItemBeenMade = false

LibLazyCrafting.isCurrentlyCrafting = {true, "smithing", earliest["Requester"]}
LibLazyCrafting:setWatchingForNewItems (true)
if IsInGamepadPreferredMode() then -- Gamepad seems to not play craft sounds
PlaySound(craftingSounds[station])
end
CraftSmithingItem(unpack(parameters))
-- d(unpack(parameters))

hasNewItemBeenMade = false
currentCraftAttempt = copy(earliest)
currentCraftAttempt.position = position
currentCraftAttempt.callback = LibLazyCrafting.craftResultFunctions[addon]
currentCraftAttempt.slot = FindFirstEmptySlotInBag(BAG_BACKPACK)

if IsInGamepadPreferredMode() then -- Gamepad seems to not play craft sounds
PlaySound(craftingSounds[station])
end
CraftSmithingItem(unpack(parameters))
-- d(unpack(parameters))

currentCraftAttempt = copy(earliest)
currentCraftAttempt.position = position
currentCraftAttempt.callback = LibLazyCrafting.craftResultFunctions[addon]
currentCraftAttempt.slot = FindFirstEmptySlotInBag(BAG_BACKPACK)

parameters[6] = LINK_STYLE_DEFAULT

currentCraftAttempt.link = GetSmithingPatternResultLink(unpack(parameters))
--d("Making reference #"..tostring(currentCraftAttempt.reference).." link: "..currentCraftAttempt.link)
elseif earliest.type =="improvement" then
local parameters = {}
local currentSkill, maxSkill = getImprovementLevel(station)
local currentItemQuality = GetItemLinkQuality(GetItemLink(earliest.ItemBagID, earliest.ItemSlotID))
if earliest.quality == currentItemQuality then
dbug("ACTION:RemoveImprovementRequest")
d("Item is already at final quality, but LLC did not improve the item. It may have been improved by the user or another addon")
local returnTable = table.remove(craftingQueue[addon][station],position )
returnTable.bag = BAG_BACKPACK
LibLazyCrafting.SendCraftEvent( LLC_CRAFT_SUCCESS , station,addon , returnTable )
parameters[6] = LINK_STYLE_DEFAULT

currentCraftAttempt.link = GetSmithingPatternResultLink(unpack(parameters))
--d("Making reference #"..tostring(currentCraftAttempt.reference).." link: "..currentCraftAttempt.link)
end

currentCraftAttempt = {}
--sortCraftQueue()
LibLazyCrafting.craftInteract(nil, station)
LibLazyCrafting.DeleteHomeMarker(returnTable.setIndex, station)
return
end
if currentSkill~=maxSkill then
-- cancel if quality is already blue and skill is not max
-- This is to save on improvement mats.
local function LLC_improvement_MinorModuleInteraction(station, earliest, addon, position)
local parameters = {}
local currentSkill, maxSkill = getImprovementLevel(station)
local currentItemQuality = GetItemLinkQuality(GetItemLink(earliest.ItemBagID, earliest.ItemSlotID))
if earliest.quality == currentItemQuality then
dbug("ACTION:RemoveImprovementRequest")
d("Item is already at final quality, but LLC did not improve the item. It may have been improved by the user or another addon")
local returnTable = table.remove(craftingQueue[addon][station],position )
returnTable.bag = BAG_BACKPACK
LibLazyCrafting.SendCraftEvent( LLC_CRAFT_SUCCESS , station,addon , returnTable )

if earliest.quality>2 and currentItemQuality >ITEM_QUALITY_MAGIC then
d("Improvement skill is not at maximum. Improvement prevented to save mats.")
return
end
if station == CRAFTING_TYPE_JEWELRYCRAFTING and earliest.quality>1 and currentItemQuality >ITEM_QUALITY_NORMAL then
d("Improvement skill is not at maximum. Improvement prevented to save mats.")
return
end
end
local numBooster = GetMaxImprovementMats( earliest.ItemBagID,earliest.ItemSlotID,station)
if not numBooster then return end
local _,_, stackSize = GetSmithingImprovementItemInfo(station, currentItemQuality)
if stackSize< numBooster then
d("Not enough improvement mats")
return end
dbug("CALL:ZOImprovement")
LibLazyCrafting.isCurrentlyCrafting = {true, "improve", earliest["Requester"]}
if IsInGamepadPreferredMode() then
PlaySound(craftingSounds.improve)
end
ImproveSmithingItem(earliest.ItemBagID,earliest.ItemSlotID, numBooster)
currentCraftAttempt = copy(earliest)
currentCraftAttempt.position = position
currentCraftAttempt.callback = LibLazyCrafting.craftResultFunctions[addon]
currentCraftAttempt.previousQuality = currentItemQuality

currentCraftAttempt.link = GetSmithingImprovedItemLink(earliest.ItemBagID, earliest.ItemSlotID, station)
currentCraftAttempt = {}
--sortCraftQueue()
LibLazyCrafting.craftInteract(nil, station)
LibLazyCrafting.DeleteHomeMarker(returnTable.setIndex, station)
return
end
if currentSkill~=maxSkill then
-- cancel if quality is already blue and skill is not max
-- This is to save on improvement mats.

if earliest.quality>2 and currentItemQuality >ITEM_QUALITY_MAGIC then
d("Improvement skill is not at maximum. Improvement prevented to save mats.")
return
end
if station == CRAFTING_TYPE_JEWELRYCRAFTING and earliest.quality>1 and currentItemQuality >ITEM_QUALITY_NORMAL then
d("Improvement skill is not at maximum. Improvement prevented to save mats.")
return
end
end
local numBooster = GetMaxImprovementMats( earliest.ItemBagID,earliest.ItemSlotID,station)
if not numBooster then return end
local _,_, stackSize = GetSmithingImprovementItemInfo(station, currentItemQuality)
if stackSize< numBooster then
d("Not enough improvement mats")
return end
dbug("CALL:ZOImprovement")
LibLazyCrafting.isCurrentlyCrafting = {true, "improve", earliest["Requester"]}
if IsInGamepadPreferredMode() then
PlaySound(craftingSounds.improve)
end
ImproveSmithingItem(earliest.ItemBagID,earliest.ItemSlotID, numBooster)
currentCraftAttempt = copy(earliest)
currentCraftAttempt.position = position
currentCraftAttempt.callback = LibLazyCrafting.craftResultFunctions[addon]
currentCraftAttempt.previousQuality = currentItemQuality

currentCraftAttempt.link = GetSmithingImprovedItemLink(earliest.ItemBagID, earliest.ItemSlotID, station)
end

local function findAllDeconstructable()
end

-- ["reference"] = reference or "",
-- ["autocraft"] = autocraft or true,
-- ["ItemLink"] = GetItemLink(bagIndex, slotIndex),
-- ["itemUniqueId"] = GetItemUniqueId(bagIndex, slotIndex),
-- ['itemStringUniqueId'] = Id64ToString(GetItemUniqueId(bagIndex, slotIndex)),
-- ["station"] = station,
-- ["timestamp"] = LibLazyCrafting.GetNextQueueOrder(),
-- ["type"] = "deconstruct"
local function LLC_Deconstruction_MinorModuleInteraction(station, earliest, addon, position)
if GetItemUniqueId(earliest.bagIndex, earliest.slotIndex) == earliest.itemUniqueId then
currentCraftAttempt = {}
currentCraftAttempt = copy(earliest)
PrepareDeconstructMessage()
AddItemToDeconstructMessage(earliest.bagIndex, earliest.slotIndex, 1)
SendDeconstructMessage()
end
dbug("Not implemented yet")

end

local function LLC_Research_MinorModuleInteraction(station, earliest, addon, position)
dbug("Not implemented yet")
end

local smithingMinorModuleFunctions =
{
["smithing"] = LLC_Smithing_MinorModuleInteraction,
["improvement"] = LLC_improvement_MinorModuleInteraction,
["deconstruct"] = LLC_Deconstruction_MinorModuleInteraction,
["research"] = LLC_Research_MinorModuleInteraction,

}

local hasNewItemBeenMade = false

local function LLC_SmithingCraftInteraction( station, earliest, addon , position)
dbug("EVENT:CraftIntBegin")
--abc = abc + 1 if abc>50 then d("raft")return end

local earliest, addon , position = LibLazyCrafting.findEarliestRequest(station)
if earliest and not IsPerformingCraftProcess() then
smithingMinorModuleFunctions[earliest.type](station, earliest, addon, position)
--ImproveSmithingItem(number itemToImproveBagId, number itemToImproveSlotIndex, number numBoostersToUse)
--GetSmithingImprovedItemLink(number itemToImproveBagId, number itemToImproveSlotIndex, number TradeskillType craftingSkillType, number LinkStyle linkStyle)
else
Expand Down Expand Up @@ -1170,6 +1242,28 @@ local function SmithingCraftCompleteFunction(station)
currentCraftAttempt = {}
--sortCraftQueue()
backupPosition = nil
-- ["reference"] = reference or "",
-- ["autocraft"] = autocraft or true,
-- ["ItemLink"] = GetItemLink(bagIndex, slotIndex),
-- ["itemUniqueId"] = GetItemUniqueId(bagIndex, slotIndex),
-- ['itemStringUniqueId'] = Id64ToString(GetItemUniqueId(bagIndex, slotIndex)),
-- ["station"] = station,
-- ["timestamp"] = LibLazyCrafting.GetNextQueueOrder(),
-- ["type"] = "deconstruct"
-- LLC_Global:DeconstructSmithingItem
elseif currentCraftAttempt.type == "deconstruct" then
local id64 = GetItemUniqueId(currentCraftAttempt.bagIndex, currentCraftAttempt.slotIndex)
if id64 ~= currentCraftAttempt.itemUniqueId then
local addonName, position = removedRequest(station, currentCraftAttempt.timestamp)
if addonName then
returnTable = table.remove(craftingQueue[addonName][station],position)
local copiedTable = LibLazyCrafting.tableShallowCopy(returnTable)
LibLazyCrafting.SendCraftEvent(LLC_CRAFT_SUCCESS, station, returnTable.Requester, copiedTable )
end
end
currentCraftAttempt = {}
backupPosition = nil

else
return
end
Expand Down Expand Up @@ -1931,6 +2025,9 @@ LibLazyCrafting.craftInteractionTables[CRAFTING_TYPE_BLACKSMITHING] =
end
return true
end
if request["type"] == "deconstruct" then
return true
end
if canCraftItemHere(station, request["setIndex"]) and canCraftItem(request) and enoughMaterials(request) then
return true
else
Expand Down

0 comments on commit 3a462bb

Please sign in to comment.