Skip to content

Commit

Permalink
Improved auto watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonaza committed Aug 21, 2018
1 parent 7281382 commit 887f9ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.1
* Now auto watch automatically tracks reputation with largest gain when multiple reputations are earned at same time.

## 3.0.0
* Updated for Battle for Azeroth.
* Artifact module now tracks Heart of Azeroth once player receives it.
Expand Down
2 changes: 1 addition & 1 deletion Experiencer.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Experiencer
## Notes: Simple but advanced tracking progress bar addon
## Author: Sonaza
## Version: 3.0.0
## Version: 3.0.1
## OptionalDeps: Ace3
## SavedVariables: ExperiencerDB, ExperiencerDB_module_experience, ExperiencerDB_module_reputation, ExperiencerDB_module_artifact, ExperiencerDB_module_honor, ExperiencerDB_module_conquest

Expand Down
46 changes: 38 additions & 8 deletions modules/reputation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ function module:Initialize()
amount = 0;
};
end

module.AutoWatchRecent = {};
module.AutoWatchRecentTimeout = 0;
end

function module:IsDisabled()
return false;
end

function module:Update(elapsed)

end

function module:GetSortedRecentList()
local sortedList = {};
for name, data in pairs(module.recentReputations) do
Expand Down Expand Up @@ -666,15 +665,45 @@ function module:CHAT_MSG_COMBAT_FACTION_CHANGE(event, message, ...)

if(self.db.global.AutoWatch.Enabled) then
local name = GetWatchedFactionInfo();
if(name ~= reputation) then
module:UpdateAutoWatch(reputation, isGuild);
if(not self.db.global.AutoWatch.IgnoreGuild or not isGuild) then
module.AutoWatchUpdate = true;
module.AutoWatchRecentTimeout = 0.25;

if(not module.AutoWatchRecent[reputation]) then
module.AutoWatchRecent[reputation] = 0;
end
module.AutoWatchRecent[reputation] = module.AutoWatchRecent[reputation] + amount;
end
end
end

function module:UpdateAutoWatch(reputation, isGuild)
if(self.db.global.AutoWatch.IgnoreGuild and isGuild) then return end
function module:Update(elapsed)
if (module.AutoWatchUpdate) then
if (module.AutoWatchRecentTimeout > 0.0) then
module.AutoWatchRecentTimeout = module.AutoWatchRecentTimeout - elapsed;
end

if (module.AutoWatchRecentTimeout <= 0.0) then
local selectedFaction = nil;
local largestGain = 0;
for faction, gain in pairs(module.AutoWatchRecent) do
if (gain > largestGain) then
selectedFaction = faction;
largestGain = gain;
end
end
if (selectedFaction) then
module:UpdateAutoWatch(selectedFaction);
end

module.AutoWatchRecentTimeout = 0;
module.AutoWatchUpdate = false;
wipe(module.AutoWatchRecent);
end
end
end

function module:UpdateAutoWatch(reputation)
local factionListIndex, factionID = module:GetReputationID(reputation);
if(not factionListIndex) then return end

Expand All @@ -683,3 +712,4 @@ function module:UpdateAutoWatch(reputation, isGuild)

SetWatchedFactionIndex(factionListIndex);
end

0 comments on commit 887f9ad

Please sign in to comment.