Skip to content

Commit

Permalink
Initial Furniture support
Browse files Browse the repository at this point in the history
Main LLC file has been modified to handle furniture requests
Provisioning file has been modified to now also do furniture crafting at any station
Hid a exposed global variable
Added getItemLinkFromItemId to the function table
Added aliases for the craft provisioning functions
Removed an unused zo_callLater
Added a readMe, and actually made it up to date! Probably. Should be. The main stuff is there anyway.
Grand Master crafting station updates and fixes
  • Loading branch information
Dolgubon committed Jan 8, 2024
1 parent bd3b47a commit bac2fc0
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 129 deletions.
78 changes: 39 additions & 39 deletions Enchanting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -506,47 +506,47 @@ local function wasItemMade(bag, slot)
and GetItemLinkQuality(GetItemLink(BAG_BACKPACK, slot,0)) == GetItemLinkQuality(currentCraftAttempt.link)
end
local function handleEnchantComplete(station, slot)
-- We found it!
dbug("ACTION:RemoveQueueItem")
local removedTable = craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING][currentCraftAttempt.position]
if (currentCraftAttempt.quantity or 1) <= 1 then
removedTable = table.remove(craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING] , currentCraftAttempt.position )
removedTable.quantity = removedTable.quantity - 1
currentCraftAttempt.quantity = currentCraftAttempt.quantity - 1

LibLazyCrafting.DeleteHomeMarker(nil, CRAFTING_TYPE_ENCHANTING)
else
removedTable = craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING][currentCraftAttempt.position]
removedTable.quantity = removedTable.quantity - 1
currentCraftAttempt.quantity = currentCraftAttempt.quantity - 1
end
if removedTable.dualEnchantingSmithing then
removedTable.glyphInfo= removedTable.glyphInfo or {}
table.insert(removedTable.glyphInfo,
{
bag=BAG_BACKPACK,
slot=slot,
uniqueId=GetItemUniqueId(BAG_BACKPACK, slot),
uniqueIdString = Id64ToString(GetItemUniqueId(BAG_BACKPACK, slot)),
})
removedTable.glyphBag = BAG_BACKPACK
removedTable.glyphSlot = slot
removedTable['glyphUniqueId'] = GetItemUniqueId(removedTable.glyphBag, removedTable.glyphSlot)
removedTable['glyphStringUniqueId'] = Id64ToString(removedTable['glyphUniqueId'])
return removedTable
end
--sortCraftQueue()
local resultTable =
-- We found it!
dbug("ACTION:RemoveQueueItem")
local removedTable = craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING][currentCraftAttempt.position]
if (currentCraftAttempt.quantity or 1) <= 1 then
removedTable = table.remove(craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING] , currentCraftAttempt.position )
removedTable.quantity = removedTable.quantity - 1
currentCraftAttempt.quantity = currentCraftAttempt.quantity - 1

LibLazyCrafting.DeleteHomeMarker(nil, CRAFTING_TYPE_ENCHANTING)
else
removedTable = craftingQueue[currentCraftAttempt.Requester][CRAFTING_TYPE_ENCHANTING][currentCraftAttempt.position]
removedTable.quantity = removedTable.quantity - 1
currentCraftAttempt.quantity = currentCraftAttempt.quantity - 1
end
if removedTable.dualEnchantingSmithing then
removedTable.glyphInfo= removedTable.glyphInfo or {}
table.insert(removedTable.glyphInfo,
{
["bag"] = BAG_BACKPACK,
["slot"] = slot,
['link'] = currentCraftAttempt.link,
['uniqueId'] = GetItemUniqueId(BAG_BACKPACK, currentCraftAttempt.slot),
["quantity"] = removedTable.quantity,
["reference"] = removedTable.reference,
}
LibLazyCrafting.SendCraftEvent( LLC_CRAFT_SUCCESS , station, removedTable.Requester , resultTable )
bag=BAG_BACKPACK,
slot=slot,
uniqueId=GetItemUniqueId(BAG_BACKPACK, slot),
uniqueIdString = Id64ToString(GetItemUniqueId(BAG_BACKPACK, slot)),
})
removedTable.glyphBag = BAG_BACKPACK
removedTable.glyphSlot = slot
removedTable['glyphUniqueId'] = GetItemUniqueId(removedTable.glyphBag, removedTable.glyphSlot)
removedTable['glyphStringUniqueId'] = Id64ToString(removedTable['glyphUniqueId'])
return removedTable
end
--sortCraftQueue()
local resultTable =
{
["bag"] = BAG_BACKPACK,
["slot"] = slot,
['link'] = currentCraftAttempt.link,
['uniqueId'] = GetItemUniqueId(BAG_BACKPACK, currentCraftAttempt.slot),
["quantity"] = removedTable.quantity,
["reference"] = removedTable.reference,
}
LibLazyCrafting.SendCraftEvent( LLC_CRAFT_SUCCESS , station, removedTable.Requester , resultTable )
return removedTable
end

