Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/Classes/ImportTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -691,18 +691,11 @@ function ImportTabClass:ImportPassiveTreeAndJewels(charData)
self.build.treeTab.controls.versionSelect.selIndex = #self.build.treeTab.treeVersions
-- attributes nodes
for skillId, nodeInfo in pairs(charPassiveData.skill_overrides) do
local changeAttributeId = 0
if nodeInfo.name == "Intelligence" then
changeAttributeId = 3
elseif nodeInfo.name == "Dexterity" then
changeAttributeId = 2
elseif nodeInfo.name == "Strength" then
changeAttributeId = 1
end

if changeAttributeId > 0 then
local id = tonumber(skillId)
self.build.spec:SwitchAttributeNode(id, changeAttributeId)
local id = tonumber(skillId)
local changeAttributeIndex = self.build.spec:GetAttributeIndexForNodeId(id, nodeInfo.name)

if changeAttributeIndex > 0 then
self.build.spec:SwitchAttributeNode(id, changeAttributeIndex)
local node = self.build.spec.nodes[id]

if node then
Expand Down
173 changes: 159 additions & 14 deletions src/Classes/PassiveSpec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,30 @@
for _, child in ipairs(node) do
if child.elem == "AttributeOverride" then
for strengthId in child.attrib.strNodes:gmatch("%d+") do
self:SwitchAttributeNode(tonumber(strengthId), 1)
local strengthNumberId = tonumber(strengthId)
local atributeIndex = self:GetAttributeIndexForNodeId(strengthNumberId, "Strength")

Check warning on line 194 in src/Classes/PassiveSpec.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (atribute)
self:SwitchAttributeNode(strengthNumberId, atributeIndex)

Check warning on line 195 in src/Classes/PassiveSpec.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (atribute)
end
for dexterityId in child.attrib.dexNodes:gmatch("%d+") do
self:SwitchAttributeNode(tonumber(dexterityId), 2)
local dexterityNumberId = tonumber(dexterityId)
local atributeIndex = self:GetAttributeIndexForNodeId(dexterityNumberId, "Dexterity")

Check warning on line 199 in src/Classes/PassiveSpec.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (atribute)
self:SwitchAttributeNode(dexterityNumberId, atributeIndex)

Check warning on line 200 in src/Classes/PassiveSpec.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (atribute)
end
for intelligenceId in child.attrib.intNodes:gmatch("%d+") do
self:SwitchAttributeNode(tonumber(intelligenceId), 3)
local intelligenceNumberId = tonumber(intelligenceId)
local atributeIndex = self:GetAttributeIndexForNodeId(intelligenceNumberId, "Intelligence")

Check warning on line 204 in src/Classes/PassiveSpec.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (atribute)
self:SwitchAttributeNode(intelligenceNumberId, atributeIndex)
end
-- check if have child elems for other attribute types
for _, other in ipairs(child) do
if other.elem == "other" then
local otherId = tonumber(other.attrib.id)
local dn = other.attrib.dn
local atributeIndex = self:GetAttributeIndexForNodeId(otherId, dn)
self:SwitchAttributeNode(otherId, atributeIndex)
end
end

else
ConPrintf("[PassiveSpecClass:Load] Unexpected element found in Overrides: " .. child.elem)
end
Expand Down Expand Up @@ -281,7 +297,7 @@
elem = "Overrides"
}
if self.hashOverrides then
local strList, dexList, intList = { }, { }, { }
local strList, dexList, intList, others = { }, { }, { }, { }
for nodeId, node in pairs(self.hashOverrides) do
if node.isAttribute then
if node.dn == "Strength" then
Expand All @@ -290,10 +306,18 @@
t_insert(dexList, nodeId)
elseif node.dn == "Intelligence" then
t_insert(intList, nodeId)
else
-- other attribute types not currently supported
t_insert(others, { elem = "other", attrib = {id=tostring(nodeId), dn=tostring(node.dn)} })
end
end
end
local attributeOverride = { elem = "AttributeOverride", attrib = { strNodes = table.concat(strList, ","), dexNodes = table.concat(dexList, ","), intNodes = table.concat(intList, ",") } }
if #others > 0 then
for _, other in pairs(others) do
t_insert(attributeOverride, other)
end
end
t_insert(overrides, attributeOverride)
end
t_insert(xml, overrides)
Expand Down Expand Up @@ -1221,7 +1245,16 @@

-- set attribute nodes
if self.hashOverrides[node.id] then
self:ReplaceNode(node, self.hashOverrides[node.id])
-- before building path we need to check for hashOverrides still valid
local overrideNode = self.hashOverrides[node.id]
if self:IsUnlockedAttributeForNodeId(node.id, overrideNode.dn) then
-- valid override
self:ReplaceNode(node, self.hashOverrides[node.id])
else
-- invalid override, remove it
self.hashOverrides[node.id] = nil
self:ReplaceNode(node, self.tree.nodes[node.id])
end
end

