diff --git a/spec/System/TestMercenaryWarrant_spec.lua b/spec/System/TestMercenaryWarrant_spec.lua new file mode 100644 index 00000000000..27d4b357df2 --- /dev/null +++ b/spec/System/TestMercenaryWarrant_spec.lua @@ -0,0 +1,150 @@ +local warrantParser = require("Modules.MercenaryWarrantParser") + +local sampleWarrant = [[ +Mercenary Warrant +-------- +Lotha, the Cynic +-------- +Build: Stormhand +Mercenary Level: 69 +-------- +Conductivity +Greater Curse Effect (Tier: 3) +Greater More Duration (Tier: 3) +-------- +Sigil of Power +More Duration (Tier: 2) +-------- +Greater Stormcall +Greater Area of Effect (Tier: 3) +Greater Less Duration (Tier: 3) +Greater Elemental Focus (Tier: 3) +-------- +Greater Shock Nova +Greater Critical Chance (Tier: 3) +Maximum Shock Effect (Tier: 3) +Second Wind (Tier: 3) +Faster Casting (Tier: 2) +-------- +Lightning Warp +Faster Casting (Tier: 2) +Increased Area of Effect (Tier: 2) +-------- +Purity of Lightning +]] + +describe("TestMercenaryWarrant", function() + before_each(function() + newBuild() + runCallback("OnFrame") + end) + + it("Detects valid Mercenary Warrant text", function() + assert.is_true(warrantParser.IsWarrantText(sampleWarrant)) + assert.is_false(warrantParser.IsWarrantText("Rarity: Rare\nSome Item")) + end) + + it("Parses metadata, skills, and tiered supports from Warrant text", function() + local parsed, errMsg = warrantParser.Parse(sampleWarrant, build.skillsTab) + assert.is_nil(errMsg) + assert.are.equals("Lotha, the Cynic", parsed.name) + assert.are.equals("Stormhand", parsed.build) + assert.are.equals(69, parsed.level) + assert.are.equals("Intelligence", parsed.type) + assert.are.equals(6, #parsed.skillGroups) + + assert.are.equals("Conductivity", parsed.skillGroups[1].gemList[1].nameSpec) + assert.are.equals(3, parsed.skillGroups[1].gemList[2].mercTier) + assert.are.equals(3, parsed.skillGroups[1].gemList[3].mercTier) + assert.are.equals("Greater Stormcall", parsed.skillGroups[3].gemList[1].nameSpec) + assert.are.equals("Purity of Lightning", parsed.skillGroups[6].gemList[1].nameSpec) + end) + + it("Applies Warrant into SkillsTab, ItemsTab metadata, and PartyTab summary", function() + build.spec.curAscendClassName = "Luminary" + local ok = warrantParser.ApplyWarrant(build, sampleWarrant) + assert.is_true(ok) + + assert.are.equals("Lotha, the Cynic", build.itemsTab.activeItemSet.mercenaryName) + assert.are.equals("Stormhand", build.itemsTab.activeItemSet.mercenaryBuild) + assert.are.equals(69, build.itemsTab.activeItemSet.mercenaryLevel) + assert.are.equals("Intelligence", build.itemsTab.activeItemSet.mercenaryType) + assert.are.equals(6, #build.skillsTab.mercenarySocketGroupList) + assert.is_nil(build.skillsTab.mercenarySocketGroupList[3].gemList[1].errMsg) + + local summary = build.partyTab:BuildMercenarySummaryText() + assert.is_truthy(summary:find("Conductivity")) + assert.is_truthy(summary:find("Tier 3")) + assert.is_truthy(summary:find("Purity of Lightning")) + end) + + it("Parses PoE Trade Mercenary Warrant with Item Class/Rarity header and trailing note, adding to PartyTab roster", function() + local tradeWarrant = [[ +Item Class: Map Fragments +Rarity: Normal +Mercenary Warrant +-------- +Tanua, the Pit-fighter +-------- +Build: Earthshaker +Mercenary Level: 83 +-------- +Intimidating Cry +Greater Raging Cry (Tier: 3) +Cooldown Recovery (Tier: 2) +-------- +Leap Slam +Brutality (Tier: 2) +Increased Area of Effect (Tier: 2) +-------- +Earthquake of Amplification +Faster Attacks (Tier: 2) +Increased Area of Effect (Tier: 2) +Brutality (Tier: 2) +Concentrated Effect (Tier: 2) +Pulverise (Tier: 2) +-------- +Sunder of Trarthus +Brutality (Tier: 2) +Greater Pulverise (Tier: 3) +Greater Concentrated Effect (Tier: 3) +Greater Area of Effect (Tier: 3) +Greater Faster Attacks (Tier: 3) +-------- +Vaal Vitality +Increased Area of Effect (Tier: 2) +Cooldown Recovery (Tier: 2) +-------- +Molten Shell +Greater Cooldown Recovery (Tier: 3) +More Duration (Tier: 2) +-------- +Right click this item to view Mercenary details. +Open a portal to the Proving Grounds by using this item in a personal Map Device. This previously fought Mercenary will reappear in the area for a rematch. While viewing your Atlas, Right-click this item to pinpoint its location. +-------- +Note: ~b/o 1 chaos +]] + + assert.is_true(warrantParser.IsWarrantText(tradeWarrant)) + local ok1 = warrantParser.ApplyWarrant(build, sampleWarrant) + local ok2 = warrantParser.ApplyWarrant(build, tradeWarrant) + assert.is_true(ok1) + assert.is_true(ok2) + + -- Both mercenaries are present in PartyTab roster and selectable + assert.are.equals(2, #build.partyTab.mercenaries) + local active = build.partyTab:GetActiveMercenary() + assert.are.equals("Tanua, the Pit-fighter", active.name) + assert.are.equals("Earthshaker", active.build) + assert.are.equals("Strength", active.type) + assert.are.equals(83, active.level) + assert.are.equals(6, #active.skills) + assert.are.equals("Molten Shell", active.skills[6].label) + + local summary = build.partyTab:BuildMercenarySummaryText() + assert.is_truthy(summary:find("Intimidating Cry")) + assert.is_truthy(summary:find("Sunder of Trarthus")) + assert.is_falsy(summary:find("Right click")) + assert.is_falsy(summary:find("~b/o")) + end) +end) diff --git a/spec/System/TestPartyTabMercenary_spec.lua b/spec/System/TestPartyTabMercenary_spec.lua new file mode 100644 index 00000000000..337a4b9bce0 --- /dev/null +++ b/spec/System/TestPartyTabMercenary_spec.lua @@ -0,0 +1,282 @@ +describe("TestPartyTabMercenary", function() + before_each(function() + newBuild() + runCallback("OnFrame") + end) + + it("Shows Mercenary section in PartyTab for Luminary or when Mercenary data exists", function() + assert.is_false(build.partyTab:IsMercenaryShown()) + build.spec.curAscendClassName = "Luminary" + assert.is_true(build.partyTab:IsMercenaryShown()) + end) + + it("Serializes and restores across Save, Load, and PostLoad", function() + build.spec.curAscendClassName = "Luminary" + build.itemsTab:CreateDisplayItemFromRaw("Crown of Thorns\nVine Circlet") + build.itemsTab:AddDisplayItem(true) + local helm = build.itemsTab.items[#build.itemsTab.itemOrderList] + build.itemsTab.activeItemSet.mercenaryItems["Helmet"] = helm.id + build.itemsTab.activeItemSet.mercenaryName = "Lotha, the Cynic" + build.itemsTab.activeItemSet.mercenaryBuild = "Stormhand" + build.itemsTab.activeItemSet.mercenaryType = "Intelligence" + build.itemsTab.activeItemSet.mercenaryLevel = 69 + + local mercGroup = { + label = "Purity of Lightning", + enabled = true, + isMercenary = true, + gemList = { + { nameSpec = "Purity of Lightning", level = 19, quality = 0, enabled = true, enableGlobal1 = true, enableGlobal2 = true, count = 1 }, + }, + } + build.skillsTab:ProcessSocketGroup(mercGroup) + table.insert(build.skillsTab.mercenarySocketGroupList, mercGroup) + + local partyXML = { elem = "Party" } + build.partyTab:Save(partyXML) + + -- Reset mercenary state and reload from XML via Load + PostLoad + build.itemsTab.activeItemSet.mercenaryItems = {} + build.itemsTab.activeItemSet.mercenaryName = nil + wipeTable(build.skillsTab.mercenarySocketGroupList) + + build.partyTab:Load(partyXML, "test.xml") + build.partyTab:PostLoad() + + assert.are.equals("Lotha, the Cynic", build.itemsTab.activeItemSet.mercenaryName) + assert.are.equals(69, build.itemsTab.activeItemSet.mercenaryLevel) + assert.are.equals(helm.id, build.itemsTab.activeItemSet.mercenaryItems["Helmet"]) + assert.are.equals(1, #build.skillsTab.mercenarySocketGroupList) + assert.are.equals("Purity of Lightning", build.skillsTab.mercenarySocketGroupList[1].label) + end) + + it("Imports mocked league-account mercenary payload into ItemsTab and SkillsTab", function() + build.spec.curAscendClassName = "Luminary" + local mockMerc = { + name = "Lotha, the Cynic", + build = "Stormhand", + level = 69, + items = { + { + inventoryId = "Helm", + frameType = 3, + name = "Crown of Thorns", + typeLine = "Vine Circlet", + ilvl = 69, + }, + }, + skills = { + { + name = "Conductivity", + level = 19, + supports = { + { name = "Greater Curse Effect", tier = 3 }, + }, + }, + }, + } + + build.importTab:ImportMercenary(mockMerc, true, true) + + assert.are.equals("Lotha, the Cynic", build.itemsTab.activeItemSet.mercenaryName) + assert.are.equals("Intelligence", build.itemsTab.activeItemSet.mercenaryType) + assert.is_truthy(build.itemsTab.activeItemSet.mercenaryItems["Helmet"]) + assert.are.equals(1, #build.skillsTab.mercenarySocketGroupList) + assert.are.equals(2, #build.skillsTab.mercenarySocketGroupList[1].gemList) + assert.are.equals(3, build.skillsTab.mercenarySocketGroupList[1].gemList[2].mercTier) + end) + + it("Builds PC and console DownloadLeagueAccount URLs cleanly", function() + local capturedUrls = {} + local api = new("PoEAPI"):PoEAPI("tok", "ref", os.time() + 3600) + api.DownloadWithRateLimit = function(_, _, url, cb) + table.insert(capturedUrls, url) + if cb then cb({}, nil) end + end + + api:DownloadLeagueAccount("pc", "Mercenaries of Trarthus", function() end) + api:DownloadLeagueAccount("xbox", "Standard", function() end) + + assert.are.equals("/league-account/Mercenaries%20of%20Trarthus", capturedUrls[1]) + assert.are.equals("/league-account/xbox/Standard", capturedUrls[2]) + end) + + it("Shows Mercenary import row only for Luminary characters and imports selected roster entry", function() + local importTab = build.importTab + importTab.usingOauth = true + importTab.isAuthorized = function() return true end + + importTab:BuildCharacterList("pc", "Covens", { + { name = "NonLumChar", realm = "pc", league = "Covens", class = "Inquisitor", level = 90 }, + { name = "Chochi_flaca", realm = "pc", league = "Covens", class = "Luminary", level = 91 }, + }, importTab.controls.charSelect) + + -- Select Inquisitor -> Mercenary row hidden + importTab.controls.charSelect.selIndex = 2 + if importTab.controls.charSelect:GetSelValue().char.class == "Luminary" then + importTab.controls.charSelect.selIndex = 1 + end + assert.is_false(importTab.controls.charImportMercenary:IsShown()) + + -- Select Luminary -> Mercenary row shown + for i, entry in ipairs(importTab.controls.charSelect.list) do + if entry.char.class == "Luminary" then + importTab.controls.charSelect.selIndex = i + break + end + end + assert.is_true(importTab.controls.charImportMercenary:IsShown()) + + -- Populate sparse mercenary roster matching live /league-account/Covens shape + local roster = { + { + index = 0, + name = "Veth, the Vile", + level = 83, + build = "ChaosMinionWitchChaosHit", + skills = { { name = "Despair", supports = { { name = "Increased Area of Effect", tier = 2 } } } }, + items = {}, + }, + { + index = 2, + name = "Draveth Azrus", + level = 66, + build = "EleBowRangerClones", + skills = { { name = "Hatred", supports = {} } }, + items = {}, + }, + } + importTab:PopulateMercenaryList("pc", "Covens", roster) + assert.are.equals(2, #importTab.controls.mercenarySelect.list) + + -- Import both mercenaries and verify PartyTab roster switching + XML round-trip + importTab:ImportMercenary(roster[1], true, true) + importTab:ImportMercenary(roster[2], true, true) + + assert.are.equals(2, #build.partyTab.mercenaries) + assert.are.equals(2, build.partyTab.activeMercenaryIndex) + assert.are.equals("Draveth Azrus", build.partyTab:GetActiveMercenary().name) + assert.is_truthy(build.partyTab:BuildMercenarySummaryText():find("Hatred")) + + -- Switch to first mercenary on PartyTab + build.partyTab:SetActiveMercenary(1) + assert.are.equals("Veth, the Vile", build.partyTab:GetActiveMercenary().name) + assert.are.equals("Veth, the Vile", build.itemsTab.activeItemSet.mercenaryName) + assert.is_truthy(build.partyTab:BuildMercenarySummaryText():find("Despair")) + + -- Save and reload + local partyXML = { elem = "Party" } + build.partyTab:Save(partyXML) + build.partyTab:Load(partyXML, "test.xml") + build.partyTab:PostLoad() + + assert.are.equals(2, #build.partyTab.mercenaries) + assert.are.equals(1, build.partyTab.activeMercenaryIndex) + assert.are.equals("Veth, the Vile", build.partyTab:GetActiveMercenary().name) + + -- Remove active mercenary -> falls back cleanly to remaining entry + build.partyTab:RemoveActiveMercenary() + assert.are.equals(1, #build.partyTab.mercenaries) + assert.are.equals("Draveth Azrus", build.partyTab:GetActiveMercenary().name) + end) + + it("Populates Any Loadout item selector when a Mercenary item slot is selected on PartyTab", function() + build.spec.curAscendClassName = "Luminary" + build.itemsTab:CreateDisplayItemFromRaw("Crown of Thorns\nVine Circlet") + build.itemsTab:AddDisplayItem(true) + local helm = build.itemsTab.items[#build.itemsTab.itemOrderList] + + build.itemsTab:CreateDisplayItemFromRaw("New Item\nCobalt Jewel") + build.itemsTab:AddDisplayItem(true) + + build.partyTab:UpsertMercenary({ + name = "Tanua, the Pit-fighter", + build = "Earthshaker", + type = "Strength", + level = 83, + skills = {}, + items = {}, + }) + + -- All 10 wearable slots appear in mercenaryItemsList + assert.are.equals(10, #build.partyTab.mercenaryItemRows) + + -- Select the Helmet row -> dropdown lists None + Crown of Thorns (excluding Jewel) + local helmRowIdx + for i, row in ipairs(build.partyTab.mercenaryItemRows) do + if row.slotName == "Helmet" then + helmRowIdx = i + break + end + end + build.partyTab.controls.mercenaryItemsList.selIndex = helmRowIdx + build.partyTab.controls.mercenaryItemsList.selValue = build.partyTab.mercenaryItemRows[helmRowIdx] + build.partyTab:SyncMercenaryItemPicker("Helmet") + + assert.are.equals(2, #build.partyTab.controls.mercenaryItemSelect.list) + assert.are.equals(helm.id, build.partyTab.controls.mercenaryItemSelect.list[2].itemId) + + -- Equip Crown of Thorns via the dropdown callback + build.partyTab.controls.mercenaryItemSelect.selFunc(2, build.partyTab.controls.mercenaryItemSelect.list[2]) + assert.are.equals(helm.id, build.partyTab:GetActiveMercenary().items["Helmet"]) + assert.are.equals(helm.id, build.partyTab.mercenaryItemRows[helmRowIdx].itemId) + + -- Adding a new valid Helmet in ItemsTab automatically refreshes the PartyTab dropdown + build.itemsTab:CreateDisplayItemFromRaw("Goldrim\nLeather Cap") + build.itemsTab:AddDisplayItem(true) + assert.are.equals(3, #build.partyTab.controls.mercenaryItemSelect.list) + end) + + it("Gates PartyTab code import of mercenaries on All destination and respects Append", function() + build.spec.curAscendClassName = "Luminary" + build.partyTab:UpsertMercenary({ + index = 0, + name = "Veth, the Vile", + build = "ChaosMinionWitchChaosHit", + type = "Intelligence", + level = 83, + skills = {}, + items = {}, + }) + + local partyCodeXML = [[ + + + --- Curse Limit --- +1 + + + + + +]] + + -- 1. Destination = Curse, Append = true -> existing mercenary must NOT be replaced or modified + build.partyTab.controls.importCodeDestination:SelByValue("Curse") + build.partyTab.controls.appendNotReplace.state = true + build.partyTab.importCodeValid = true + build.partyTab.importCodeFetching = false + build.partyTab.importCodeXML = partyCodeXML + build.partyTab.controls.importCodeGo.onClick() + + assert.are.equals(1, #build.partyTab.mercenaries) + assert.are.equals("Veth, the Vile", build.partyTab:GetActiveMercenary().name) + + -- 2. Destination = All, Append = true -> appends imported mercenary and preserves active selection + build.partyTab.controls.importCodeDestination:SelByValue("All") + build.partyTab.controls.appendNotReplace.state = true + build.partyTab.controls.importCodeGo.onClick() + + assert.are.equals(2, #build.partyTab.mercenaries) + assert.are.equals(1, build.partyTab.activeMercenaryIndex) + assert.are.equals("Veth, the Vile", build.partyTab:GetActiveMercenary().name) + assert.are.equals("Draveth Azrus", build.partyTab.mercenaries[2].name) + + -- 3. Destination = All, Append = false -> replaces existing mercenaries + build.partyTab.controls.appendNotReplace.state = false + build.partyTab.controls.importCodeGo.onClick() + + assert.are.equals(1, #build.partyTab.mercenaries) + assert.are.equals("Draveth Azrus", build.partyTab:GetActiveMercenary().name) + end) +end) diff --git a/src/Classes/ImportTab.lua b/src/Classes/ImportTab.lua index f4ad27a3e0a..67aa6d16009 100644 --- a/src/Classes/ImportTab.lua +++ b/src/Classes/ImportTab.lua @@ -10,6 +10,7 @@ local b_rshift = bit.rshift local band = bit.band local m_max = math.max local dkjson = require "dkjson" +local mercenaryWarrant = require("Modules.MercenaryWarrantParser") @@ -88,10 +89,43 @@ local function addOAuthControls(self) end) self.controls.logoutApiButton.shown = function() return self.usingOauth and self.isAuthorized() end + self.mercenaryList = {} + + local function isSelectedCharLuminary() + local sel = self.controls.charSelect and self.controls.charSelect:GetSelValue() + return sel ~= nil and sel.char ~= nil and sel.char.class == "Luminary" + end + + local function getSelectedMercenaryKey() + local realm = self.controls.accountRealm and self.controls.accountRealm:GetSelValue() + local sel = self.controls.charSelect and self.controls.charSelect:GetSelValue() + local league = (sel and sel.char and sel.char.league) or (self.controls.charSelectLeague and self.controls.charSelectLeague:GetSelValue()) + if realm and league and league ~= "Any" then + return realm.realmCode .. ":" .. league, realm.realmCode, league + end + return nil + end + + local function syncMercenarySelect() + if not self.controls.mercenarySelect then + return + end + local key, realmCode, league = getSelectedMercenaryKey() + if key and self.mercenaryList[key] then + self:PopulateMercenaryList(realmCode, league, self.mercenaryList[key]) + else + wipeTable(self.controls.mercenarySelect.list) + self.controls.mercenarySelect.selIndex = 1 + end + end + self.controls.characterImportAnchor = new("Control"):Control({ "TOPLEFT", self.controls.sectionOauthCharImport, "TOPLEFT" }, { labelSpacing, 40, 200, 16 }) self.controls.sectionOauthCharImport.height = function() - return self.isAuthorized() and 200 or 60 + if not self.isAuthorized() then + return 60 + end + return isSelectedCharLuminary() and 230 or 200 end -- realm select @@ -222,6 +256,7 @@ local function addOAuthControls(self) else self:BuildCharacterList(realm, newLeague, self.characterList[realm], self.controls.charSelect) end + syncMercenarySelect() end self.controls.charSelectLeagueLabel = new("LabelControl"):LabelControl({ "TOPLEFT", self.controls.accountRealm, "BOTTOMLEFT" }, @@ -230,7 +265,9 @@ local function addOAuthControls(self) { labelSpacing, 0, 150, 18 }, nil, onLeagueChange) -- character select self.controls.charSelect = new("DropDownControl"):DropDownControl({ "TOPLEFT", self.controls.charSelectLeagueLabel, "BOTTOMLEFT" }, - { 0, rowSpacing, 400, 18 }, nil) + { 0, rowSpacing, 400, 18 }, nil, function() + syncMercenarySelect() + end) self.controls.charSelect.enabled = function() return self.usingOauth and self.isAuthorized() end @@ -318,6 +355,62 @@ local function addOAuthControls(self) { 220, 0, 18 }, "Delete equipment:", nil, "Delete all equipped items when importing.", true) self.controls.charImportItemsIgnoreWeaponSwap = new("CheckBoxControl"):CheckBoxControl({ "LEFT", self.controls.charImportItems, "RIGHT" }, { 380, 0, 18 }, "Ignore weapon swap:", nil, "Ignore items and skills in weapon swap.", false) + + -- Mercenary roster fetch & import row (Luminary only) + self.controls.charImportMercenary = new("ButtonControl"):ButtonControl({ "TOPLEFT", self.controls.charImportItems, "BOTTOMLEFT" }, + { 0, rowSpacing, 110, 20 }, "Mercenary", function() + local key, realmCode, league = getSelectedMercenaryKey() + if not key then + self.oauthErrCode = "Could not determine league for mercenary fetch" + return + end + self.oauthLoading = true + self.oauthErrCode = nil + main.api:DownloadLeagueAccount(realmCode, league, function(leagueData, leagueErrMsg) + local mercenaries = leagueData and ((leagueData.league_account and leagueData.league_account.mercenaries) or leagueData.mercenaries) + if mercenaries then + self:PopulateMercenaryList(realmCode, league, mercenaries) + if #mercenaries == 0 then + self.oauthErrCode = "No mercenaries found in " .. league + end + elseif leagueErrMsg then + ConPrintf("Mercenary league-account fetch failed: %s", leagueErrMsg) + if leagueErrMsg:match("403") or leagueErrMsg:match("401") then + self.oauthErrCode = "Mercenary fetch failed (" .. leagueErrMsg .. "): Logout and re-authorize for account:league_accounts scope" + else + self.oauthErrCode = "Mercenary fetch failed: " .. leagueErrMsg + end + else + self.oauthErrCode = "No mercenary data returned for " .. league + end + self.oauthLoading = false + end) + end) + self.controls.charImportMercenary.shown = function() + return self.usingOauth and self.isAuthorized() and isSelectedCharLuminary() + end + self.controls.charImportMercenary.enabled = function() + return self.usingOauth and self.isAuthorized() and not self.oauthLoading and isSelectedCharLuminary() + end + self.controls.mercenarySelect = new("DropDownControl"):DropDownControl({ "LEFT", self.controls.charImportMercenary, "RIGHT" }, + { labelSpacing, 0, 260, 20 }, {}) + self.controls.mercenarySelect.shown = self.controls.charImportMercenary.shown + self.controls.mercenarySelect.enabled = function() + return #self.controls.mercenarySelect.list > 0 + end + self.controls.charImportMercenaryGo = new("ButtonControl"):ButtonControl({ "LEFT", self.controls.mercenarySelect, "RIGHT" }, + { labelSpacing, 0, 70, 20 }, "Import", function() + local sel = self.controls.mercenarySelect:GetSelValue() + if sel and sel.merc then + local clearItems = self.controls.charImportItemsClearItems.state + local clearSkills = self.controls.charImportItemsClearSkills.state + self:ImportMercenary(sel.merc, clearItems, clearSkills) + end + end) + self.controls.charImportMercenaryGo.shown = self.controls.charImportMercenary.shown + self.controls.charImportMercenaryGo.enabled = function() + return self.controls.mercenarySelect:GetSelValue() ~= nil + end end local function addAccountNameControls(self) self.charImportMode = "GETACCOUNTNAME" @@ -1499,6 +1592,136 @@ local slotMap = { ["Weapon"] = "Weapon 1", ["Offhand"] = "Weapon 2", ["Weapon2"] ["Amulet"] = "Amulet", ["Ring"] = "Ring 1", ["Ring2"] = "Ring 2", ["Ring3"] = "Ring 3", ["Belt"] = "Belt", ["BrequelGrafts"] = "Graft 1", ["BrequelGrafts2"] = "Graft 2", ["VisceraHead"] = "Head", ["VisceraBody"] = "Body", ["VisceraArm"] = "Arm", ["VisceraLeg"] = "Leg", } +function ImportTabClass:PopulateMercenaryList(realmCode, league, mercenaries) + self.mercenaryList = self.mercenaryList or {} + self.mercenaryList[realmCode .. ":" .. league] = mercenaries or {} + local control = self.controls.mercenarySelect + if not control then + return + end + wipeTable(control.list) + for _, merc in ipairs(mercenaries or {}) do + local name = merc.name or ("Mercenary #" .. tostring(merc.index or 0)) + local lvl = tonumber(merc.level) or 0 + local buildName = merc.build or "" + local detail = buildName ~= "" and string.format("%s ^x808080lvl %d", buildName, lvl) or string.format("^x808080lvl %d", lvl) + t_insert(control.list, { + label = name, + detail = detail, + merc = merc, + }) + end + control.selIndex = 1 +end + +---Imports an active mercenary entry from /league-account/ +---@param mercData table +---@param clearItems boolean? +---@param clearSkills boolean? +function ImportTabClass:ImportMercenary(mercData, clearItems, clearSkills) + if not mercData then + return + end + local itemsTab = self.build.itemsTab + local skillsTab = self.build.skillsTab + local partyTab = self.build.partyTab + + local buildName = mercData.build or mercData.archetype + local mercLevel = tonumber(mercData.level) + local mappedType = mercData.type or mercenaryWarrant.BuildToType(buildName) + local mercEntry = { + index = mercData.index, + name = mercData.name, + build = buildName, + type = mappedType, + level = mercLevel, + items = {}, + skills = {}, + replaceItems = true, + } + + if itemsTab and itemsTab.activeItemSet then + local prevMercItems = itemsTab.activeItemSet.mercenaryItems + itemsTab.activeItemSet.mercenaryItems = mercEntry.items + for _, itemData in ipairs(mercData.items or mercData.equipment or {}) do + local baseSlot = slotMap[itemData.inventoryId] + if baseSlot and not baseSlot:match("Swap") and not baseSlot:match("Graft") and not baseSlot:match("Ring 3") + and baseSlot ~= "Head" and baseSlot ~= "Body" and baseSlot ~= "Arm" and baseSlot ~= "Leg" then + self:ImportItem(itemData, "Mercenary " .. baseSlot, true) + end + end + if not partyTab then + itemsTab.activeItemSet.mercenaryName = mercEntry.name or itemsTab.activeItemSet.mercenaryName + itemsTab.activeItemSet.mercenaryBuild = mercEntry.build or itemsTab.activeItemSet.mercenaryBuild + itemsTab.activeItemSet.mercenaryLevel = mercEntry.level or itemsTab.activeItemSet.mercenaryLevel + itemsTab.activeItemSet.mercenaryType = mercEntry.type or itemsTab.activeItemSet.mercenaryType + else + itemsTab.activeItemSet.mercenaryItems = prevMercItems + end + itemsTab:PopulateSlots() + itemsTab:AddUndoState() + end + + if skillsTab then + local defaultGemLevel = mercLevel and math.min(20, math.max(1, math.floor(mercLevel / 3.5))) or 20 + for _, skillEntry in ipairs(mercData.skills or {}) do + local activeName = skillEntry.name or skillEntry.skill or skillEntry.id or "" + if activeName ~= "" then + local activeSpec, activeGemId = mercenaryWarrant.ResolveGemName(activeName, false, skillsTab) + local group = { + label = activeName, + enabled = true, + isMercenary = true, + gemList = { + { + nameSpec = activeSpec, + gemId = activeGemId, + level = tonumber(skillEntry.level) or defaultGemLevel, + quality = tonumber(skillEntry.quality) or 0, + enabled = true, + enableGlobal1 = true, + enableGlobal2 = true, + count = 1, + } + }, + } + for _, sup in ipairs(skillEntry.supports or {}) do + local supName = type(sup) == "table" and (sup.name or sup.skill or sup.id) or tostring(sup) + local supSpec, supGemId = mercenaryWarrant.ResolveGemName(supName, true, skillsTab) + t_insert(group.gemList, { + nameSpec = supSpec, + gemId = supGemId, + level = (type(sup) == "table" and tonumber(sup.level)) or defaultGemLevel, + quality = (type(sup) == "table" and tonumber(sup.quality)) or 0, + mercTier = type(sup) == "table" and tonumber(sup.tier) or nil, + enabled = true, + enableGlobal1 = true, + enableGlobal2 = true, + count = 1, + }) + end + skillsTab:ProcessSocketGroup(group) + t_insert(mercEntry.skills, group) + end + end + if not partyTab and skillsTab.mercenarySocketGroupList then + if clearSkills then + wipeTable(skillsTab.mercenarySocketGroupList) + end + for _, group in ipairs(mercEntry.skills) do + t_insert(skillsTab.mercenarySocketGroupList, group) + end + end + skillsTab:AddUndoState() + end + + if partyTab and partyTab.UpsertMercenary then + partyTab:UpsertMercenary(mercEntry) + end + + self.build.buildFlag = true +end + function ImportTabClass:ImportItem(itemData, slotName, ignoreWeaponSwap, itemSetId) if not slotName then if itemData.inventoryId == "PassiveJewels" then @@ -1820,7 +2043,11 @@ function ImportTabClass:ImportItem(itemData, slotName, ignoreWeaponSwap, itemSet else self.build.itemsTab:AddItem(item, true) end - if itemSetId and itemSetId ~= self.build.itemsTab.activeItemSetId then + if slotName:match("^Mercenary ") then + local targetSet = itemSetId and self.build.itemsTab.itemSets[itemSetId] or self.build.itemsTab.activeItemSet + targetSet.mercenaryItems = targetSet.mercenaryItems or {} + targetSet.mercenaryItems[slotName:gsub("^Mercenary ", "")] = item.id + elseif itemSetId and itemSetId ~= self.build.itemsTab.activeItemSetId then self.build.itemsTab.itemSets[itemSetId][slotName].selItemId = item.id else self.build.itemsTab.slots[slotName]:SetSelItemId(item.id) diff --git a/src/Classes/ItemListControl.lua b/src/Classes/ItemListControl.lua index aff11b7152c..8d99478989d 100644 --- a/src/Classes/ItemListControl.lua +++ b/src/Classes/ItemListControl.lua @@ -255,7 +255,14 @@ function ItemListClass:GetRowValue(column, index, itemId) if used == "" then local slot, itemSet = self.itemsTab:GetEquippedSlotForItem(item) if not slot then - used = " ^9(Unused)" + local isMerc, mercSet = self.itemsTab:IsItemEquippedByMercenary(itemId) + if isMerc and mercSet and mercSet ~= self.itemsTab.activeItemSet then + used = " ^9(Mercenary in '" .. (mercSet.title or "Default") .. "')" + elseif isMerc then + used = " ^9(Mercenary)" + else + used = " ^9(Unused)" + end elseif itemSet then used = " ^9(Used in '" .. (itemSet.title or "Default") .. "')" end diff --git a/src/Classes/ItemsTab.lua b/src/Classes/ItemsTab.lua index 4c40b333e4a..c1d306ef16a 100644 --- a/src/Classes/ItemsTab.lua +++ b/src/Classes/ItemsTab.lua @@ -1367,6 +1367,10 @@ function ItemsTabClass:Load(xml, dbFileName) elseif node.elem == "ItemSet" then local itemSet = self:CreateItemSet(tonumber(node.attrib.id), node.attrib.title or "Default") itemSet.useSecondWeaponSet = node.attrib.useSecondWeaponSet == "true" + itemSet.mercenaryType = node.attrib.mercenaryType + itemSet.mercenaryName = node.attrib.mercenaryName + itemSet.mercenaryBuild = node.attrib.mercenaryBuild + itemSet.mercenaryLevel = tonumber(node.attrib.mercenaryLevel) for _, child in ipairs(node) do if child.elem == "Slot" then local slotName = child.attrib.name or "" @@ -1469,7 +1473,15 @@ function ItemsTabClass:Save(xml) end for _, itemSetId in ipairs(self.itemSetOrderList) do local itemSet = self.itemSets[itemSetId] - local child = { elem = "ItemSet", attrib = { id = tostring(itemSetId), title = itemSet.title, useSecondWeaponSet = tostring(itemSet.useSecondWeaponSet) } } + local child = { elem = "ItemSet", attrib = { + id = tostring(itemSetId), + title = itemSet.title, + useSecondWeaponSet = tostring(itemSet.useSecondWeaponSet), + mercenaryType = itemSet.mercenaryType, + mercenaryName = itemSet.mercenaryName, + mercenaryBuild = itemSet.mercenaryBuild, + mercenaryLevel = itemSet.mercenaryLevel and tostring(itemSet.mercenaryLevel), + } } for _, slot in ipairs(self.orderedSlots) do local slotName = slot.slotName if not slot.nodeId then @@ -1656,9 +1668,41 @@ function ItemsTabClass:Draw(viewPort, inputEvents) self.controls.specSelect:SetList(self.build.treeTab:GetSpecList()) end +function ItemsTabClass:IsLuminary() + return self.build and self.build.spec and self.build.spec.curAscendClassName == "Luminary" +end + +function ItemsTabClass:IsItemEquippedByMercenary(itemId) + if not itemId or itemId == 0 then + return false + end + local partyTab = self.build and self.build.partyTab + if partyTab and partyTab.mercenaries then + for _, merc in ipairs(partyTab.mercenaries) do + if merc.items then + for _, id in pairs(merc.items) do + if id == itemId then + return true, self.activeItemSet + end + end + end + end + end + for _, itemSet in pairs(self.itemSets) do + if itemSet.mercenaryItems then + for _, id in pairs(itemSet.mercenaryItems) do + if id == itemId then + return true, itemSet + end + end + end + end + return false +end + -- Creates a new item set function ItemsTabClass:CreateItemSet(itemSetId, name) - local itemSet = { id = itemSetId, title = name } + local itemSet = { id = itemSetId, title = name, mercenaryItems = {} } if not itemSetId then itemSet.id = 1 while self.itemSets[itemSet.id] do @@ -1722,6 +1766,7 @@ function ItemsTabClass:SetActiveItemSet(itemSetId, deferSync) self.activeItemSetId = itemSetId self.activeItemSet = self.itemSets[itemSetId] local curSet = self.activeItemSet + curSet.mercenaryItems = curSet.mercenaryItems or {} for slotName, slot in pairs(self.slots) do if not slot.nodeId then if prevSet then @@ -1781,6 +1826,10 @@ function ItemsTabClass:PopulateSlots() for _, slot in pairs(self.slots) do slot:Populate() end + local partyTab = self.build and self.build.partyTab + if partyTab and partyTab.SyncMercenaryItemsList then + partyTab:SyncMercenaryItemsList() + end end -- Updates the status and position of the socket controls @@ -2000,6 +2049,32 @@ function ItemsTabClass:DeleteItem(item, deferUndoState) end end end + for _, itemSet in pairs(self.itemSets) do + if itemSet.mercenaryItems then + for mercSlot, mercItemId in pairs(itemSet.mercenaryItems) do + if mercItemId == item.id then + itemSet.mercenaryItems[mercSlot] = nil + end + end + end + end + local partyTab = self.build and self.build.partyTab + if partyTab and partyTab.mercenaries then + local changed = false + for _, merc in ipairs(partyTab.mercenaries) do + if merc.items then + for mercSlot, mercItemId in pairs(merc.items) do + if mercItemId == item.id then + merc.items[mercSlot] = nil + changed = true + end + end + end + end + if changed and partyTab.SyncMercenaryItemsList then + partyTab:SyncMercenaryItemsList() + end + end for index, id in pairs(self.itemOrderList) do if id == item.id then t_remove(self.itemOrderList, index) @@ -2702,6 +2777,18 @@ function ItemsTabClass:GetComparisonSlotNameForItem(item, activeOnly) end -- Check if the given item could be equipped in the given slot, taking into account possible conflicts with currently equipped items -- For example, a shield is not valid for Weapon 2 if Weapon 1 is a staff, and a wand is not valid for Weapon 2 if Weapon 1 is a dagger +local function isValidOffhandForWeapon1(itemsTab, item, weapon1Sel) + local weapon1Type = itemsTab.items[weapon1Sel] and itemsTab.items[weapon1Sel].base.type or "None" + if weapon1Type == "None" then + return item.type == "Shield" or (itemsTab.build.data.weaponTypeInfo[item.type] and itemsTab.build.data.weaponTypeInfo[item.type].oneHand) + elseif weapon1Type == "Bow" then + return item.type == "Quiver" + elseif itemsTab.build.data.weaponTypeInfo[weapon1Type].oneHand then + return item.type == "Shield" or (itemsTab.build.data.weaponTypeInfo[item.type] and itemsTab.build.data.weaponTypeInfo[item.type].oneHand and ((weapon1Type == "Wand" and item.type == "Wand") or (weapon1Type ~= "Wand" and item.type ~= "Wand"))) + end + return false +end + function ItemsTabClass:IsItemValidForSlot(item, slotName, itemSet) itemSet = itemSet or self.activeItemSet local slotType, slotId = slotName:match("^([%a ]+) (%d+)$") @@ -2746,13 +2833,8 @@ function ItemsTabClass:IsItemValidForSlot(item, slotName, itemSet) return item.base.weapon ~= nil elseif slotName == "Weapon 2" or slotName == "Weapon 2 Swap" then local weapon1Sel = itemSet[slotName == "Weapon 2" and "Weapon 1" or "Weapon 1 Swap"].selItemId or 0 - local weapon1Type = self.items[weapon1Sel] and self.items[weapon1Sel].base.type or "None" - if weapon1Type == "None" then - return item.type == "Shield" or (self.build.data.weaponTypeInfo[item.type] and self.build.data.weaponTypeInfo[item.type].oneHand) - elseif weapon1Type == "Bow" then - return item.type == "Quiver" - elseif self.build.data.weaponTypeInfo[weapon1Type].oneHand then - return item.type == "Shield" or (self.build.data.weaponTypeInfo[item.type] and self.build.data.weaponTypeInfo[item.type].oneHand and ((weapon1Type == "Wand" and item.type == "Wand") or (weapon1Type ~= "Wand" and item.type ~= "Wand"))) + if isValidOffhandForWeapon1(self, item, weapon1Sel) then + return true end end end diff --git a/src/Classes/PartyTab.lua b/src/Classes/PartyTab.lua index 96cc74508ea..53b394d2ac5 100644 --- a/src/Classes/PartyTab.lua +++ b/src/Classes/PartyTab.lua @@ -8,6 +8,11 @@ local ipairs = ipairs local s_format = string.format local t_insert = table.insert local m_max = math.max +local mercenaryWarrant = require("Modules.MercenaryWarrantParser") + +local mercenarySlotOrder = { + "Weapon 1", "Weapon 2", "Helmet", "Body Armour", "Gloves", "Boots", "Amulet", "Ring 1", "Ring 2", "Belt", +} ---@class PartyTab: ControlHost, Control local PartyTabClass = newClass("PartyTab", "ControlHost", "Control") @@ -24,6 +29,9 @@ function PartyTabClass:PartyTab(build) self.enemyModList = new("ModList"):ModList() self.buffExports = { } self.enableExportBuffs = false + self.mercenaries = { } + self.activeMercenaryIndex = 1 + self.mercenaryItemRows = { } self.lastContent = { Aura = "", @@ -270,6 +278,10 @@ function PartyTabClass:PartyTab(build) self.controls.enemyMods:SetText(node[1] or "") end end + elseif node.elem == "Mercenary" or node.elem == "Mercenaries" then + if partyDestinations[self.controls.importCodeDestination.selIndex] == "All" then + self:ApplyMercenariesXML(node, dbXML, self.controls.appendNotReplace.state ~= true) + end end end if partyDestinations[self.controls.importCodeDestination.selIndex] == "All" or partyDestinations[self.controls.importCodeDestination.selIndex] == "EnemyConditions" or partyDestinations[self.controls.importCodeDestination.selIndex] == "EnemyMods" then @@ -441,6 +453,165 @@ function PartyTabClass:PartyTab(build) return not self.controls.ShowAdvanceTools.state end + -- Mercenary Overview (Luminary / imported Mercenary) + self.controls.mercenaryHeader = new("LabelControl"):LabelControl({"TOPLEFT",self.controls.editLinksLabel,"BOTTOMLEFT"}, {0, 12, 0, theme.stringHeight}, function() + local merc = self:GetActiveMercenary() + local itemsTab = self.build and self.build.itemsTab + local itemSet = itemsTab and itemsTab.activeItemSet + local name = (merc and merc.name and merc.name ~= "" and merc.name) + or (itemSet and itemSet.mercenaryName and itemSet.mercenaryName ~= "" and itemSet.mercenaryName) + or "Unnamed" + local buildName = (merc and merc.build) or (itemSet and itemSet.mercenaryBuild) + local mercType = (merc and merc.type) or (itemSet and itemSet.mercenaryType) + local mercLevel = (merc and merc.level) or (itemSet and itemSet.mercenaryLevel) + local meta = {} + if buildName and buildName ~= "" then + t_insert(meta, buildName) + end + if mercType and mercType ~= "" then + t_insert(meta, mercType) + end + if mercLevel and mercLevel > 0 then + t_insert(meta, "Level " .. tostring(mercLevel)) + end + local suffix = #meta > 0 and (" (" .. table.concat(meta, ", ") .. ")") or "" + return "^7Mercenary: " .. colorCodes.RELIC .. name .. "^7" .. suffix + end) + self.controls.mercenaryHeader.y = function() + return self.controls.ShowAdvanceTools.state and (self.controls.editLinks.height() + 12) or (theme.lineCounter(self.controls.simpleLinks.label) + 12) + end + self.controls.mercenaryHeader.shown = function() + return self:IsMercenaryShown() + end + self.controls.mercenarySelect = new("DropDownControl"):DropDownControl({"TOPLEFT",self.controls.mercenaryHeader,"BOTTOMLEFT"}, {0, 4, 220, 18}, {}, function(index) + self:SetActiveMercenary(index) + end) + self.controls.mercenarySelect.shown = self.controls.mercenaryHeader.shown + self.controls.mercenarySelect.enabled = function() + return #self.mercenaries > 1 + end + self.controls.mercenaryPasteWarrant = new("ButtonControl"):ButtonControl({"LEFT",self.controls.mercenarySelect,"RIGHT"}, {4, 0, 100, 18}, "Paste Warrant", function() + self:OpenPasteWarrantPopup() + end) + self.controls.mercenaryPasteWarrant.shown = self.controls.mercenaryHeader.shown + self.controls.mercenaryRemove = new("ButtonControl"):ButtonControl({"LEFT",self.controls.mercenaryPasteWarrant,"RIGHT"}, {4, 0, 65, 18}, "Remove", function() + self:RemoveActiveMercenary() + end) + self.controls.mercenaryRemove.shown = self.controls.mercenaryHeader.shown + self.controls.mercenaryRemove.enabled = function() + return #self.mercenaries > 0 + end + self.controls.mercenarySummary = new("LabelControl"):LabelControl({"TOPLEFT",self.controls.mercenarySelect,"BOTTOMLEFT"}, {0, 6, 0, theme.stringHeight}, function() + return self:BuildMercenarySkillsText() + end) + self.controls.mercenarySummary.shown = self.controls.mercenaryHeader.shown + + self.controls.mercenaryItemsList = new("ListControl"):ListControl({"TOPLEFT",self.controls.mercenarySummary,"BOTTOMLEFT"}, {0, 22, 380, 180}, 16, "VERTICAL", false, self.mercenaryItemRows, true) + self.controls.mercenaryItemsList.label = "^7Mercenary Items:" + self.controls.mercenaryItemsList.defaultText = "^x7F7F7FNo items equipped" + self.controls.mercenaryItemsList.reserveIconSpace = true + self.controls.mercenaryItemsList.width = function() + return m_max(380, self.width / 2 - 24) + end + self.controls.mercenaryItemsList.y = function() + return theme.lineCounter(self.controls.mercenarySummary:GetProperty("label")) + 24 + end + self.controls.mercenaryItemsList.shown = self.controls.mercenaryHeader.shown + self.controls.mercenaryItemsList.GetRowValue = function(_, column, index, entry) + if column == 1 and entry then + local itemsTab = self.build and self.build.itemsTab + local item = entry.itemId and itemsTab and itemsTab.items[entry.itemId] + if item then + return "^7" .. entry.slotName .. ": " .. colorCodes[item.rarity] .. item.name + end + return "^7" .. entry.slotName .. ": ^x7F7F7FNone" + end + return "" + end + self.controls.mercenaryItemsList.GetRowIcon = function(_, column, index, entry) + if column == 1 and entry and entry.itemId then + local itemsTab = self.build and self.build.itemsTab + local item = itemsTab and itemsTab.items[entry.itemId] + if item then + return itemsTab:GetItemIcon(item) + end + end + end + self.controls.mercenaryItemsList.AddValueTooltip = function(_, tooltip, index, entry) + if main.popups[1] or not entry or not entry.itemId then + tooltip:Clear() + return + end + local itemsTab = self.build and self.build.itemsTab + local item = itemsTab and itemsTab.items[entry.itemId] + if item then + if tooltip:CheckForUpdate(item, launch.devModeAlt, self.build.outputRevision) then + itemsTab:AddItemTooltip(tooltip, item, nil, true) + end + else + tooltip:Clear() + end + end + self.controls.mercenaryItemsList.OnSelect = function(_, index, entry) + self:SyncMercenaryItemPicker(entry and entry.slotName or nil) + end + + self.controls.mercenaryItemSelectLabel = new("LabelControl"):LabelControl({"TOPLEFT",self.controls.mercenaryItemsList,"BOTTOMLEFT"}, {0, 6, 0, theme.stringHeight}, function() + local sel = self.controls.mercenaryItemsList.selValue + return sel and ("^7" .. sel.slotName .. ":") or "" + end) + self.controls.mercenaryItemSelectLabel.shown = function() + return self:IsMercenaryShown() and self:GetActiveMercenary() ~= nil and self.controls.mercenaryItemsList.selValue ~= nil + end + self.controls.mercenaryItemSelect = new("DropDownControl"):DropDownControl({"TOPLEFT",self.controls.mercenaryItemsList,"BOTTOMLEFT"}, {85, 4, 295, 20}, {}, function(index, value) + local sel = self.controls.mercenaryItemsList.selValue + local merc = self:GetActiveMercenary() + if not sel or not merc or not value then + return + end + merc.items = merc.items or {} + local newId = value.itemId or 0 + if newId == 0 then + merc.items[sel.slotName] = nil + else + merc.items[sel.slotName] = newId + end + if sel.slotName == "Weapon 1" and merc.items["Weapon 2"] then + local itemsTab = self.build and self.build.itemsTab + local offhand = itemsTab and itemsTab.items[merc.items["Weapon 2"]] + if offhand and not self:IsItemValidForMercenarySlot(offhand, "Weapon 2", merc.items) then + merc.items["Weapon 2"] = nil + end + end + local itemsTab = self.build and self.build.itemsTab + if itemsTab and itemsTab.activeItemSet then + itemsTab.activeItemSet.mercenaryItems = merc.items + end + self:SyncMercenaryItemsList() + self:SyncMercenaryItemPicker(sel.slotName) + if self.build then + self.build.buildFlag = true + end + end) + self.controls.mercenaryItemSelect.width = function() + return m_max(295, self.controls.mercenaryItemsList.width() - 85) + end + self.controls.mercenaryItemSelect.shown = self.controls.mercenaryItemSelectLabel.shown + self.controls.mercenaryItemSelect.enabled = function() + return #self.controls.mercenaryItemSelect.list > 1 + end + self.controls.mercenaryItemSelect.tooltipFunc = function(tooltip, mode, index, value) + if main.popups[1] or mode == "OUT" or not value or not value.itemId or value.itemId == 0 then + tooltip:Clear() + return + end + local itemsTab = self.build and self.build.itemsTab + local item = itemsTab and itemsTab.items[value.itemId] + if item and tooltip:CheckForUpdate(item, launch.devModeAlt, self.build.outputRevision) then + itemsTab:AddItemTooltip(tooltip, item, nil, true) + end + end + self.controls.editPartyMemberStatsLabel = new("LabelControl"):LabelControl({"TOPLEFT",self.controls.notesDesc,"TOPRIGHT"}, {8, 0, 0, theme.stringHeight}, "^7Party Member Stats") self.controls.editPartyMemberStats = new("EditControl"):EditControl({"TOPLEFT",self.controls.editPartyMemberStatsLabel,"BOTTOMLEFT"}, {0, 2, 0, 0}, "", nil, "^%C\t\n", nil, nil, 14, true) self.controls.editPartyMemberStats.width = function() @@ -513,7 +684,432 @@ function PartyTabClass:PartyTab(build) return self end +function PartyTabClass:OpenPasteWarrantPopup() + local controls = {} + local clipboard = Paste() + local initialText = (clipboard and mercenaryWarrant.IsWarrantText(clipboard)) and clipboard or "" + local errText = "" + controls.label = new("LabelControl"):LabelControl(nil, {0, 16, 0, 16}, "^7Paste Mercenary Warrant text (from in-game or PoE Trade):") + controls.edit = new("EditControl"):EditControl(nil, {0, 38, 460, 240}, initialText, nil, "^%C\t\n", nil, function(buf) + errText = "" + controls.add.enabled = buf:match("%S") ~= nil + end, 14, true) + controls.err = new("LabelControl"):LabelControl(nil, {0, 284, 0, 14}, function() + return errText ~= "" and (colorCodes.NEGATIVE .. errText) or "" + end) + controls.add = new("ButtonControl"):ButtonControl(nil, {-50, 304, 90, 20}, "Add", function() + local ok, res = mercenaryWarrant.ApplyWarrant(self.build, controls.edit.buf) + if ok then + main:ClosePopup() + else + errText = res or "Invalid Mercenary Warrant text" + end + end) + controls.add.enabled = initialText ~= "" + controls.cancel = new("ButtonControl"):ButtonControl(nil, {50, 304, 90, 20}, "Cancel", function() + main:ClosePopup() + end) + main:OpenPopup(500, 336, "Paste Mercenary Warrant", controls, "add", "edit", "cancel") +end + +function PartyTabClass:GetActiveMercenary() + return self.mercenaries and self.mercenaries[self.activeMercenaryIndex] or nil +end + +function PartyTabClass:IsItemValidForMercenarySlot(item, slotName, mercItems) + if not item or not item.base then + return false + end + if item.type == "Jewel" or item.type == "Flask" or item.type == "Tincture" or item.type == "Graft" or item.type == "Viscera" then + return false + end + if slotName == "Weapon 1" then + return item.base.weapon ~= nil + elseif slotName == "Weapon 2" then + local itemsTab = self.build and self.build.itemsTab + local weapon1Id = mercItems and mercItems["Weapon 1"] or 0 + local weapon1 = itemsTab and itemsTab.items[weapon1Id] + local weapon1Type = weapon1 and weapon1.base and weapon1.base.type or "None" + local weaponInfo = self.build and self.build.data and self.build.data.weaponTypeInfo or {} + if weapon1Type == "None" then + return item.type == "Shield" or (weaponInfo[item.type] and weaponInfo[item.type].oneHand) + elseif weapon1Type == "Bow" then + return item.type == "Quiver" + elseif weaponInfo[weapon1Type] and weaponInfo[weapon1Type].oneHand then + return item.type == "Shield" or (weaponInfo[item.type] and weaponInfo[item.type].oneHand and ((weapon1Type == "Wand" and item.type == "Wand") or (weapon1Type ~= "Wand" and item.type ~= "Wand"))) + end + return false + end + local slotType = slotName:match("^([%a ]+) %d+$") or slotName + return item.type == slotType +end + +function PartyTabClass:SyncMercenaryItemPicker(slotName) + local control = self.controls.mercenaryItemSelect + if not control then + return + end + wipeTable(control.list) + control.selIndex = 1 + local merc = self:GetActiveMercenary() + local itemsTab = self.build and self.build.itemsTab + if not slotName or not merc or not itemsTab then + return + end + t_insert(control.list, { label = "None", itemId = 0 }) + local equippedId = merc.items and merc.items[slotName] or 0 + for _, itemId in ipairs(itemsTab.itemOrderList) do + local item = itemsTab.items[itemId] + if item and self:IsItemValidForMercenarySlot(item, slotName, merc.items) then + t_insert(control.list, { + label = colorCodes[item.rarity] .. item.name, + itemId = item.id, + }) + if item.id == equippedId then + control.selIndex = #control.list + end + end + end +end + +function PartyTabClass:SyncMercenaryItemsList() + local prevSlotName = self.controls.mercenaryItemsList and self.controls.mercenaryItemsList.selValue and self.controls.mercenaryItemsList.selValue.slotName + wipeTable(self.mercenaryItemRows) + local merc = self:GetActiveMercenary() + local itemsTab = self.build and self.build.itemsTab + local mercItems = (merc and merc.items) or (itemsTab and itemsTab.activeItemSet and itemsTab.activeItemSet.mercenaryItems) + if merc or (mercItems and next(mercItems) ~= nil) then + for _, slotName in ipairs(mercenarySlotOrder) do + local itemId = mercItems and mercItems[slotName] + if itemId and itemsTab and not itemsTab.items[itemId] then + itemId = nil + end + t_insert(self.mercenaryItemRows, { slotName = slotName, itemId = itemId }) + end + end + if self.controls.mercenaryItemsList then + local restoredIdx + if prevSlotName then + for i, row in ipairs(self.mercenaryItemRows) do + if row.slotName == prevSlotName then + restoredIdx = i + break + end + end + end + self.controls.mercenaryItemsList.selIndex = restoredIdx + self.controls.mercenaryItemsList.selValue = restoredIdx and self.mercenaryItemRows[restoredIdx] or nil + self:SyncMercenaryItemPicker(restoredIdx and prevSlotName or nil) + end +end + +function PartyTabClass:SyncMercenaryDropdown() + local control = self.controls.mercenarySelect + if control then + wipeTable(control.list) + for i, merc in ipairs(self.mercenaries) do + local name = (merc.name and merc.name ~= "") and merc.name or ("Mercenary #" .. tostring(i)) + local lvl = tonumber(merc.level) or 0 + local label = lvl > 0 and string.format("%s (lvl %d)", name, lvl) or name + t_insert(control.list, { label = label, index = i }) + end + control.selIndex = (#self.mercenaries > 0) and math.min(math.max(self.activeMercenaryIndex, 1), #self.mercenaries) or 1 + end + self:SyncMercenaryItemsList() +end + +function PartyTabClass:SetActiveMercenary(index) + if #self.mercenaries == 0 then + self.activeMercenaryIndex = 1 + self:SyncMercenaryDropdown() + return + end + self.activeMercenaryIndex = math.min(math.max(tonumber(index) or 1, 1), #self.mercenaries) + local merc = self.mercenaries[self.activeMercenaryIndex] + local itemsTab = self.build and self.build.itemsTab + if itemsTab and itemsTab.activeItemSet and merc then + itemsTab.activeItemSet.mercenaryName = merc.name + itemsTab.activeItemSet.mercenaryBuild = merc.build + itemsTab.activeItemSet.mercenaryType = merc.type + itemsTab.activeItemSet.mercenaryLevel = merc.level + itemsTab.activeItemSet.mercenaryItems = merc.items or {} + end + local skillsTab = self.build and self.build.skillsTab + if skillsTab and skillsTab.mercenarySocketGroupList and merc then + wipeTable(skillsTab.mercenarySocketGroupList) + for _, group in ipairs(merc.skills or {}) do + t_insert(skillsTab.mercenarySocketGroupList, group) + end + end + self:SyncMercenaryDropdown() + if self.build then + self.build.buildFlag = true + end +end + +function PartyTabClass:UpsertMercenary(entry) + if not entry then + return + end + entry.skills = entry.skills or {} + entry.items = entry.items or {} + local matchIdx + for i, existing in ipairs(self.mercenaries) do + if entry.index ~= nil and existing.index ~= nil and existing.index == entry.index then + matchIdx = i + break + elseif entry.name and entry.name ~= "" and existing.name == entry.name then + matchIdx = i + break + end + end + if matchIdx then + if next(entry.items) == nil and self.mercenaries[matchIdx].items and next(self.mercenaries[matchIdx].items) ~= nil and not entry.replaceItems then + entry.items = self.mercenaries[matchIdx].items + end + entry.replaceItems = nil + self.mercenaries[matchIdx] = entry + self:SetActiveMercenary(matchIdx) + else + entry.replaceItems = nil + t_insert(self.mercenaries, entry) + self:SetActiveMercenary(#self.mercenaries) + end +end + +function PartyTabClass:RemoveActiveMercenary() + if #self.mercenaries == 0 then + return + end + table.remove(self.mercenaries, self.activeMercenaryIndex) + if #self.mercenaries == 0 then + local itemsTab = self.build and self.build.itemsTab + if itemsTab and itemsTab.activeItemSet then + itemsTab.activeItemSet.mercenaryName = nil + itemsTab.activeItemSet.mercenaryBuild = nil + itemsTab.activeItemSet.mercenaryType = nil + itemsTab.activeItemSet.mercenaryLevel = nil + itemsTab.activeItemSet.mercenaryItems = {} + end + local skillsTab = self.build and self.build.skillsTab + if skillsTab and skillsTab.mercenarySocketGroupList then + wipeTable(skillsTab.mercenarySocketGroupList) + end + self.activeMercenaryIndex = 1 + self:SyncMercenaryDropdown() + if self.build then + self.build.buildFlag = true + end + else + self:SetActiveMercenary(math.min(self.activeMercenaryIndex, #self.mercenaries)) + end +end + +function PartyTabClass:IsMercenaryShown() + if self.build and self.build.spec and self.build.spec.curAscendClassName == "Luminary" then + return true + end + if self.mercenaries and #self.mercenaries > 0 then + return true + end + local skillsTab = self.build and self.build.skillsTab + if skillsTab and skillsTab.mercenarySocketGroupList and #skillsTab.mercenarySocketGroupList > 0 then + return true + end + local itemsTab = self.build and self.build.itemsTab + if itemsTab and itemsTab.activeItemSet and itemsTab.activeItemSet.mercenaryItems then + for _, itemId in pairs(itemsTab.activeItemSet.mercenaryItems) do + if itemId and itemId ~= 0 then + return true + end + end + end + return false +end + +function PartyTabClass:BuildMercenarySkillsText() + local lines = {} + local merc = self:GetActiveMercenary() + local skillsTab = self.build and self.build.skillsTab + local skillGroups = (merc and merc.skills) or (skillsTab and skillsTab.mercenarySocketGroupList) + if skillGroups and #skillGroups > 0 then + t_insert(lines, "^7Skills:") + for _, group in ipairs(skillGroups) do + local parts = {} + for _, gem in ipairs(group.gemList or {}) do + local name = (gem.gemData and gem.gemData.name) or (gem.grantedEffect and gem.grantedEffect.name) or gem.nameSpec + if name and name ~= "" then + local info = {} + if gem.level then + t_insert(info, "Lv " .. tostring(gem.level)) + end + if gem.mercTier then + t_insert(info, "Tier " .. tostring(gem.mercTier)) + end + t_insert(parts, #info > 0 and (name .. " (" .. table.concat(info, ", ") .. ")") or name) + end + end + if #parts > 0 then + t_insert(lines, " " .. (group.enabled == false and "^x7F7F7F" or "^7") .. table.concat(parts, " + ")) + end + end + else + t_insert(lines, "^x7F7F7FSkills: None") + end + return table.concat(lines, "\n") +end + +function PartyTabClass:BuildMercenarySummaryText() + local lines = { self:BuildMercenarySkillsText() } + local merc = self:GetActiveMercenary() + + local itemsTab = self.build and self.build.itemsTab + local itemLines = {} + local mercItems = (merc and merc.items) or (itemsTab and itemsTab.activeItemSet and itemsTab.activeItemSet.mercenaryItems) + if mercItems and itemsTab then + for slotName, itemId in pairsSortByKey(mercItems) do + if itemId and itemId ~= 0 then + local item = itemsTab.items[itemId] + if item then + t_insert(itemLines, " ^7" .. slotName .. ": " .. colorCodes[item.rarity] .. item.name) + end + end + end + end + if #itemLines > 0 then + t_insert(lines, "^7Items:") + for _, l in ipairs(itemLines) do + t_insert(lines, l) + end + else + t_insert(lines, "^x7F7F7FItems: None") + end + return table.concat(lines, "\n") +end + +function PartyTabClass:ParseMercenaryNode(mercNode, itemLookup) + local itemsTab = self.build and self.build.itemsTab + local skillsTab = self.build and self.build.skillsTab + local entry = { + index = tonumber(mercNode.attrib.index), + name = mercNode.attrib.name, + build = mercNode.attrib.build, + type = mercNode.attrib.type, + level = tonumber(mercNode.attrib.level), + skills = {}, + items = {}, + replaceItems = true, + } + for _, child in ipairs(mercNode) do + if child.elem == "Skills" and skillsTab then + for _, skillNode in ipairs(child) do + if skillNode.elem == "Skill" then + skillsTab:LoadSkill(skillNode, skillsTab.activeSkillSetId, entry.skills) + if entry.skills[#entry.skills] then + entry.skills[#entry.skills].isMercenary = true + end + end + end + elseif child.elem == "Items" and itemsTab then + for _, slotNode in ipairs(child) do + if slotNode.elem == "Slot" and slotNode.attrib.name and slotNode.attrib.itemId then + local slotName = slotNode.attrib.name:gsub("^Mercenary ", "") + local srcId = tonumber(slotNode.attrib.itemId) + if srcId and srcId ~= 0 then + if itemLookup and itemLookup[srcId] then + local rawText + for _, itemChild in ipairs(itemLookup[srcId]) do + if type(itemChild) == "string" then + rawText = itemChild + break + end + end + if rawText then + local newItem = new("Item"):Item(rawText) + if newItem.base then + itemsTab:AddItem(newItem, true) + entry.items[slotName] = newItem.id + end + end + elseif itemsTab.items[srcId] then + entry.items[slotName] = srcId + end + end + end + end + end + end + return entry +end + +function PartyTabClass:ApplyMercenariesXML(node, dbXML, replaceExisting) + if not node then + return + end + local itemLookup + if dbXML then + itemLookup = {} + for _, tabNode in ipairs(dbXML[1]) do + if type(tabNode) == "table" and tabNode.elem == "Items" then + for _, itemNode in ipairs(tabNode) do + if itemNode.elem == "Item" and itemNode.attrib.id then + itemLookup[tonumber(itemNode.attrib.id)] = itemNode + end + end + end + end + end + + local hadExisting = #self.mercenaries > 0 + local prevActive = self.activeMercenaryIndex + if replaceExisting then + wipeTable(self.mercenaries) + end + + local activeIdx = 1 + if node.elem == "Mercenaries" then + activeIdx = tonumber(node.attrib.active) or 1 + for _, child in ipairs(node) do + if child.elem == "Mercenary" then + local entry = self:ParseMercenaryNode(child, itemLookup) + if replaceExisting then + t_insert(self.mercenaries, entry) + else + self:UpsertMercenary(entry) + end + end + end + if not replaceExisting and hadExisting then + activeIdx = prevActive + end + elseif node.elem == "Mercenary" then + local entry = self:ParseMercenaryNode(node, itemLookup) + self:UpsertMercenary(entry) + activeIdx = (not replaceExisting and hadExisting) and prevActive or self.activeMercenaryIndex + end + + if #self.mercenaries > 0 then + self:SetActiveMercenary(activeIdx) + else + self:SyncMercenaryDropdown() + end + if self.build and self.build.itemsTab then + self.build.itemsTab:PopulateSlots() + end +end + +function PartyTabClass:PostLoad() + if self.pendingMercenaryXML then + self:ApplyMercenariesXML(self.pendingMercenaryXML, nil, true) + self.pendingMercenaryXML = nil + end +end + function PartyTabClass:Load(xml, fileName) + self.pendingMercenaryXML = nil + wipeTable(self.mercenaries) + self.activeMercenaryIndex = 1 + self:SyncMercenaryDropdown() for _, node in ipairs(xml) do if node.elem == "ImportedBuffs" then if not node.attrib.name then @@ -554,6 +1150,8 @@ function PartyTabClass:Load(xml, fileName) --self:ParseBuffs(self.buffExports, node[1] or "", "Link") --self:ParseBuffs(self.buffExports, node[1] or "", "EnemyConditions") --self:ParseBuffs(self.buffExports, node[1] or "", "EnemyMods") + elseif node.elem == "Mercenary" or node.elem == "Mercenaries" then + self.pendingMercenaryXML = node end end self.lastContent.PartyMemberStats = self.controls.editPartyMemberStats.buf @@ -651,6 +1249,83 @@ function PartyTabClass:Save(xml) t_insert(child, exportString) t_insert(xml, child) end + local function serializeMercenaryNode(merc) + local mercNode = { + elem = "Mercenary", + attrib = { + index = merc.index ~= nil and tostring(merc.index) or nil, + name = merc.name, + build = merc.build, + type = merc.type, + level = merc.level and tostring(merc.level) or nil, + } + } + if merc.skills and #merc.skills > 0 then + local skillsNode = { elem = "Skills" } + for _, socketGroup in ipairs(merc.skills) do + local skillNode = { elem = "Skill", attrib = { + enabled = tostring(socketGroup.enabled), + label = socketGroup.label, + } } + for _, gemInstance in ipairs(socketGroup.gemList) do + t_insert(skillNode, { elem = "Gem", attrib = { + nameSpec = gemInstance.nameSpec, + skillId = gemInstance.skillId, + gemId = gemInstance.gemData and gemInstance.gemData.gameId, + variantId = gemInstance.gemData and gemInstance.gemData.variantId, + level = tostring(gemInstance.level), + quality = tostring(gemInstance.quality), + mercTier = gemInstance.mercTier and tostring(gemInstance.mercTier), + enabled = tostring(gemInstance.enabled), + enableGlobal1 = tostring(gemInstance.enableGlobal1), + enableGlobal2 = tostring(gemInstance.enableGlobal2), + count = tostring(gemInstance.count), + } }) + end + t_insert(skillsNode, skillNode) + end + t_insert(mercNode, skillsNode) + end + if merc.items and next(merc.items) ~= nil then + local itemsNode = { elem = "Items" } + for slotName, itemId in pairsSortByKey(merc.items) do + if itemId and itemId ~= 0 then + t_insert(itemsNode, { elem = "Slot", attrib = { name = slotName, itemId = tostring(itemId) } }) + end + end + if #itemsNode > 0 then + t_insert(mercNode, itemsNode) + end + end + return mercNode + end + + local mercList = self.mercenaries + if #mercList == 0 then + local skillsTab = self.build and self.build.skillsTab + local itemsTab = self.build and self.build.itemsTab + local itemSet = itemsTab and itemsTab.activeItemSet + local hasMercMeta = itemSet and ((itemSet.mercenaryName and itemSet.mercenaryName ~= "") or (itemSet.mercenaryBuild and itemSet.mercenaryBuild ~= "") or (itemSet.mercenaryLevel and itemSet.mercenaryLevel > 0)) + local hasMercSkills = skillsTab and skillsTab.mercenarySocketGroupList and #skillsTab.mercenarySocketGroupList > 0 + local hasMercItems = itemSet and itemSet.mercenaryItems and next(itemSet.mercenaryItems) ~= nil + if hasMercMeta or hasMercSkills or hasMercItems then + mercList = { { + name = itemSet and itemSet.mercenaryName, + build = itemSet and itemSet.mercenaryBuild, + type = itemSet and itemSet.mercenaryType, + level = itemSet and itemSet.mercenaryLevel, + skills = skillsTab and skillsTab.mercenarySocketGroupList or {}, + items = itemSet and itemSet.mercenaryItems or {}, + } } + end + end + if #mercList > 0 then + local mercsNode = { elem = "Mercenaries", attrib = { active = tostring(self.activeMercenaryIndex or 1) } } + for _, merc in ipairs(mercList) do + t_insert(mercsNode, serializeMercenaryNode(merc)) + end + t_insert(xml, mercsNode) + end xml.attrib = { destination = self.controls.importCodeDestination.list[self.controls.importCodeDestination.selIndex], append = tostring(self.controls.appendNotReplace.state), diff --git a/src/Classes/PoEAPI.lua b/src/Classes/PoEAPI.lua index 7a9031df059..e46cf15e588 100644 --- a/src/Classes/PoEAPI.lua +++ b/src/Classes/PoEAPI.lua @@ -6,6 +6,7 @@ local scopesOAuth = { "account:profile", "account:leagues", "account:characters", + "account:league_accounts", "account:trade" } @@ -236,3 +237,13 @@ function PoEAPIClass:DownloadCharacter(realm, name, callback) self:DownloadWithRateLimit("character-request-limit", "/character" .. (realm == "pc" and "" or "/" .. realm) .. "/" .. name, callback) end + +---Fetches league account data (including hired mercenaries) from PoE's OAuth api +---@param realm string Realm to fetch from +---@param league string League name to fetch +---@param callback DownloadCallback +function PoEAPIClass:DownloadLeagueAccount(realm, league, callback) + local realmPath = realm == "pc" and "" or "/" .. realm + self:DownloadWithRateLimit("league-account-request-limit", + "/league-account" .. realmPath .. "/" .. urlEncode(league), callback) +end diff --git a/src/Classes/SkillsTab.lua b/src/Classes/SkillsTab.lua index 04d383461cd..7e72b3f03e8 100644 --- a/src/Classes/SkillsTab.lua +++ b/src/Classes/SkillsTab.lua @@ -87,6 +87,7 @@ function SkillsTabClass:SkillsTab(build) self.build = build self.socketGroupList = { } + self.mercenarySocketGroupList = { } self.sortGemsByDPS = true self.sortGemsByDPSField = "CombinedDPS" @@ -438,7 +439,11 @@ will automatically apply to the skill.]] end -function SkillsTabClass:LoadSkill(node, skillSetId) +function SkillsTabClass:IsLuminary() + return self.build and self.build.spec and self.build.spec.curAscendClassName == "Luminary" +end + +function SkillsTabClass:LoadSkill(node, skillSetId, targetList) if node.elem ~= "Skill" then return end @@ -453,6 +458,9 @@ function SkillsTabClass:LoadSkill(node, skillSetId) socketGroup.mainActiveSkill = tonumber(node.attrib.mainActiveSkill) or 1 socketGroup.mainActiveSkillCalcs = tonumber(node.attrib.mainActiveSkillCalcs) or 1 socketGroup.gemList = { } + if targetList == self.skillSets[skillSetId].mercenarySocketGroupList then + socketGroup.isMercenary = true + end if node.attrib.imbuedSupport and node.attrib.slot then local name = escapeGGGString(node.attrib.imbuedSupport) local gem = self:FindImbuedSupport(name) @@ -495,6 +503,7 @@ function SkillsTabClass:LoadSkill(node, skillSetId) end gemInstance.level = tonumber(child.attrib.level) gemInstance.quality = tonumber(child.attrib.quality) + gemInstance.mercTier = tonumber(child.attrib.mercTier) gemInstance.nameSpec = sanitiseText(gemInstance.nameSpec) gemInstance.enabled = not child.attrib.enabled and true or child.attrib.enabled == "true" gemInstance.enableGlobal1 = not child.attrib.enableGlobal1 or child.attrib.enableGlobal1 == "true" @@ -518,7 +527,7 @@ function SkillsTabClass:LoadSkill(node, skillSetId) socketGroup.gemList[1].skillPart = tonumber(node.attrib.skillPart) end self:ProcessSocketGroup(socketGroup) - t_insert(self.skillSets[skillSetId].socketGroupList, socketGroup) + t_insert(targetList or self.skillSets[skillSetId].socketGroupList, socketGroup) end function SkillsTabClass:Load(xml, fileName) @@ -563,7 +572,13 @@ function SkillsTabClass:Load(xml, fileName) skillSet.title = node.attrib.title t_insert(self.skillSetOrderList, skillSet.id) for _, subNode in ipairs(node) do - self:LoadSkill(subNode, skillSet.id) + if subNode.elem == "MercenarySkills" then + for _, mercNode in ipairs(subNode) do + self:LoadSkill(mercNode, skillSet.id, skillSet.mercenarySocketGroupList) + end + else + self:LoadSkill(subNode, skillSet.id) + end end end end @@ -581,50 +596,61 @@ function SkillsTabClass:Save(xml) sortGemsByDPSField = self.sortGemsByDPSField, showLegacyGems = tostring(self.showLegacyGems), } + local function saveSocketGroup(parent, socketGroup) + local node = { elem = "Skill", attrib = { + enabled = tostring(socketGroup.enabled), + includeInFullDPS = tostring(socketGroup.includeInFullDPS), + groupCount = socketGroup.groupCount ~= nil and tostring(socketGroup.groupCount), + label = socketGroup.label, + slot = socketGroup.slot, + source = socketGroup.source, + mainActiveSkill = tostring(socketGroup.mainActiveSkill), + mainActiveSkillCalcs = tostring(socketGroup.mainActiveSkillCalcs), + imbuedSupport = socketGroup.imbuedSupport and tostring(socketGroup.imbuedSupport), + } } + for _, gemInstance in ipairs(socketGroup.gemList) do + t_insert(node, { elem = "Gem", attrib = { + nameSpec = gemInstance.nameSpec, + skillId = gemInstance.skillId, + gemId = gemInstance.gemData and gemInstance.gemData.gameId, + variantId = gemInstance.gemData and gemInstance.gemData.variantId, + level = tostring(gemInstance.level), + quality = tostring(gemInstance.quality), + mercTier = gemInstance.mercTier and tostring(gemInstance.mercTier), + enabled = tostring(gemInstance.enabled), + enableGlobal1 = tostring(gemInstance.enableGlobal1), + enableGlobal2 = tostring(gemInstance.enableGlobal2), + count = tostring(gemInstance.count), + skillPart = gemInstance.skillPart and tostring(gemInstance.skillPart), + skillPartCalcs = gemInstance.skillPartCalcs and tostring(gemInstance.skillPartCalcs), + skillStageCount = gemInstance.skillStageCount and tostring(gemInstance.skillStageCount), + skillStageCountCalcs = gemInstance.skillStageCountCalcs and tostring(gemInstance.skillStageCountCalcs), + skillMineCount = gemInstance.skillMineCount and tostring(gemInstance.skillMineCount), + skillMineCountCalcs = gemInstance.skillMineCountCalcs and tostring(gemInstance.skillMineCountCalcs), + skillMinion = gemInstance.skillMinion, + skillMinionCalcs = gemInstance.skillMinionCalcs, + skillMinionItemSet = gemInstance.skillMinionItemSet and tostring(gemInstance.skillMinionItemSet), + skillMinionItemSetCalcs = gemInstance.skillMinionItemSetCalcs and tostring(gemInstance.skillMinionItemSetCalcs), + skillMinionSkill = gemInstance.skillMinionSkill and tostring(gemInstance.skillMinionSkill), + skillMinionSkillCalcs = gemInstance.skillMinionSkillCalcs and tostring(gemInstance.skillMinionSkillCalcs), + } }) + end + t_insert(parent, node) + end for _, skillSetId in ipairs(self.skillSetOrderList) do local skillSet = self.skillSets[skillSetId] local child = { elem = "SkillSet", attrib = { id = tostring(skillSetId), title = skillSet.title } } t_insert(xml, child) for _, socketGroup in ipairs(skillSet.socketGroupList) do - local node = { elem = "Skill", attrib = { - enabled = tostring(socketGroup.enabled), - includeInFullDPS = tostring(socketGroup.includeInFullDPS), - groupCount = socketGroup.groupCount ~= nil and tostring(socketGroup.groupCount), - label = socketGroup.label, - slot = socketGroup.slot, - source = socketGroup.source, - mainActiveSkill = tostring(socketGroup.mainActiveSkill), - mainActiveSkillCalcs = tostring(socketGroup.mainActiveSkillCalcs), - imbuedSupport = socketGroup.imbuedSupport and tostring(socketGroup.imbuedSupport), - } } - for _, gemInstance in ipairs(socketGroup.gemList) do - t_insert(node, { elem = "Gem", attrib = { - nameSpec = gemInstance.nameSpec, - skillId = gemInstance.skillId, - gemId = gemInstance.gemData and gemInstance.gemData.gameId, - variantId = gemInstance.gemData and gemInstance.gemData.variantId, - level = tostring(gemInstance.level), - quality = tostring(gemInstance.quality), - enabled = tostring(gemInstance.enabled), - enableGlobal1 = tostring(gemInstance.enableGlobal1), - enableGlobal2 = tostring(gemInstance.enableGlobal2), - count = tostring(gemInstance.count), - skillPart = gemInstance.skillPart and tostring(gemInstance.skillPart), - skillPartCalcs = gemInstance.skillPartCalcs and tostring(gemInstance.skillPartCalcs), - skillStageCount = gemInstance.skillStageCount and tostring(gemInstance.skillStageCount), - skillStageCountCalcs = gemInstance.skillStageCountCalcs and tostring(gemInstance.skillStageCountCalcs), - skillMineCount = gemInstance.skillMineCount and tostring(gemInstance.skillMineCount), - skillMineCountCalcs = gemInstance.skillMineCountCalcs and tostring(gemInstance.skillMineCountCalcs), - skillMinion = gemInstance.skillMinion, - skillMinionCalcs = gemInstance.skillMinionCalcs, - skillMinionItemSet = gemInstance.skillMinionItemSet and tostring(gemInstance.skillMinionItemSet), - skillMinionItemSetCalcs = gemInstance.skillMinionItemSetCalcs and tostring(gemInstance.skillMinionItemSetCalcs), - skillMinionSkill = gemInstance.skillMinionSkill and tostring(gemInstance.skillMinionSkill), - skillMinionSkillCalcs = gemInstance.skillMinionSkillCalcs and tostring(gemInstance.skillMinionSkillCalcs), - } }) + saveSocketGroup(child, socketGroup) + end + if skillSet.mercenarySocketGroupList and #skillSet.mercenarySocketGroupList > 0 then + local mercNode = { elem = "MercenarySkills" } + for _, socketGroup in ipairs(skillSet.mercenarySocketGroupList) do + saveSocketGroup(mercNode, socketGroup) end - t_insert(child, node) + t_insert(child, mercNode) end end end @@ -709,6 +735,11 @@ end function SkillsTabClass:PasteSocketGroup(testInput) local skillText = sanitiseText(Paste() or testInput) if skillText then + local warrantParser = require("Modules.MercenaryWarrantParser") + if self:IsLuminary() and warrantParser.IsWarrantText(skillText) then + warrantParser.ApplyWarrant(self.build, skillText) + return + end local newGroup = { label = "", enabled = true, gemList = { } } local label = skillText:match("Label: (%C+)") if label then @@ -936,7 +967,10 @@ function SkillsTabClass:CreateGemSlot(index) end end - local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator(self.build) + local calcFunc, calcBase + if not self.displayGroup.isMercenary then + calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator(self.build) + end if calcFunc then local storedQuality = self.displayGroup.gemList[index].quality self.displayGroup.gemList[index].quality = 20 @@ -975,7 +1009,7 @@ function SkillsTabClass:CreateGemSlot(index) end) slot.enabled.tooltipFunc = function(tooltip) if tooltip:CheckForUpdate(self.build.outputRevision, self.displayGroup) then - if self.displayGroup.gemList[index] then + if self.displayGroup.gemList[index] and not self.displayGroup.isMercenary then local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator(self.build) if calcFunc then self.displayGroup.gemList[index].enabled = not self.displayGroup.gemList[index].enabled @@ -1216,6 +1250,10 @@ function SkillsTabClass:ProcessSocketGroup(socketGroup) gemInstance.errMsg = gemInstance.nameSpec .. " is not supported yet" gemInstance.gemData = nil end + if socketGroup.isMercenary and not gemInstance.gemData and not gemInstance.grantedEffect then + -- Mercenary-exclusive skills and tiered supports may not exist in player gem data + gemInstance.errMsg = nil + end if gemInstance.gemData or gemInstance.grantedEffect then gemInstance.new = nil local grantedEffect = gemInstance.grantedEffect or gemInstance.gemData.grantedEffect @@ -1241,6 +1279,23 @@ function SkillsTabClass:ProcessSocketGroup(socketGroup) end end end + if socketGroup.isMercenary then + if socketGroup.label and socketGroup.label:match("%S") then + socketGroup.displayLabel = socketGroup.label + else + local displayLabel + for _, gemInstance in ipairs(socketGroup.gemList) do + local grantedEffect = gemInstance.grantedEffect or (gemInstance.gemData and gemInstance.gemData.grantedEffect) + if grantedEffect and not grantedEffect.support and gemInstance.enabled then + displayLabel = (displayLabel and displayLabel .. ", " or "") .. grantedEffect.name + end + end + if not displayLabel and socketGroup.gemList[1] and socketGroup.gemList[1].nameSpec:match("%S") then + displayLabel = socketGroup.gemList[1].nameSpec + end + socketGroup.displayLabel = displayLabel or "" + end + end end -- reprocess socket groups on rebuild @@ -1408,21 +1463,27 @@ function SkillsTabClass:AddSocketGroupTooltip(tooltip, socketGroup) end end +local function copySocketGroupList(list) + local out = { } + for socketGroupIndex, socketGroup in pairs(list or {}) do + local newGroup = copyTable(socketGroup, true) + newGroup.gemList = { } + for gemIndex, gem in pairs(socketGroup.gemList) do + newGroup.gemList[gemIndex] = copyTable(gem, true) + end + out[socketGroupIndex] = newGroup + end + return out +end + function SkillsTabClass:CreateUndoState() local state = { } state.activeSkillSetId = self.activeSkillSetId state.skillSets = { } for skillSetIndex, skillSet in pairs(self.skillSets) do local newSkillSet = copyTable(skillSet, true) - newSkillSet.socketGroupList = { } - for socketGroupIndex, socketGroup in pairs(skillSet.socketGroupList) do - local newGroup = copyTable(socketGroup, true) - newGroup.gemList = { } - for gemIndex, gem in pairs(socketGroup.gemList) do - newGroup.gemList[gemIndex] = copyTable(gem, true) - end - newSkillSet.socketGroupList[socketGroupIndex] = newGroup - end + newSkillSet.socketGroupList = copySocketGroupList(skillSet.socketGroupList) + newSkillSet.mercenarySocketGroupList = copySocketGroupList(skillSet.mercenarySocketGroupList) state.skillSets[skillSetIndex] = newSkillSet end state.skillSetOrderList = copyTable(self.skillSetOrderList) @@ -1433,7 +1494,8 @@ function SkillsTabClass:CreateUndoState() end function SkillsTabClass:RestoreUndoState(state) - local displayId = isValueInArray(self.socketGroupList, self.displayGroup) + local displayIsMercenary = self.displayGroup and self.displayGroup.isMercenary + local displayId = displayIsMercenary and isValueInArray(self.mercenarySocketGroupList, self.displayGroup) or isValueInArray(self.socketGroupList, self.displayGroup) wipeTable(self.skillSets) for k, v in pairs(state.skillSets) do self.skillSets[k] = v @@ -1443,7 +1505,11 @@ function SkillsTabClass:RestoreUndoState(state) self.skillSetOrderList[k] = v end self:SetActiveSkillSet(state.activeSkillSetId) - self:SetDisplayGroup(displayId and self.socketGroupList[displayId]) + if displayIsMercenary then + self:SetDisplayGroup(displayId and self.mercenarySocketGroupList[displayId]) + else + self:SetDisplayGroup(displayId and self.socketGroupList[displayId]) + end if self.controls.groupList.selValue then self.controls.groupList.selValue = self.socketGroupList[self.controls.groupList.selIndex] end @@ -1464,7 +1530,7 @@ end -- Creates a new skill set without adding to order list function SkillsTabClass:CreateSkillSet(skillSetId, title) - local skillSet = { id = skillSetId, title = title, socketGroupList = {} } + local skillSet = { id = skillSetId, title = title, socketGroupList = {}, mercenarySocketGroupList = {} } if not skillSetId then skillSet.id = #self.skillSets + 1 end @@ -1485,7 +1551,7 @@ function SkillsTabClass:CopySkillSet(sourceSkillSetId, newSkillSetName) local newSkillSet = copyTable(skillSet, true) newSkillSet.title = newSkillSetName or skillSet.title .. " (Copy)" newSkillSet.socketGroupList = {} - for socketGroupIndex, socketGroup in pairs(skillSet.socketGroupList) do + for _, socketGroup in pairs(skillSet.socketGroupList) do local newGroup = copyTable(socketGroup, true) newGroup.gemList = {} for gemIndex, gem in pairs(socketGroup.gemList) do @@ -1493,6 +1559,15 @@ function SkillsTabClass:CopySkillSet(sourceSkillSetId, newSkillSetName) end t_insert(newSkillSet.socketGroupList, newGroup) end + newSkillSet.mercenarySocketGroupList = {} + for _, socketGroup in pairs(skillSet.mercenarySocketGroupList or {}) do + local newGroup = copyTable(socketGroup, true) + newGroup.gemList = {} + for gemIndex, gem in pairs(socketGroup.gemList) do + newGroup.gemList[gemIndex] = copyTable(gem, true) + end + t_insert(newSkillSet.mercenarySocketGroupList, newGroup) + end newSkillSet.id = #self.skillSets + 1 self.skillSets[newSkillSet.id] = newSkillSet t_insert(self.skillSetOrderList, newSkillSet.id) @@ -1546,6 +1621,8 @@ function SkillsTabClass:SetActiveSkillSet(skillSetId, deferSync) end self.socketGroupList = self.skillSets[skillSetId].socketGroupList + self.skillSets[skillSetId].mercenarySocketGroupList = self.skillSets[skillSetId].mercenarySocketGroupList or {} + self.mercenarySocketGroupList = self.skillSets[skillSetId].mercenarySocketGroupList self:RebuildImbuedSupportBySlot() self.controls.groupList.list = self.socketGroupList self.activeSkillSetId = skillSetId diff --git a/src/Classes/TradeQueryRateLimiter.lua b/src/Classes/TradeQueryRateLimiter.lua index f98c59f669f..840fb1c1f8b 100644 --- a/src/Classes/TradeQueryRateLimiter.lua +++ b/src/Classes/TradeQueryRateLimiter.lua @@ -56,7 +56,8 @@ function TradeQueryRateLimiterClass:TradeQueryRateLimiter() ["trade-search-request-limit"] = {}, ["trade-fetch-request-limit"] = {}, ["character-list-request-limit"] = {}, - ["character-request-limit"] = {} + ["character-request-limit"] = {}, + ["league-account-request-limit"] = {} } return self end @@ -225,6 +226,7 @@ function TradeQueryRateLimiterClass:InsertRequest(policy, timestamp, time) end local requestId = self.requestId self.requestId = self.requestId + 1 + self.pendingRequests[policy] = self.pendingRequests[policy] or {} table.insert(self.pendingRequests[policy], requestId) return requestId end diff --git a/src/Modules/MercenaryWarrantParser.lua b/src/Modules/MercenaryWarrantParser.lua new file mode 100644 index 00000000000..9e4193fac4f --- /dev/null +++ b/src/Modules/MercenaryWarrantParser.lua @@ -0,0 +1,258 @@ +-- Path of Building +-- +-- Module: Mercenary Warrant Parser +-- Parses in-game Mercenary Warrant clipboard text into SPEC-001/SPEC-002 structures. +-- +local t_insert = table.insert +local m_min = math.min +local m_max = math.max +local m_floor = math.floor + +local M = {} + +local buildArchetypeToType = { + ["Stormhand"] = "Intelligence", + ["Kineticist"] = "Intelligence", + ["Winterpriest"] = "Intelligence", + ["Flamecaller"] = "Intelligence", + ["Sanguimancer"] = "StrInt", + ["Warpriest"] = "StrInt", + ["Bastion"] = "Strength", + ["Striker"] = "Strength", + ["Eruptor"] = "Strength", + ["Earthshaker"] = "Strength", + ["Ripper"] = "StrDex", + ["Manyshot"] = "Dexterity", + ["Sniper"] = "Dexterity", + ["Toxicologist"] = "DexInt", + ["Trapmaster"] = "DexInt", +} + +local supportAliases = { + ["Increased Area of Effect"] = "Increased Area of Effect Support", + ["Greater Area of Effect"] = "Increased Area of Effect Support", + ["Less Duration"] = "Less Duration Support", + ["Greater Less Duration"] = "Less Duration Support", + ["Elemental Focus"] = "Elemental Focus Support", + ["Greater Elemental Focus"] = "Elemental Focus Support", + ["Greater Critical Chance"] = "Increased Critical Strikes Support", + ["Increased Critical Chance"] = "Increased Critical Strikes Support", + ["Second Wind"] = "Second Wind Support", + ["Faster Casting"] = "Faster Casting Support", + ["Brutality"] = "Brutality Support", + ["Concentrated Effect"] = "Concentrated Effect Support", + ["Greater Concentrated Effect"] = "Concentrated Effect Support", + ["Pulverise"] = "Pulverise Support", + ["Greater Pulverise"] = "Pulverise Support", + ["Faster Attacks"] = "Faster Attacks Support", + ["Greater Faster Attacks"] = "Faster Attacks Support", +} + +local function trim(s) + return (s:gsub("^%s+", ""):gsub("%s+$", "")) +end + +local function isNonSkillSection(lines) + local first = lines[1] or "" + if first:match("^Right click") + or first:match("^Open a portal") + or first:match("^Note:") + or first:match("^Item Level:") + or first:match("^Item Class:") + or first:match("^Rarity:") + or first == "Corrupted" + or first == "Mirrored" + or first == "Unidentified" then + return true + end + return false +end + +---@param text string? +---@return boolean +function M.IsWarrantText(text) + if type(text) ~= "string" then + return false + end + for line in text:gmatch("([^\r\n]+)") do + local cleaned = trim(line) + if cleaned == "--------" then + return false + elseif cleaned == "Mercenary Warrant" then + return true + end + end + return false +end + +---@param buildName string? +---@return string? +function M.BuildToType(buildName) + return buildName and buildArchetypeToType[buildName] or nil +end + +---@param rawName string +---@param isSupport boolean +---@param skillsTab SkillsTab? +---@return string nameSpec, string? gemId +function M.ResolveGemName(rawName, isSupport, skillsTab) + local candidate = isSupport and (supportAliases[rawName] or rawName) or rawName + if skillsTab and skillsTab.FindSkillGem then + local errMsg, gemData = skillsTab:FindSkillGem(candidate) + if not errMsg and gemData then + return gemData.name, gemData.id + end + end + return rawName, nil +end + +---@param text string +---@param skillsTab SkillsTab? +---@return table? parsed, string? errMsg +function M.Parse(text, skillsTab) + if not M.IsWarrantText(text) then + return nil, "Not a Mercenary Warrant" + end + + -- Split into sections separated by "--------" + local sections = {} + local current = {} + for line in text:gmatch("([^\r\n]+)") do + local cleaned = trim(line) + if cleaned == "--------" then + if #current > 0 then + t_insert(sections, current) + current = {} + end + elseif cleaned ~= "" then + t_insert(current, cleaned) + end + end + if #current > 0 then + t_insert(sections, current) + end + + local result = { + name = sections[2] and sections[2][1] or "", + build = nil, + level = nil, + type = nil, + skillGroups = {}, + } + + -- Section 3 holds Build: and Mercenary Level: + local metaIndex = 3 + if sections[metaIndex] then + local hasMeta = false + for _, line in ipairs(sections[metaIndex]) do + local b = line:match("^Build:%s*(.+)$") + local lvl = line:match("^Mercenary Level:%s*(%d+)$") + if b then + result.build = trim(b) + result.type = M.BuildToType(result.build) + hasMeta = true + elseif lvl then + result.level = tonumber(lvl) + hasMeta = true + end + end + if hasMeta then + metaIndex = 4 + end + end + + local defaultLevel = result.level and m_min(20, m_max(1, m_floor(result.level / 3.5))) or 20 + for i = metaIndex, #sections do + local lines = sections[i] + if #lines > 0 and not isNonSkillSection(lines) then + local group = { + label = lines[1], + enabled = true, + isMercenary = true, + gemList = {}, + } + for j, line in ipairs(lines) do + local isSupport = j > 1 + local rawName, tier = line:match("^(.+)%s*%(Tier:%s*(%d+)%)$") + if rawName then + rawName = trim(rawName) + tier = tonumber(tier) + else + rawName = line + end + local nameSpec, gemId = M.ResolveGemName(rawName, isSupport, skillsTab) + t_insert(group.gemList, { + nameSpec = nameSpec, + gemId = gemId, + level = defaultLevel, + quality = 0, + mercTier = tier, + enabled = true, + enableGlobal1 = true, + enableGlobal2 = true, + count = 1, + }) + end + t_insert(result.skillGroups, group) + end + end + + return result +end + +---@param build table +---@param text string +---@return boolean ok, table|string resultOrErr +function M.ApplyWarrant(build, text) + local parsed, errMsg = M.Parse(text, build.skillsTab) + if not parsed then + return false, errMsg + end + + local itemsTab = build.itemsTab + local skillsTab = build.skillsTab + local partyTab = build.partyTab + + local processedSkills = {} + for _, group in ipairs(parsed.skillGroups) do + if skillsTab then + skillsTab:ProcessSocketGroup(group) + end + t_insert(processedSkills, group) + end + + if partyTab and partyTab.UpsertMercenary then + partyTab:UpsertMercenary({ + name = parsed.name, + build = parsed.build, + type = parsed.type, + level = parsed.level, + skills = processedSkills, + items = {}, + }) + if itemsTab then itemsTab:AddUndoState() end + if skillsTab then skillsTab:AddUndoState() end + else + if itemsTab and itemsTab.activeItemSet then + itemsTab.activeItemSet.mercenaryName = parsed.name + itemsTab.activeItemSet.mercenaryBuild = parsed.build + itemsTab.activeItemSet.mercenaryLevel = parsed.level + if parsed.type then + itemsTab.activeItemSet.mercenaryType = parsed.type + end + itemsTab:AddUndoState() + end + if skillsTab and skillsTab.mercenarySocketGroupList then + wipeTable(skillsTab.mercenarySocketGroupList) + for _, group in ipairs(processedSkills) do + t_insert(skillsTab.mercenarySocketGroupList, group) + end + skillsTab:AddUndoState() + end + end + + build.buildFlag = true + return true, parsed +end + +return M