local function LLC_EnchantingCraftingComplete(station, lastCheck)
Expand Down
4 changes: 1 addition & 3 deletions LLC.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ functions.lua

;------------
;Furnishings:
;At the moment, furniture is not handled. Adding furniture would require additional changes to either all of the current craft files, or to the core
;LLC file, so that it can handle furniture. If you would like to use the featues of the library for furniture, I will consider adding support in.

;Furniture crafting uses the exact same functions as Provisinoing.

83 changes: 42 additions & 41 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", 3.086
local LIB_NAME, VERSION = "LibLazyCrafting", 3.0865
local LibLazyCrafting, oldminor
if LibStub then
LibLazyCrafting, oldminor = LibStub:NewLibrary(LIB_NAME, VERSION)
Expand Down Expand Up @@ -207,16 +207,10 @@ end

-- Mostly a queue function, but kind of a helper function too
local function isItemCraftable(request, station)

if LibLazyCrafting.craftInteractionTables[station].isItemCraftable then

return LibLazyCrafting.craftInteractionTables[station]:isItemCraftable(station, request)
end

if station ==CRAFTING_TYPE_ENCHANTING or station == CRAFTING_TYPE_PROVISIONING or station == CRAFTING_TYPE_ALCHEMY then
return true
local stationToUse = request.recipeIndex and CRAFTING_TYPE_PROVISIONING or station
if LibLazyCrafting.craftInteractionTables[stationToUse].isItemCraftable then
return LibLazyCrafting.craftInteractionTables[stationToUse]:isItemCraftable(station, request)
end

end

