@@ -8,51 +8,152 @@ local CGI_GetFriendshipReputation = C_GossipInfo.GetFriendshipReputation
88local CMF_GetMajorFactionRenownInfo = C_MajorFactions .GetMajorFactionRenownInfo
99local CR_GetFactionDataByID = C_Reputation .GetFactionDataByID
1010local CR_GetFactionParagonInfo = C_Reputation .GetFactionParagonInfo
11+ local CR_IsAccountWideReputation = C_Reputation .IsAccountWideReputation
1112local 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
1323function 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' )
1534end
1635
1736function Module :OnEnteringWorld ()
18- self :UpdateReputations ()
37+ self :GetFactionData ()
1938end
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 )
58159end
0 commit comments