Skip to content

Commit

Permalink
Moved TopFit:GetSetItemFromSlot(slotID, set) to Set:GetItemInSlot(slo…
Browse files Browse the repository at this point in the history
…tID).

Added function Set:CanItemGoInSlot(item, slotID) that validates item types & dual wielding.
  • Loading branch information
ckaotik committed Mar 23, 2015
1 parent cf1db68 commit 7bde094
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 48 deletions.
2 changes: 1 addition & 1 deletion TopFit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ local function EvaluateNewItems(newItems)
local itemTable = ns:GetCachedItem(newItem)
for _, slotID in pairs(itemTable.equipLocationsByType) do
-- try to get the currently used item from the player's equipment set
local setItem = ns:GetSetItemFromSlot(slotID, set)
local setItem = set:GetItemInSlot(slotID)
local setItemTable = ns:GetCachedItem(setItem)
if setItem and setItemTable then
-- if either score or any cap is higher than currently equipped, calculate
Expand Down
37 changes: 0 additions & 37 deletions inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,6 @@ function TopFit:ClearCache()
TopFit.scoresCache = {}
end

--TODO: move into set
function TopFit:GetSetItemFromSlot(slotID, set)
local itemLink = nil
local setName = TopFit:GenerateSetName(set:GetName())
local itemPositions = GetEquipmentSetLocations(setName)
if itemPositions then
if slotID == _G.INVSLOT_OFFHAND then
-- check mainhand: can't use OH with 2H weapon w/o DW
local item = GetEquipmentSetItemIDs(setName)[_G.INVSLOT_MAINHAND]
if item and set:IsOnehandedWeapon(item) == false then
return nil
end
end

local itemLocation = itemPositions[slotID]
if itemLocation and itemLocation ~= 1 and itemLocation ~= 0 then
local player, bank, bags, _, slot, bag = EquipmentManager_UnpackLocation(itemLocation)
if player then
if bank then
-- item is banked, use itemID
local itemID = GetEquipmentSetItemIDs(setName)[slotID]
if itemID and itemID ~= 1 then
_, itemLink = GetItemInfo(itemID)
end
elseif bags then
-- item is in player's bags
itemLink = GetContainerItemLink(bag, slot)
else
-- item is equipped
itemLink = GetInventoryItemLink("player", slot)
end
end
end
end
return itemLink
end

--- Gather all items from inventory and bags and save their info to cache.
-- @param bag Limit collection to this bag.
function ns:updateItemsCache(bag)
Expand Down
45 changes: 35 additions & 10 deletions set.class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,24 +457,49 @@ function Set:IsOnehandedWeapon(item)
if not itemTable then return nil end

-- item might not have been a weapon at all
if itemTable.equipLocationsByType[1] ~= 16 and itemTable.equipLocationsByType[1] ~= 17 then
if not itemTable.itemEquipLoc or itemTable.itemEquipLoc == ''
or (not tContains(itemTable.equipLocationsByType, INVSLOT_MAINHAND)
and not tContains(itemTable.equipLocationsByType, INVSLOT_OFFHAND)) then
return nil
end

if itemTable.itemEquipLoc and string.find(itemTable.itemEquipLoc, "2HWEAPON") then
if (self:CanTitansGrip()) then
if itemTable.subclass == POLEARMS or itemTable.subclass == STAVES or itemTable.subclass == FISHINGPOLES then
return false
end
else
return false
end
elseif itemTable.itemEquipLoc and string.find(itemTable.itemEquipLoc, "RANGED") then
if itemTable.itemEquipLoc:find('2HWEAPON') then
return self:CanTitansGrip() and not (itemTable.subclass == POLEARMS or itemTable.subclass == STAVES or itemTable.subclass == FISHINGPOLES)
elseif itemTable.itemEquipLoc:find('RANGED') then
return itemTable.subClass == WANDS
end
return true
end

function Set:CanItemGoInSlot(item, slotID)
local itemTable = type(item) == 'table' and item or TopFit:GetCachedItem(item)
if not itemTable then return nil end

local canGoInSlot = tContains(itemTable.equipLocationsByType, slotID)
and not ns.Unfit:IsClassUnusable(itemTable.subClass, itemTable.itemEquipLoc)
if canGoInSlot and slotID == INVSLOT_OFFHAND and self:IsOnehandedWeapon(itemTable) then
-- check offhand item type
canGoInSlot = self:CanDualWield() -- weapons only work with dual wield
or itemTable.itemEquipLoc == 'INVTYPE_HOLDABLE'
or itemTable.itemEquipLoc == 'INVTYPE_SHIELD'
end
-- TODO: check for forced types, e.g. OH:shield or MH:dagger
return canGoInSlot
end

function Set:GetItemInSlot(slotID)
local locationBySlot = GetEquipmentSetLocations(self:GetEquipmentSetName())
local location = locationBySlot and locationBySlot[slotID]
if location and location <= 0 then location = nil end
if location and slotID == INVSLOT_OFFHAND then
-- can't use OH when MH item is wielded 2H
if self:IsOnehandedWeapon(locationBySlot[INVSLOT_MAINHAND]) == false then
location = nil
end
end
return location and select(3, ns.ItemLocations:GetLocationItemInfo(location)) or nil
end

function Set:SetDisplayInTooltip(enable)
self.displayInTooltip = enable and true or false
if self.savedVariables then
Expand Down

0 comments on commit 7bde094

Please sign in to comment.