Skip to content

Commit b41d152

Browse files
author
Freddie
committed
Rewrite reputation handling
1 parent 4551bad commit b41d152

4 files changed

Lines changed: 135 additions & 133 deletions

File tree

Core.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function Addon:Cleanup()
115115
charData.illusions = nil
116116
charData.mythicPlus = nil
117117
charData.name = nil
118+
charData.reputations = nil
118119
charData.transmog = nil
119120
charData.transmogSquish = nil
120121
charData.weeklyQuests = nil

DB/Reputations.lua

Lines changed: 0 additions & 99 deletions
This file was deleted.

Modules/Reputations.lua

Lines changed: 134 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,152 @@ local CGI_GetFriendshipReputation = C_GossipInfo.GetFriendshipReputation
88
local CMF_GetMajorFactionRenownInfo = C_MajorFactions.GetMajorFactionRenownInfo
99
local CR_GetFactionDataByID = C_Reputation.GetFactionDataByID
1010
local CR_GetFactionParagonInfo = C_Reputation.GetFactionParagonInfo
11+
local CR_IsAccountWideReputation = C_Reputation.IsAccountWideReputation
1112
local CR_IsFactionParagon = C_Reputation.IsFactionParagon
13+
local CR_IsMajorFaction = C_Reputation.IsMajorFaction
14+
15+
local MAX_FACTION_ID = 3000
16+
local INIT_CHUNK_SIZE = 100
17+
local SCAN_CHUNK_SIZE = 50
18+
19+
local TYPE_REPUTATION = 1
20+
local TYPE_MAJOR = 2
21+
local TYPE_FRIEND = 3
1222

1323
function Module:OnEnable()
14-
self:RegisterBucketEvent('UPDATE_FACTION', 1, 'UpdateReputations')
24+
Addon.charData.paragons = Addon.charData.paragons or {}
25+
Addon.charData.reputationsV2 = Addon.charData.reputationsV2 or {}
26+
WWTCSaved.paragons = WWTCSaved.paragons or {}
27+
WWTCSaved.reputations = WWTCSaved.reputations or {}
28+
29+
self.factions = {}
30+
self.factionIds = {}
31+
self.updatedFactions = false
32+
33+
self:RegisterBucketEvent('UPDATE_FACTION', 2, 'UpdateReputations')
1534
end
1635

1736
function Module:OnEnteringWorld()
18-
self:UpdateReputations()
37+
self:GetFactionData()
1938
end
2039

21-
function Module:UpdateReputations()
22-
local reputations = {}
23-
local paragons = {}
24-
25-
for _, factionID in ipairs(self.db.reputations) do
26-
local renownData = CMF_GetMajorFactionRenownInfo(factionID)
27-
if renownData ~= nil then
28-
reputations[factionID] = (renownData.renownLevel * renownData.renownLevelThreshold) + renownData.renownReputationEarned
29-
else
30-
local factionData = CR_GetFactionDataByID(factionID)
31-
if factionData ~= nil then
32-
reputations[factionID] = factionData.currentStanding
33-
end
34-
end
40+
function Module:GetFactionData()
41+
if self.updatedFactions == true then
42+
Module:UpdateReputations()
43+
return
3544
end
3645

37-
for _, friendshipID in ipairs(self.db.friendships) do
38-
local friendRep = CGI_GetFriendshipReputation(friendshipID)
39-
reputations[friendshipID] = friendRep.standing
40-
end
46+
local workload = {}
47+
48+
for chunkIndex = 1, MAX_FACTION_ID, INIT_CHUNK_SIZE do
49+
tinsert(workload, function()
50+
-- local startTime = debugprofilestop()
51+
for factionID = chunkIndex, chunkIndex + INIT_CHUNK_SIZE - 1 do
52+
local factionType = nil
53+
local isAccountWide = CR_IsAccountWideReputation(factionID)
54+
local isParagon = CR_IsFactionParagon(factionID)
55+
56+
if CR_IsMajorFaction(factionID) then
57+
factionType = TYPE_MAJOR
58+
else
59+
local friendshipInfo = CGI_GetFriendshipReputation(factionID)
60+
if friendshipInfo ~= nil and friendshipInfo.maxRep > 0 then
61+
factionType = TYPE_FRIEND
62+
else
63+
local reputationInfo = CR_GetFactionDataByID(factionID)
64+
if reputationInfo ~= nil then
65+
factionType = TYPE_REPUTATION
66+
end
67+
end
68+
end
4169

42-
for i, factionID in ipairs(self.db.paragon) do
43-
if CR_IsFactionParagon(factionID) then
44-
local currentValue, threshold, _, hasRewardPending = CR_GetFactionParagonInfo(factionID)
45-
-- value:max:hasReward
46-
paragons[factionID] = table.concat({
47-
currentValue or 0,
48-
threshold or 0,
49-
hasRewardPending and 1 or 0,
50-
}, ':')
51-
end
70+
if factionType ~= nil then
71+
self.factions[factionID] = { factionType, isAccountWide, isParagon }
72+
tinsert(self.factionIds, factionID)
73+
end
74+
end
75+
-- print('factions '..(debugprofilestop() - startTime))
76+
end)
5277
end
5378

