Skip to content

Commit

Permalink
Currency Trigger: Add Player Money
Browse files Browse the repository at this point in the history
  • Loading branch information
Boneshockx committed Dec 17, 2024
1 parent e9e7e5a commit 7a86591
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 2 deletions.
117 changes: 116 additions & 1 deletion WeakAuras/Prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11279,6 +11279,7 @@ Private.event_prototypes = {
local events = {
"CHAT_MSG_CURRENCY",
"CURRENCY_DISPLAY_UPDATE",
"PLAYER_MONEY",
}
if WeakAuras.IsRetail() then
tinsert(events, "ACCOUNT_CHARACTER_CURRENCY_DATA_RECEIVED")
Expand All @@ -11290,6 +11291,55 @@ Private.event_prototypes = {
force_events = "WA_DELAYED_PLAYER_ENTERING_WORLD",
name = WeakAuras.newFeatureString..L["Currency"],
triggerFunction = function(trigger)
if trigger.currencyId == "money" then
local moneyChecks = {}
local function createMoneyCheck(property, operator, value, use)
if not use then return nil end
return([[
if not (%s %s %s) then
active = false
end
]]):format(property, operator or "<", tonumber(value) or 0)
end

table.insert(moneyChecks, createMoneyCheck("gold", trigger.gold_operator, trigger.gold, trigger.use_gold))
table.insert(moneyChecks, createMoneyCheck("silver", trigger.silver_operator, trigger.silver, trigger.use_silver))
table.insert(moneyChecks, createMoneyCheck("copper", trigger.copper_operator, trigger.copper, trigger.use_copper))

local moneyCheckString = table.concat(moneyChecks, "\n")

local ret = [=[return
function(states)
local money = GetMoney()
local gold = floor(money / 1e4)
local silver = floor(money / 100 %% 100)
local copper = money %% 100
local active = true
-- Insert Gold/Silver/Copper checks
%s
states[""] = states[""] or {}
local state = states[""]
state.name = MONEY
state.icon = C_CurrencyInfo.GetCoinIcon(money)
state.progressType = "static"
state.show = active
state.changed = state.value ~= money
state.value = money
state.money = money
state.gold = gold
state.silver = silver
state.copper = copper
return state.changed
end
]=]

return ret:format(moneyCheckString)
end

local quantityChecks, tristateChecks, cloneChecks = {}, {}, {}

local function createQuantityCheck(property, operator, value, primary, use)
Expand Down Expand Up @@ -11499,6 +11549,9 @@ Private.event_prototypes = {
display = L["Quantity"],
store = true,
conditionType = "number",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "total",
Expand All @@ -11513,6 +11566,47 @@ Private.event_prototypes = {
hidden = true,
test = "true",
},
{
name = "money",
type = "number",
display = L["Player Money"],
store = true,
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId == "money"
end
},
{
name = "gold",
type = "number",
display = Private.coin_icons.gold .. L["Gold"],
store = true,
conditionType = "number",
enable = function(trigger)
return trigger.currencyId == "money"
end
},
{
name = "silver",
type = "number",
display = Private.coin_icons.silver .. L["Silver"],
store = true,
conditionType = "number",
enable = function(trigger)
return trigger.currencyId == "money"
end
},
{
name = "copper",
type = "number",
display = Private.coin_icons.copper .. L["Copper"],
store = true,
conditionType = "number",
enable = function(trigger)
return trigger.currencyId == "money"
end
},
{
name = "realCharacterQuantity",
type = "number",
Expand Down Expand Up @@ -11622,21 +11716,30 @@ Private.event_prototypes = {
store = true,
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "quality",
type = "number",
display = L["Quality Id"],
hidden = true,
test = "true",
store = true
store = true,
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "discovered",
type = "tristate",
display = L["Discovered"],
store = true,
conditionType = "bool",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "transferPercentage",
Expand All @@ -11646,6 +11749,9 @@ Private.event_prototypes = {
conditionType = "number",
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "characterName",
Expand All @@ -11654,6 +11760,9 @@ Private.event_prototypes = {
store = true,
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "characterGUID",
Expand All @@ -11662,6 +11771,9 @@ Private.event_prototypes = {
store = true,
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "mainCharacter",
Expand All @@ -11671,6 +11783,9 @@ Private.event_prototypes = {
conditionType = "bool",
hidden = true,
test = "true",
enable = function(trigger)
return trigger.currencyId ~= "money"
end
},
{
name = "clones",
Expand Down
5 changes: 4 additions & 1 deletion WeakAuras/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,10 @@ local function InitializeCurrencies()
end

Private.discovered_currencies["member"] = "|Tinterface\\common\\ui-searchbox-icon:0:0:0:-2|t"..L["Specific Currency"];
Private.discovered_currencies_sorted["member"] = -1;
Private.discovered_currencies_sorted["member"] = -2;

Private.discovered_currencies["money"] = "|Tinterface/moneyframe/ui-goldicon:0:0:0:-2|t"..L["Player Money"];
Private.discovered_currencies_sorted["money"] = -1;
end

---@type function
Expand Down

0 comments on commit 7a86591

Please sign in to comment.