Skip to content

Commit

Permalink
Add warband currency support (#5229)
Browse files Browse the repository at this point in the history
Several state values for account wide currencies have been added:
- accountQuantity (sum of all account characters' quantity)
- realAccountQuantity (total account quantity after transferring
everything to your current character and paying the transfer cost)
- realCharacterQuantity (remaining quantity if all this character's
currency was transfered and paid the transfer cost)
- transferPercentage (transfer cost %)
- unitName (comes from currency API)
- unitGUID (comes from currency API)
- mainCharacter (bool value to check for the character you are currently
playing on)
  • Loading branch information
Boneshockx authored Nov 12, 2024
1 parent 8d0642d commit 4722b15
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 38 deletions.
51 changes: 51 additions & 0 deletions WeakAuras/GenericTrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5130,6 +5130,57 @@ Private.GetCurrencyInfoForTrigger = function(trigger)
end
end

Private.ExecEnv.GetCurrencyAccountInfo = function(currencyId)
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId)

-- Gather currency data for account characters
if WeakAuras.IsRetail() and currencyInfo and currencyInfo.isAccountTransferable then
local dataReady = C_CurrencyInfo.IsAccountCharacterCurrencyDataReady()
local accountCurrencyData = dataReady and C_CurrencyInfo.FetchCurrencyDataFromAccountCharacters(currencyId)

if dataReady and accountCurrencyData then
currencyInfo.accountQuantity = currencyInfo.quantity
currencyInfo.realAccountQuantity = currencyInfo.quantity
if currencyInfo.transferPercentage then
currencyInfo.realCharacterQuantity = math.floor(currencyInfo.quantity * (currencyInfo.transferPercentage / 100))
end

currencyInfo.accountCurrencyData = accountCurrencyData
for _, currencyData in ipairs(currencyInfo.accountCurrencyData) do
if currencyData.quantity then
if currencyInfo.transferPercentage then
currencyData.realCharacterQuantity = math.floor(currencyData.quantity * (currencyInfo.transferPercentage / 100))
end
currencyInfo.realAccountQuantity = currencyInfo.realAccountQuantity + (currencyData.realCharacterQuantity or currencyData.quantity)
currencyInfo.accountQuantity = currencyInfo.accountQuantity + currencyData.quantity
end
end
else
C_CurrencyInfo.RequestCurrencyDataForAccountCharacters()
end
end

-- WORKAROUND https://github.com/WeakAuras/WeakAuras2/issues/5106
if currencyInfo and WeakAuras.IsCataClassic() then
if currencyInfo.quantityEarnedThisWeek then
currencyInfo.quantityEarnedThisWeek = currencyInfo.quantityEarnedThisWeek / 100
end
end

if currencyInfo then
currencyInfo.capped = currencyInfo.maxQuantity and currencyInfo.maxQuantity > 0 and currencyInfo.quantity >= currencyInfo.maxQuantity
currencyInfo.seasonCapped = currencyInfo.maxQuantity and currencyInfo.maxQuantity > 0 and currencyInfo.useTotalEarnedForMaxQty and currencyInfo.totalEarned >= currencyInfo.maxQuantity
currencyInfo.weeklyCapped = currencyInfo.maxWeeklyQuantity and currencyInfo.maxWeeklyQuantity > 0 and currencyInfo.quantityEarnedThisWeek >= currencyInfo.maxWeeklyQuantity
end

if not currencyInfo then
currencyInfo = C_CurrencyInfo.GetCurrencyInfo(1) --Currency Token Test Token 4
currencyInfo.iconFileID = "Interface\\Icons\\INV_Misc_QuestionMark" --We don't want the user to think their input was valid
end

return currencyInfo
end


local types = {}
tinsert(types, "custom")
Expand Down
Loading

0 comments on commit 4722b15

Please sign in to comment.