Quantcast

First BFA Port of TomTom_Corpse.lua: Convert to new APIs.

Ludovicus [06-20-18 - 21:58]
First BFA Port of TomTom_Corpse.lua: Convert to new APIs.
Filename
TomTom_Corpse.lua
diff --git a/TomTom_Corpse.lua b/TomTom_Corpse.lua
index b811acf..1f33b91 100755
--- a/TomTom_Corpse.lua
+++ b/TomTom_Corpse.lua
@@ -12,8 +12,9 @@ eventFrame:RegisterEvent("PLAYER_DEAD")
 eventFrame:RegisterEvent("PLAYER_UNGHOST")
 eventFrame:Hide()

--- Local variables to store map, floor, x, y and uid or corpse waypoint
-local m,f,x,y,uid
+
+-- Local variables to store map, x, y and uid or corpse waypoint
+local m,x,y,uid

 local function StartCorpseSearch()
     if not IsInInstance() then
@@ -24,39 +25,40 @@ end
 local function ClearCorpseArrow()
     if uid then
         TomTom:RemoveWaypoint(uid)
-        m,f,x,y,uid = nil, nil, nil, nil, nil
+        m,x,y,uid = nil, nil, nil, nil, nil
     end
 end

 local function GetCorpseLocation()
     -- If the player isn't dead or a ghost, drop out
     if not UnitIsDeadOrGhost("player") then
-        if m or f or x or y then
+        if m or x or y then
             ClearCorpseArrow()
         end
     end

     -- Cache the result so we don't scan the maps multiple times
-    if m and f and x and y then
-        return m, f, x, y
+    if m and x and y then
+        return m, x, y
     end

     --  See if the player corpse is on the current map
-    local om = GetCurrentMapAreaID()
-    local of = GetCurrentMapDungeonLevel()
-
-    local cx, cy = GetCorpseMapPosition()
+    local om = C_Map.GetBestMapForUnit("player")
+    if not om then return nil; end
+    local corpse = C_DeathInfo.GetCorpseMapPosition(om)
+    if not corpse then return nil; end
+    local cx, cy = corpse:GetXY()
     if cx ~= 0 and cy ~= 0 then
         m = om
-        f = of
         x = cx
         y = cy
     end
+    return m, x, y
 end

 local function SetCorpseArrow()
-    if m and f and x and y then
-        uid = TomTom:AddMFWaypoint(m, f, x, y, {
+    if m and x and y then
+        uid = TomTom:AddWaypoint(m, x, y, {
             title = L["My Corpse"],
             persistent = false,
 			corpse = true,
@@ -99,12 +101,9 @@ eventFrame:SetScript("OnEvent", function(self, event, arg1, ...)
             ClearCorpseArrow()
         end
     elseif event == "PLAYER_DEAD" then
-        -- Cheat a bit and avoid the map flipping
-        SetMapToCurrentZone()
-        m = GetCurrentMapAreaID()
-        f = GetCurrentMapDungeonLevel()
+        m = C_Map.GetBestMapForUnit("player")
         if not IsInInstance() then
-            x,y = GetPlayerMapPosition("player")
+            x,y = C_Map.GetPlayerMapPosition(m, "player"):GetXY()
         end
         StartCorpseSearch()
     elseif event == "PLAYER_UNGHOST" then