function findItemLocationById(itemID)
Expand Down Expand Up @@ -305,7 +299,7 @@ function LibLazyCrafting.stackableCraftingComplete(station, lastCheck, craftingT
dbug("RESULT:StackableMade")
if currentCraftAttempt["timesToMake"] < 2 then
dbug("ACTION:RemoveQueueItem")
table.remove( craftingQueue[currentCraftAttempt.addon][craftingType] , currentCraftAttempt.position )
table.remove( craftingQueue[currentCraftAttempt.addon][station] , currentCraftAttempt.position )
--LibLazyCrafting.sortCraftQueue()
local resultTable =
{
Expand All @@ -321,18 +315,18 @@ function LibLazyCrafting.stackableCraftingComplete(station, lastCheck, craftingT
LibLazyCrafting.DeleteHomeMarker(nil, station)
else
-- Loop to craft multiple copies
local earliest = craftingQueue[currentCraftAttempt.addon][craftingType][currentCraftAttempt.position]
local earliest = craftingQueue[currentCraftAttempt.addon][station][currentCraftAttempt.position]
earliest.timesToMake = earliest.timesToMake - 1
currentCraftAttempt.timesToMake = earliest.timesToMake
if GetCraftingInteractionType()==0 then zo_callLater(function() LibLazyCrafting.stackableCraftingComplete( station, true, craftingType, currentCraftAttempt) end,100) end
if GetCraftingInteractionType()==0 then zo_callLater(function() LibLazyCrafting.stackableCraftingComplete( station, true, station, currentCraftAttempt) end,100) end
end
elseif lastCheck then
-- give up on finding it.
tableClear(currentCraftAttempt)
else
-- further search
-- search again later
if GetCraftingInteractionType()==0 then zo_callLater(function() LibLazyCrafting.stackableCraftingComplete( station, true, craftingType, currentCraftAttempt) end,100) end
if GetCraftingInteractionType()==0 then zo_callLater(function() LibLazyCrafting.stackableCraftingComplete( station, true, station, currentCraftAttempt) end,100) end
end
end

Expand Down Expand Up @@ -374,6 +368,9 @@ local function getItemLinkFromItemId(itemId) local name = GetItemLinkName(ZO_Lin
return ZO_LinkHandler_CreateLink(zo_strformat("<<t:1>>",name), nil, ITEM_LINK_TYPE,itemId, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
end

LibLazyCrafting.getItemLinkFromItemId = getItemLinkFromItemId
LibLazyCrafting.functionTable.getItemLinkFromItemId = getItemLinkFromItemId

function LibLazyCrafting.HaveMaterials(materialList)
for _, mat in ipairs(materialList) do
local itemLink = mat.itemLink
Expand Down Expand Up @@ -409,7 +406,6 @@ end
LibLazyCrafting.sortCraftQueue = sortCraftQueue


local abc = 1
-- Finds the highest priority request.
local function findEarliestRequest(station)
local earliest = {["timestamp"] = GetTimeStamp() + 100000} -- should be later than anything else, as it's 'in the future'
Expand Down Expand Up @@ -709,7 +705,7 @@ end
-- If it is a string, simply check to see if the user's name is the optional debug name for the addon, throw an error
-- if it is true, always throw the error.

local function LLCThrowError(addonNameOrTableOrAlwaysThrow, message)
local function LLCThrowError(addonNameOrTable, message)
local addonName
if type(addonNameOrTable)=="table" then
addonName = addonNameOrTable.addonName
Expand All @@ -729,24 +725,30 @@ LLC.LLCThrowError = LLCThrowError
------------------------------------------------------
-- CRAFT EVENT HANDLERS

-- Helper function. Finds the earliest craftable request, then crafts it using the relevant crafting function
-- Return true if we started crafting something
local function CraftEarliest(event, station)
local stationInteractionTable = LibLazyCrafting.craftInteractionTables[station]
local earliest, addon , position = LibLazyCrafting.findEarliestRequest(station)
if not earliest then return false end
if earliest.recipeIndex then -- is furniture/recipe
LibLazyCrafting.craftInteractionTables[CRAFTING_TYPE_PROVISIONING]["function"]( station, earliest, addon , position)
return true
else
stationInteractionTable["function"]( station, earliest, addon , position)
return true
end
end

-- Called when a crafting station is opened. Should then craft anything needed in the queue
local function CraftInteract(event, station)
if IsPerformingCraftProcess() then
return
end
for k,v in pairs(LibLazyCrafting.craftInteractionTables) do
if v:check( station) then
local earliest, addon , position = LibLazyCrafting.findEarliestRequest(station)
if earliest then
if earliest.isFurniture then
if v.canCraftFurniture then
v["function"]( station, earliest, addon , position)
return
end
else
v["function"]( station, earliest, addon , position)
return
end
if CraftEarliest(event, station) then
return
end
end
end
Expand Down Expand Up @@ -778,24 +780,23 @@ local function CraftComplete(event, station)
for k,v in pairs(LibLazyCrafting.craftInteractionTables) do
if v:check( station) then
if GetCraftingInteractionType()==0 then -- This is called when the user exits the crafting station while the game is crafting

endInteraction(EVENT_END_CRAFTING_STATION_INTERACT, station)
zo_callLater(function() v["complete"]( station) LibLazyCrafting.isCurrentlyCrafting = {false, "", ""} end, timetest)
if LibLazyCrafting.recipeCurrentCraftAttempt and LibLazyCrafting.recipeCurrentCraftAttempt.recipeIndex then
LibLazyCrafting.craftInteractionTables[CRAFTING_TYPE_PROVISIONING]["complete"](station)
else
v["complete"]( station)
end
LibLazyCrafting.isCurrentlyCrafting = {false, "", ""}
return
else
v["complete"]( station)
if LibLazyCrafting.recipeCurrentCraftAttempt and LibLazyCrafting.recipeCurrentCraftAttempt.recipeIndex then
LibLazyCrafting.craftInteractionTables[CRAFTING_TYPE_PROVISIONING]["complete"](station)
else
v["complete"]( station)
end
LibLazyCrafting.isCurrentlyCrafting = {false, "", ""}
local earliest, addon , position = LibLazyCrafting.findEarliestRequest(station)
if earliest then
if earliest.isFurniture then
if v.canCraftFurniture then
v["function"]( station, earliest, addon , position)
return
end
else
v["function"]( station, earliest, addon , position)
return
end
if CraftEarliest(event, station) then
return
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions LibLazyCrafting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms

## APIVersion: 101040
## Title: LibLazyCrafting v3.086
## Version: 3.086
## Title: LibLazyCrafting v3.0865
## Version: 3.0865
## Author: Dolgubon
## Contributors: ziggr
## OptionalDependsOn: pChat LibStub HomeStationMarker
Expand Down
Loading

0 comments on commit bac2fc0

Please sign in to comment.