-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathLoot.lua
More file actions
192 lines (168 loc) · 5.02 KB
/
Loot.lua
File metadata and controls
192 lines (168 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
local _, ns = ...
local Parrot = ns.addon
if not Parrot then return end
local L = LibStub("AceLocale-3.0"):GetLocale("Parrot")
local mod = Parrot:NewModule("LootData")
local newDict = Parrot.newDict
local Deformat = Parrot.Deformat
local LOOT_ITEM_SELF = _G.LOOT_ITEM_SELF
local LOOT_ITEM_SELF_MULTIPLE = _G.LOOT_ITEM_SELF_MULTIPLE
local LOOT_ITEM_PUSHED_SELF = _G.LOOT_ITEM_PUSHED_SELF
local LOOT_ITEM_PUSHED_SELF_MULTIPLE = _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE
local LOOT_ITEM_CREATED_SELF = _G.LOOT_ITEM_CREATED_SELF
local LOOT_ITEM_CREATED_SELF_MULTIPLE = _G.LOOT_ITEM_CREATED_SELF_MULTIPLE
local LOOT_ITEM_REFUND = _G.LOOT_ITEM_REFUND
local LOOT_ITEM_REFUND_MULTIPLE = _G.LOOT_ITEM_REFUND_MULTIPLE
local ITEM_QUALITY_COLORS = _G.ITEM_QUALITY_COLORS
local db
function mod:OnEnable()
db = Parrot.db:GetNamespace("CombatEvents").profile
end
function mod:OnProfileChanged()
db = Parrot.db:GetNamespace("CombatEvents").profile
end
local function parrotShowItemLooted(quality, itemClassID)
if db.lootQuestItem and itemClassID == 12 then
return true
end
if quality == 0 and db.lootQualityPoor then
return true
end
if quality == 1 and db.lootQualityCommon then
return true
end
if quality == 2 and db.lootQualityUncommon then
return true
end
if quality == 3 and db.lootQualityRare then
return true
end
if quality >= 4 and db.lootQualityEpic then
return true
end
return false
end
local function parse_CHAT_MSG_LOOT(chatmsg)
-- check for multiple
local itemLink, amount = Deformat(chatmsg, LOOT_ITEM_SELF_MULTIPLE)
if not itemLink then
itemLink, amount = Deformat(chatmsg, LOOT_ITEM_PUSHED_SELF_MULTIPLE)
end
if not itemLink then
itemLink, amount = Deformat(chatmsg, LOOT_ITEM_CREATED_SELF_MULTIPLE)
end
if not itemLink then
itemLink, amount = Deformat(chatmsg, LOOT_ITEM_REFUND_MULTIPLE)
end
-- check for single
if not itemLink then
itemLink = Deformat(chatmsg, LOOT_ITEM_SELF)
end
if not itemLink then
itemLink = Deformat(chatmsg, LOOT_ITEM_PUSHED_SELF)
end
if not itemLink then
itemLink = Deformat(chatmsg, LOOT_ITEM_CREATED_SELF)
end
if not itemLink then
itemLink = Deformat(chatmsg, LOOT_ITEM_REFUND)
end
-- if something has been looted
if itemLink then
if not amount then
amount = 1
end
local name, _, quality, _, _, itemType, _, _, _, texture, _, itemClassID = GetItemInfo(itemLink)
if parrotShowItemLooted(quality, itemClassID) then
local color = ITEM_QUALITY_COLORS[quality]
if color then
name = ("%s%s|r"):format(color.hex, name)
end
return newDict(
"name", name,
"amount", amount,
"total", GetItemCount(itemLink) + amount,
"icon", texture
)
end
end
end
Parrot:RegisterCombatEvent{
category = "Notification",
subCategory = L["Loot"],
name = "Loot items",
localName = L["Loot items"],
defaultTag = L["Loot [Name] +[Amount]([Total])"],
tagTranslations = {
Name = "name",
Amount = "amount",
Total = "total",
Icon = "icon",
},
tagTranslationsHelp = {
Name = L["The name of the item."],
Amount = L["The amount of items looted."],
Total = L["The total amount of items in inventory."],
},
events = {
CHAT_MSG_LOOT = { parse = parse_CHAT_MSG_LOOT, },
},
color = "ffffff", -- white
}
local moneyStrings = {
_G.LOOT_MONEY_SPLIT,
_G.LOOT_MONEY_SPLIT_GUILD,
_G.YOU_LOOT_MONEY,
_G.YOU_LOOT_MONEY_GUILD,
_G.LOOT_MONEY_REFUND,
}
local GOLD_AMOUNT_inv = _G.GOLD_AMOUNT:gsub("%%d", "(%1+)")
local SILVER_AMOUNT_inv = _G.SILVER_AMOUNT:gsub("%%d", "(%1+)")
local COPPER_AMOUNT_inv = _G.COPPER_AMOUNT:gsub("%%d", "(%1+)")
local GOLD_AMOUNT_SYMBOL = _G.GOLD_AMOUNT_SYMBOL
local SILVER_AMOUNT_SYMBOL = _G.SILVER_AMOUNT_SYMBOL
local COPPER_AMOUNT_SYMBOL = _G.COPPER_AMOUNT_SYMBOL
local function parse_CHAT_MSG_MONEY(chatmsg)
for _, moneyString in ipairs(moneyStrings) do
local amount = Deformat(chatmsg, moneyString)
if amount then
local gold = chatmsg:match(GOLD_AMOUNT_inv) or 0
local silver = chatmsg:match(SILVER_AMOUNT_inv) or 0
local copper = chatmsg:match(COPPER_AMOUNT_inv) or 0
return newDict(
"amount", 10000 * gold + 100 * silver + copper
)
end
end
end
Parrot:RegisterCombatEvent{
category = "Notification",
subCategory = L["Loot"],
name = "Loot money",
localName = L["Loot money"],
defaultTag = L["Loot +[Amount]"],
tagTranslations = {
Amount = function(info)
local value = info.amount
if value >= 10000 then
local gold = value / 10000
local silver = (value / 100) % 100
local copper = value % 100
return ("%d|cffffd700%s|r%d|cffc7c7cf%s|r%d|cffeda55f%s|r"):format(gold, GOLD_AMOUNT_SYMBOL, silver, SILVER_AMOUNT_SYMBOL, copper, COPPER_AMOUNT_SYMBOL)
elseif value >= 100 then
local silver = value / 100
local copper = value % 100
return ("%d|cffc7c7cf%s|r%d|cffeda55f%s|r"):format(silver, SILVER_AMOUNT_SYMBOL, copper, COPPER_AMOUNT_SYMBOL)
else
return ("%d|cffeda55f%s|r"):format(value, COPPER_AMOUNT_SYMBOL)
end
end,
},
tagTranslationsHelp = {
Amount = L["The amount of gold looted."],
},
events = {
CHAT_MSG_MONEY = { parse = parse_CHAT_MSG_MONEY, },
},
color = "ffffff", -- white
}