-- If node is conquered, replace it or add mods
Expand Down Expand Up @@ -2352,14 +2385,126 @@
end

function PassiveSpecClass:SwitchAttributeNode(nodeId, attributeIndex)
if self.tree.nodes[nodeId] then --Make sure node exists on current tree
local newNode = copyTableSafe(self.tree.nodes[nodeId], false, true)
if not newNode.isAttribute then return end -- safety check

local option = newNode.options[attributeIndex]
self:ReplaceNode(newNode, option)
self.tree:ProcessStats(newNode)

self.hashOverrides[nodeId] = newNode
if not self.tree.nodes[nodeId] then --Make sure node exists on current tree
return
end

local newNode = copyTableSafe(self.tree.nodes[nodeId], false, true)
if not newNode.isAttribute then return end -- safety check

-- check if attributeIndex is valid
if attributeIndex < 1 or attributeIndex > #newNode.options then
return
end

local option = newNode.options[attributeIndex]

-- check if the option have "unlockedBy" and check in the spec if this is allocated
if option.unlockedBy then
local unlocked = false
for _, unlockNodeId in ipairs(option.unlockedBy) do
if self.allocNodes[unlockNodeId] then
unlocked = true
break
end
end
if not unlocked then
return
end
end

self:ReplaceNode(newNode, option)
self.tree:ProcessStats(newNode)

self.hashOverrides[nodeId] = newNode
end

function PassiveSpecClass:GetAttributeIndexForNodeId(nodeId, attributeName)
local node = self.tree.nodes[nodeId]
if not node then return 0 end --Make sure node exists on current tree
if not node.isAttribute then return 0 end -- safety check
for index, option in ipairs(node.options) do
if option.dn == attributeName then
return index
end
end
return 0
end

function PassiveSpecClass:GetUnlockedAttributeListForNodeId(nodeId)
local node = self.tree.nodes[nodeId]
if not node then return {} end --Make sure node exists on current tree
if not node.isAttribute then return {} end -- safety check
local attributeList = {}
for index, option in ipairs(node.options) do
if option.unlockedBy then
local unlocked = false
for _, unlockNodeId in ipairs(option.unlockedBy) do
if self.allocNodes[unlockNodeId] then
unlocked = true
break
end
end
if unlocked then
t_insert(attributeList, option.dn)
end
else
t_insert(attributeList, option.dn)
end
end
return attributeList
end

function PassiveSpecClass:IsUnlockedAttributeForNodeId(nodeId, attributeName)
local node = self.tree.nodes[nodeId]
if not node then return false end --Make sure node exists on current tree
if not node.isAttribute then return false end -- safety check

for index, option in ipairs(node.options) do
if option.dn == attributeName then
-- check if the option have "unlockedBy" and check in the spec if
if option.unlockedBy then
local unlocked = false
for _, unlockNodeId in ipairs(option.unlockedBy) do
if self.allocNodes[unlockNodeId] then
unlocked = true
break
end
end
return unlocked
end
return true
end
end
return false
end

function PassiveSpecClass:GetNextAttributeIndexForNodeId(nodeId, currentAttributeName)
local node = self.tree.nodes[nodeId]
if not node then return 1 end --Make sure node exists on current tree
if not node.isAttribute then return 1 end -- safety check
local foundCurrent = false
for index, option in ipairs(node.options) do
if foundCurrent then
-- check if the option have "unlockedBy" and check in the spec if this is allocated
if option.unlockedBy then
local unlocked = false
for _, unlockNodeId in ipairs(option.unlockedBy) do
if self.allocNodes[unlockNodeId] then
unlocked = true
break
end
end
if unlocked then
return index
end
else
return index
end
end
if option.dn == currentAttributeName then
foundCurrent = true
end
end
return 1
end
20 changes: 7 additions & 13 deletions src/Classes/PassiveTreeView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
-- we always want to keep track of last used attribute
local function processAttributeHotkeys(switchAttribute)
if IsKeyDown("2") or IsKeyDown("S") then
spec.attributeIndex = 1
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, 1) end
spec.attributeIndex = spec:GetAttributeIndexForNodeId(hoverNode.id, "strength")
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, spec.attributeIndex) end
elseif IsKeyDown("3") or IsKeyDown("D") then
spec.attributeIndex = 2
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, 2) end
spec.attributeIndex = spec:GetAttributeIndexForNodeId(hoverNode.id, "dexterity")
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, spec.attributeIndex) end
elseif IsKeyDown("1") or IsKeyDown("I") then
spec.attributeIndex = 3
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, 3) end
spec.attributeIndex = spec:GetAttributeIndexForNodeId(hoverNode.id, "intelligence")
if switchAttribute then spec:SwitchAttributeNode(hoverNode.id, spec.attributeIndex) end
end
end

