From b379ab1ca368fddb949fa8a821601feac79a4cb8 Mon Sep 17 00:00:00 2001 From: Aldric Ducreux Date: Thu, 18 Jul 2024 00:12:14 +0200 Subject: [PATCH] handle portal coord before tp --- Core.lua | 1 + Event.lua | 42 +++++++++++++++++++++++++++++++++++++++++- helper/Utils.lua | 13 +++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Core.lua b/Core.lua index a5fea25..bdd87e4 100644 --- a/Core.lua +++ b/Core.lua @@ -34,6 +34,7 @@ function AprRC:OnInitialize() AprRCData.ExtraLineTexts = AprRCData.ExtraLineTexts or {} AprRCData.QuestLookup = AprRCData.QuestLookup or {} AprRCData.TaxiLookup = AprRCData.TaxiLookup or {} + AprRCData.BeforePortal = AprRCData.BeforePortal or {} -- Init module AprRC.settings:InitializeBlizOptions() diff --git a/Event.lua b/Event.lua index 156913d..2d101af 100644 --- a/Event.lua +++ b/Event.lua @@ -29,7 +29,8 @@ local events = { buy = "MERCHANT_SHOW", qpart = "QUEST_WATCH_UPDATE", loot = "CHAT_MSG_LOOT", - target = "PLAYER_TARGET_CHANGED" + target = "PLAYER_TARGET_CHANGED", + portal = { "PLAYER_LEAVING_WORLD", "PLAYER_ENTERING_WORLD" } -- warMode = "WAR_MODE_STATUS_UPDATE", -- vehicle = { "UNIT_ENTERING_VEHICLE", "UNIT_EXITING_VEHICLE" }, } @@ -532,6 +533,45 @@ function AprRC.event.functions.pet(event, ...) AprRC.record:RefreshFrameAnchor() end +function AprRC.event.functions.portal(event, ...) + if event == "PLAYER_LEAVING_WORLD" then + local step = {} + AprRC:SetStepCoord(step) + AprRCData.BeforePortal.lastStep = AprRC:GetLastStep() + AprRCData.BeforePortal.lastCoord = step + else + local isInitialLogin, isReloadingUi = ... + -- wait 2s si last step = saved last step alors waypoints + text prendre portal -- not skippable waypoints (new option) + -- sinon check IsCurrentStepFarAway si trop loin alors override coord + text prendre portal + -- pour les tp sans portail ni cast => LOSS_OF_CONTROL_ADDED into Zone changed indoors, waypoint update, area pois updated + -- pour les tp avec spell => spell list teleport (sans les spell de class) + unit spellcast-succeeded + + if not isInitialLogin and not isReloadingUi then + C_Timer.After(3, function() + local last = AprRC:GetLastStep() + if AprRC:DeepCompare(AprRCData.BeforePortal.lastStep, last) then + local step = { + Waypoint = AprRC:FindClosestIncompleteQuest(), + ExtraLineText = "USE_PORTAL", + Coord = AprRCData.BeforePortal.lastStep.Coord + } + AprRC:NewStep(step) + print("|cff00bfffWaypoint|r Added") + elseif AprRC:IsCurrentStepFarAway() then + local last = AprRC:GetLastStep() + last.Coord = AprRCData.BeforePortal.lastStep.Coord + last.ExtraLineText = "USE_PORTAL" + AprRCData.BeforePortal = {} + print("|cff00bfffLast Step coord updated|r Added") + end + end) + end + if isInitialLogin then + AprRCData.BeforePortal = {} + end + end +end + --------------------- -- V2 --------------------- diff --git a/helper/Utils.lua b/helper/Utils.lua index b045fc6..210755d 100644 --- a/helper/Utils.lua +++ b/helper/Utils.lua @@ -40,6 +40,19 @@ function AprRC:Contains(list, x) return false end +function AprRC:DeepCompare(t1, t2) + if t1 == t2 then return true end + if type(t1) ~= "table" or type(t2) ~= "table" then return false end + for k1, v1 in pairs(t1) do + local v2 = t2[k1] + if v2 == nil or not deepCompare(v1, v2) then return false end + end + for k2, v2 in pairs(t2) do + if t1[k2] == nil then return false end + end + return true +end + function AprRC:IsTableEmpty(table) if (table) then return next(table) == nil