View Single Post
09-25-23, 12:09 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Okay, this is bizzare; I was wrong: it isn't WoD zones, it is the final check to assign world zone data. No matter if I use:
Code:
if type(watchedFactionID) ~= "number" then ...
Or if I use
Code:
if not watchedFactionID then ...
Both of these fail, or at least are somehow assigning a value of 0 or nil to watchedFactionID. I have no clue why either of those if statements are behaving like that.

Here is my updated function SwitchedZones() with the faulty if statement on line 82 below.
Lua Code:
  1. -- Player switched zones, subzones, or instances, set watched faction
  2. function RepByZone:SwitchedZones(event)
  3.     if not db.enabled then return end -- Exit if the addon is disabled
  4.  
  5.     -- Possible zoning issues, exit out unless we have valid map data
  6.     local uiMapID = C_Map.GetBestMapForUnit("player")
  7.     if not uiMapID then return end
  8.  
  9.     if isOnTaxi then
  10.         if not db.watchOnTaxi then
  11.             -- On taxi but don't switch
  12.             return
  13.         end
  14.     end
  15.  
  16.     -- Some data may not be available because of the specialty zone functions, get something until a full data update refreshes things
  17.     instancesAndFactions = instancesAndFactions or self:InstancesAndFactionList()
  18.     zonesAndFactions = zonesAndFactions or self:ZoneAndFactionList()
  19.     subZonesAndFactions = subZonesAndFactions or self:SubZonesAndFactionsList()
  20.  
  21.     if event == "BODYGUARD_UPDATED" then
  22.         -- This is a custom event
  23.         bodyguardRepID = self:GetActiveBodyguardRepID()
  24.     else
  25.         -- bodyguardRepID might still be nil if there is no bodyguard
  26.         bodyguardRepID = bodyguardRepID or self:GetActiveBodyguardRepID()
  27.     end
  28.  
  29.     -- Set up variables
  30.     local _, watchedFactionID, factionName, isWatched
  31.     local hasDungeonTabard = false
  32.     local inInstance, instanceType = IsInInstance()
  33.     local whichInstanceID = inInstance and select(8, GetInstanceInfo())
  34.     local parentMapID = C_Map.GetMapInfo(uiMapID).parentMapID
  35.     local subZone = GetMinimapZoneText()
  36.     local isWoDZone = self.WoDFollowerZones[uiMapID] or (self.WoDFollowerZones[uiMapID] == nil and self.WoDFollowerZones[parentMapID])
  37.  
  38.     -- Apply instance reputations. Garrisons return false for inInstance and "party" for instanceType, which is good, we can filter them out
  39.     if inInstance and instanceType == "party" then
  40.         hasDungeonTabard = false
  41.         -- Certain dungeons do not benefit from tabards
  42.         if self.tabardExemptDungeons[whichInstanceID] then
  43.             return
  44.         end
  45.         -- Process faction tabards
  46.         if db.useFactionTabards then
  47.             if tabardID then
  48.                 watchedFactionID = tabardID
  49.                 hasDungeonTabard = true
  50.             end
  51.         else
  52.             -- We aren't watching faction tabards
  53.             hasDungeonTabard = false
  54.         end
  55.     else
  56.         -- We aren't in a party
  57.         hasDungeonTabard = false
  58.     end
  59.  
  60.     -- We aren't in an instance that supports tabards or we aren't watching tabards in the dungeon
  61.     if inInstance and not hasDungeonTabard then
  62.         watchedFactionID = instancesAndFactions[whichInstanceID]
  63.     end
  64.  
  65.     -- Override in WoD zones only if a bodyguard exists
  66.     if isWoDZone and bodyguardRepID then
  67.         watchedFactionID = bodyguardRepID
  68.     end
  69.  
  70.     -- Process subzones
  71.     if db.watchSubZones then
  72.         -- Don't loop through subzones if the player is watching a bodyguard rep
  73.         if isWoDZone and bodyguardRepID then return end
  74.  
  75.         -- Battlegrounds and warfronts are the only instances with subzones
  76.         if inInstance and instanceType ~= "pvp" then return end
  77.  
  78.         -- Get our subzone data
  79.         if subZone then
  80.             watchedFactionID = CitySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
  81.         end
  82.     elseif not watchedFactionID then
  83.         if (isWoDZone and bodyguardRepID) or inInstance then return end
  84.         -- Get world zone data or the character's default watched faction
  85.         watchedFactionID = zonesAndFactions[uiMapID] or db.defaultRepID
  86.  
  87.         self:Print("DEBUG: watchedFactionID:", watchedFactionID)
  88.     end
  89.  
  90.     -- WoW has a delay whenever the player changes instance/zone/subzone/tabard; factionName and isWatched aren't available immediately, so delay the lookup, then set the watched faction on the bar
  91.     C_Timer.After(db.delayGetFactionInfoByID, function()
  92.         if type(watchedFactionID) == "number" then
  93.             -- We have a factionID for the instance/zone/subzone/tabard or we don't have a factionID and db.defaultRepID is a number
  94.             factionName, _, _, _, _, _, _, _, _, _, _, isWatched = GetFactionInfoByID(watchedFactionID)
  95.             if factionName and not isWatched then
  96.                 C_Reputation.SetWatchedFaction(watchedFactionID)
  97.                 if db.verbose then
  98.                     self:Print(L["Now watching %s"]:format(factionName))
  99.                 end
  100.             end
  101.         else
  102.             -- watchedFactionID is not valid because there is no factionID for the instance/zone/subzone/tabard or db.defaultRepID is not a number
  103.             C_Reputation.SetWatchedFaction(0)
  104.         end
  105.     end)
  106. end
  Reply With Quote