Expand Down Expand Up @@ -449,13 +449,7 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
processAttributeHotkeys(hoverNode.isAttribute)
elseif hoverNode.isAttribute then
-- If the attribute node is already set to str, int, or dex create a toggle effect between attrs
if hoverNode.dn == "Intelligence" then
spec.attributeIndex = 1
elseif hoverNode.dn == "Dexterity" then
spec.attributeIndex = 3
elseif hoverNode.dn == "Strength" then
spec.attributeIndex = 2
end
spec.attributeIndex = spec:GetNextAttributeIndexForNodeId(hoverNode.id, hoverNode.dn)
spec:SwitchAttributeNode(hoverNode.id, spec.attributeIndex or 1)
end
spec:AllocNode(hoverNode, self.tracePath and hoverNode == self.tracePath[#self.tracePath] and self.tracePath)
Expand Down
7 changes: 4 additions & 3 deletions src/Classes/TreeTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,13 @@ end
function TreeTabClass:ModifyAttributePopup(hoverNode)
local controls = { }
local spec = self.build.spec
local attributes = { "Strength", "Dexterity", "Intelligence" }
local attributes = spec:GetUnlockedAttributeListForNodeId(hoverNode.id)

controls.attrSelect = new("DropDownControl", {"TOPLEFT",nil,"TOPLEFT"}, {225, 30, 100, 18}, attributes, nil)
controls.save = new("ButtonControl", nil, {-50, 65, 80, 20}, "Allocate", function()
spec:SwitchAttributeNode(hoverNode.id, controls.attrSelect.selIndex)
spec.attributeIndex = controls.attrSelect.selIndex
local attributeIndex = spec:GetAttributeIndexForNodeId(hoverNode.id, controls.attrSelect:GetSelValue())
spec:SwitchAttributeNode(hoverNode.id, attributeIndex)
spec.attributeIndex = attributeIndex
spec:AllocNode(hoverNode, spec.tracePath and hoverNode == spec.tracePath[#spec.tracePath] and spec.tracePath)
spec:AddUndoState()
self.build.buildFlag = true
Expand Down
36 changes: 19 additions & 17 deletions src/Export/Scripts/passivetree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -781,15 +781,18 @@ end

-- for now we are hardcoding attributes id
local base_attributes = {
[26297] = {}, -- str
[14927] = {}, -- dex
[57022] = {}--int
{id=26297}, -- str
{id=14927}, -- dex
{id=57022}, --int
{id=46793, unlockedBy = {46454}}, -- Damage
{id=44242, unlockedBy = {46454}}, -- Defences
{id=5375, unlockedBy = {46454}}, -- Coost efficiency
}

for id, _ in pairs(base_attributes) do
local base = dat("passiveskills"):GetRow("PassiveSkillNodeId", id)
for _, attrInfo in ipairs(base_attributes) do
local base = dat("passiveskills"):GetRow("PassiveSkillNodeId", attrInfo.id)
if base == nil then
printf("Base attribute " .. id .. " not found")
printf("Base attribute " .. attrInfo.id .. " not found")
goto continue
end

Expand All @@ -798,11 +801,10 @@ for id, _ in pairs(base_attributes) do
goto continue
end

local attribute = {
["name"] = base.Name,
["icon"] = base.Icon,
["stats"] = {},
}
local attribute = attrInfo
attribute["name"] = base.Name
attribute["icon"] = base.Icon
attribute["stats"] = {}

-- Stats
if base.Stats ~= nil then
Expand All @@ -817,7 +819,6 @@ for id, _ in pairs(base_attributes) do
end

addToSheet(getSheet("skills"), base.Icon, "normalActive", commonMetadata(nil))
base_attributes[id] = attribute
:: continue ::
end

Expand Down Expand Up @@ -1015,12 +1016,13 @@ for i, group in ipairs(psg.groups) do
if passiveRow.Attribute == true then
node["options"] = {}
node["isAttribute"] = true
for attId, value in pairs(base_attributes) do
for _, attrInfo in ipairs(base_attributes) do
table.insert(node["options"], {
["id"] = attId,
["name"] = base_attributes[attId].name,
["icon"] = base_attributes[attId].icon,
["stats"] = base_attributes[attId].stats,
["id"] = attrInfo.id,
["name"] = attrInfo.name,
["icon"] = attrInfo.icon,
["stats"] = attrInfo.stats,
["unlockedBy"] = attrInfo.unlockedBy,
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/TreeData/0_4/tree.json

Large diffs are not rendered by default.

Loading
Loading