54-
Addon.charData.paragons = paragons
55-
Addon.charData.reputations = reputations
79+
Addon:QueueWorkload(workload, function()
80+
self.updatedFactions = true
81+
Module:UpdateReputations()
82+
end)
83+
end
84+
85+
function Module:UpdateReputations()
86+
if self.updatedFactions == false then return end
87+
88+
local now = time()
89+
Addon.charData.scanTimes.reputations = now
90+
WWTCSaved.scanTimes.reputations = now
91+
92+
local accountParagons = WWTCSaved.paragons
93+
local accountReputations = WWTCSaved.reputations
94+
local charParagons = Addon.charData.paragons
95+
local charReputations = Addon.charData.reputationsV2
96+
wipe(accountParagons)
97+
wipe(accountReputations)
98+
wipe(charParagons)
99+
wipe(charReputations)
100+
101+
local workload = {}
102+
103+
for chunkIndex = 1, #self.factionIds, SCAN_CHUNK_SIZE do
104+
tinsert(workload, function()
105+
-- local startTime = debugprofilestop()
106+
for factionIndex = chunkIndex, chunkIndex + SCAN_CHUNK_SIZE - 1 do
107+
local factionID = self.factionIds[factionIndex]
108+
if factionID ~= nil then
109+
local factionType, isAccountWide, isParagon = unpack(self.factions[factionID])
110+
local repValue = -1
111+
112+
if factionType == TYPE_REPUTATION then
113+
local factionInfo = CR_GetFactionDataByID(factionID)
114+
if factionInfo ~= nil then
115+
repValue = factionInfo.currentStanding
116+
end
117+
elseif factionType == TYPE_MAJOR then
118+
local renownInfo = CMF_GetMajorFactionRenownInfo(factionID)
119+
if renownInfo ~= nil then
120+
repValue = (renownInfo.renownLevel * renownInfo.renownLevelThreshold) + renownInfo.renownReputationEarned
121+
end
122+
elseif factionType == TYPE_FRIEND then
123+
local friendshipInfo = CGI_GetFriendshipReputation(factionID)
124+
if friendshipInfo ~= nil then
125+
repValue = friendshipInfo.standing
126+
end
127+
end
128+
129+
if repValue ~= nil and repValue ~= -1 then
130+
local repString = table.concat({ factionID, repValue }, ':')
131+
if isAccountWide then
132+
tinsert(accountReputations, repString)
133+
else
134+
tinsert(charReputations, repString)
135+
end
136+
137+
if isParagon then
138+
local currentValue, threshold, _, hasRewardPending = CR_GetFactionParagonInfo(factionID)
139+
-- value:max:hasReward
140+
local paragonString = table.concat({
141+
currentValue or 0,
142+
threshold or 0,
143+
hasRewardPending and 1 or 0,
144+
}, ':')
145+
if isAccountWide then
146+
accountParagons[factionID] = paragonString
147+
else
148+
charParagons[factionID] = paragonString
149+
end
150+
end
151+
end
152+
end
153+
end
154+
-- print('reputations '..(debugprofilestop() - startTime))
155+
end)
156+
end
56157

57-
Addon.charData.scanTimes.reputations = time()
158+
Addon:QueueWorkload(workload)
58159
end

WoWthing_Collector.toc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ DB\Covenants.lua
5555
DB\Garrisons.lua
5656
DB\ProfessionCooldowns.lua
5757
DB\ProfessionTraits.lua
58-
DB\Reputations.lua
5958
DB\Spells.lua
6059
DB\Transmog.lua
6160
DB\WorldQuests.lua

0 commit comments

Comments
 (0)