- Statt Blizzards durchschnittlicher Gegenstandsstufe zeigt der Rahmen jetzt den GearScore, berechnet wie im Addon GearScore Forever (GearScoreLite- Formel), samt dessen Farbskala. Der Tooltip zeigt GearScore und Gegenstandsstufe wie dessen Charakteransicht. GearScore Forever muss nicht installiert sein. - Fehlen Gegenstandsdaten noch, wird bei GET_ITEM_INFO_RECEIVED neu gerechnet. - Trenner zwischen den Werten repariert: "||r" zeigte ein sichtbares "r", richtig ist "|||r". - Die Beschriftung "Taschen" im Rahmen entfällt, die Zahl steht allein. - Tests lesen Escape-Sequenzen jetzt wie der Client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
514 lines
18 KiB
Lua
514 lines
18 KiB
Lua
-- Goldbeutel: zeigt Gold, freie Taschenplaetze, Ruestungszustand und
|
||
-- GearScore in einem kleinen, verschiebbaren Rahmen.
|
||
-- Linksziehen verschieben
|
||
-- Rechtsklick sperren / entsperren
|
||
-- Mauszeiger drauf Details zu Taschen, Ruestung, GearScore und Gegenstandsstufe,
|
||
-- Gewinn/Verlust dieser Sitzung + alle Charaktere des Realms
|
||
-- /gold ein-/ausblenden
|
||
-- /gold lock sperren / entsperren
|
||
-- /gold reset Position zurücksetzen
|
||
-- /gold forget <Name> Charakter aus der Liste entfernen
|
||
|
||
local ADDON = ...
|
||
|
||
local GOLD = "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t"
|
||
local SILVER = "|TInterface\\MoneyFrame\\UI-SilverIcon:0:0:2:0|t"
|
||
local COPPER = "|TInterface\\MoneyFrame\\UI-CopperIcon:0:0:2:0|t"
|
||
|
||
local SEP = " |cff666666|||r " -- grauer Strich: "||" ist ein woertliches |, dann "|r"
|
||
local LABEL = "|cffaaaaaa" -- Beschriftungen im Rahmen
|
||
local YELLOW = "|cffffd100"
|
||
local RED = "|cffff3333"
|
||
|
||
-- Rucksack (0) und die vier Taschenplaetze, dahinter ggf. die Reagenzientasche
|
||
local NORMAL_BAGS = NUM_BAG_SLOTS or 4
|
||
local LAST_BAG = math.max(NUM_TOTAL_EQUIPPED_BAG_SLOTS or 0, NORMAL_BAGS)
|
||
local FIRST_SLOT = INVSLOT_FIRST_EQUIPPED or 1
|
||
local LAST_SLOT = INVSLOT_LAST_EQUIPPED or 19
|
||
|
||
local GetNumSlots = C_Container and C_Container.GetContainerNumSlots or GetContainerNumSlots
|
||
local GetFreeSlots = C_Container and C_Container.GetContainerNumFreeSlots or GetContainerNumFreeSlots
|
||
|
||
local db, realm, player, sessionStart
|
||
local frame, text
|
||
|
||
local function say(s)
|
||
print("|cffffd100Goldbeutel:|r " .. s)
|
||
end
|
||
|
||
-- 1234567 -> "1.234.567" (nutzt das Trennzeichen des Clients, falls vorhanden)
|
||
local function thousands(n)
|
||
if BreakUpLargeNumbers then return BreakUpLargeNumbers(n) end
|
||
local s = tostring(n):reverse():gsub("(%d%d%d)", "%1."):reverse()
|
||
return (s:gsub("^%.", ""))
|
||
end
|
||
|
||
local function formatMoney(c)
|
||
c = math.floor(c or 0)
|
||
local g = math.floor(c / 10000)
|
||
local s = math.floor(c / 100) % 100
|
||
local k = c % 100
|
||
if g > 0 then
|
||
return string.format("%s%s %02d%s %02d%s", thousands(g), GOLD, s, SILVER, k, COPPER)
|
||
elseif s > 0 then
|
||
return string.format("%d%s %02d%s", s, SILVER, k, COPPER)
|
||
end
|
||
return string.format("%d%s", k, COPPER)
|
||
end
|
||
|
||
local function paint(s, color)
|
||
if color then return color .. s .. "|r" end
|
||
return s
|
||
end
|
||
|
||
local function pctColor(p)
|
||
if p < 20 then return RED elseif p < 50 then return YELLOW end
|
||
end
|
||
|
||
local function freeColor(n)
|
||
if n == 0 then return RED elseif n <= 5 then return YELLOW end
|
||
end
|
||
|
||
local function classColored(name, class)
|
||
local c = class and RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]
|
||
if c and c.colorStr then
|
||
return "|c" .. c.colorStr .. name .. "|r"
|
||
end
|
||
return name
|
||
end
|
||
|
||
-- string.lower kennt nur A-Z. Fuer Namen wie "Ärger" auch À-Þ (UTF-8 C3 80-9E,
|
||
-- ausser ×) in Kleinbuchstaben umwandeln.
|
||
local function lower(s)
|
||
return (s:lower():gsub("\195([\128-\158])", function(c)
|
||
if c ~= "\151" then return "\195" .. string.char(c:byte() + 32) end
|
||
end))
|
||
end
|
||
|
||
-- Freie und gesamte Plaetze. Spezialtaschen (Koecher, Kraeuter-, Reagenzientasche
|
||
-- usw.) zaehlen getrennt, weil dort nicht alles hineinpasst.
|
||
local function bagSpace()
|
||
local free, total, sFree, sTotal = 0, 0, 0, 0
|
||
for bag = 0, LAST_BAG do
|
||
local n = GetNumSlots(bag) or 0
|
||
if n > 0 then
|
||
local f, family = GetFreeSlots(bag)
|
||
f = f or 0
|
||
if bag <= NORMAL_BAGS and (family or 0) == 0 then
|
||
free, total = free + f, total + n
|
||
else
|
||
sFree, sTotal = sFree + f, sTotal + n
|
||
end
|
||
end
|
||
end
|
||
return free, total, sFree, sTotal
|
||
end
|
||
|
||
-- Zustand des am staerksten beschaedigten Teils (Prozent und Slot) und der
|
||
-- Gesamtzustand in Prozent. nil, wenn nichts mit Haltbarkeit angelegt ist.
|
||
local function durability()
|
||
local low, lowSlot, cur, max
|
||
cur, max = 0, 0
|
||
for slot = FIRST_SLOT, LAST_SLOT do
|
||
local c, m = GetInventoryItemDurability(slot)
|
||
if c and m and m > 0 then
|
||
local p = c / m * 100
|
||
if not low or p < low then low, lowSlot = p, slot end
|
||
cur, max = cur + c, max + m
|
||
end
|
||
end
|
||
if low then return low, lowSlot, cur / max * 100 end
|
||
end
|
||
|
||
-- GearScore genau wie im Addon "GearScore Forever" (Daeler), das die Formel von
|
||
-- GearScoreLite uebernimmt. Das Addon bietet keine Schnittstelle nach aussen,
|
||
-- deshalb ist die Rechnung hier nachgebaut. So stimmt der Wert mit der
|
||
-- Charakteransicht ueberein, und Goldbeutel braucht das Addon nicht.
|
||
-- Die Punkte eines Gegenstands haengen nur von Stufe, Qualitaet und Platz ab.
|
||
local GS_SLOT = {
|
||
INVTYPE_RELIC = 0.3164, INVTYPE_TRINKET = 0.5625, INVTYPE_2HWEAPON = 2.0000,
|
||
INVTYPE_WEAPONMAINHAND = 1.0000, INVTYPE_WEAPONOFFHAND = 1.0000,
|
||
INVTYPE_RANGED = 0.3164, INVTYPE_THROWN = 0.3164, INVTYPE_RANGEDRIGHT = 0.3164,
|
||
INVTYPE_SHIELD = 1.0000, INVTYPE_WEAPON = 1.0000, INVTYPE_HOLDABLE = 1.0000,
|
||
INVTYPE_HEAD = 1.0000, INVTYPE_NECK = 0.5625, INVTYPE_SHOULDER = 0.7500,
|
||
INVTYPE_CHEST = 1.0000, INVTYPE_ROBE = 1.0000, INVTYPE_WAIST = 0.7500,
|
||
INVTYPE_LEGS = 1.0000, INVTYPE_FEET = 0.7500, INVTYPE_WRIST = 0.5625,
|
||
INVTYPE_HAND = 0.7500, INVTYPE_FINGER = 0.5625, INVTYPE_CLOAK = 0.5625,
|
||
INVTYPE_BODY = 0,
|
||
}
|
||
-- [Qualitaet] = { A, B } fuer (Stufe - A) / B
|
||
local GS_HIGH = { [4] = { 91.45, 0.65 }, [3] = { 81.375, 0.8125 }, [2] = { 73, 1 } }
|
||
local GS_LOW = { [4] = { 26, 1.2 }, [3] = { 0.75, 1.8 }, [2] = { 8, 2 }, [1] = { 0, 2.25 } }
|
||
local GS_EPIC60 = { [4] = { 0.25, 1.6275 } } -- Epics unter Stufe 100
|
||
local GS_HUNTER = { [16] = 0.3164, [17] = 0.3164, [18] = 5.3224 } -- Nahkampf wenig, Fernkampf viel
|
||
|
||
-- Farbverlauf je Abschnitt der Skala wie in GearScoreLite: grau, weiss, gruen,
|
||
-- blau, lila, orange. Je Farbkanal r, g, b: { Start, Abschnitt, Steigung, Richtung }
|
||
local GS_COLOR = {
|
||
{ { 0.55, 0, 0.00045, 1 }, { 0.55, 0, 0.00045, 1 }, { 0.55, 0, 0.00045, 1 } },
|
||
{ { 1, 1, 0.00088, -1 }, { 1, 0, 0, 0 }, { 1, 1, 0.001, -1 } },
|
||
{ { 0.12, 2, 0.00012, -1 }, { 1, 2, 0.0005, -1 }, { 0, 2, 0.001, 1 } },
|
||
{ { 0, 3, 0.00069, 1 }, { 0.5, 3, 0.00022, -1 }, { 1, 3, 0.00003, -1 } },
|
||
{ { 0.69, 4, 0.00025, 1 }, { 0.28, 4, 0.00019, 1 }, { 0.97, 4, 0.00096, -1 } },
|
||
{ { 0.94, 5, 0.00006, 1 }, { 0.47, 5, 0.00047, -1 }, { 0, 0, 0, 0 } },
|
||
}
|
||
|
||
local GetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
|
||
local GetDetailedItemLevelInfo = C_Item and C_Item.GetDetailedItemLevelInfo or GetDetailedItemLevelInfo
|
||
|
||
local function requestItem(item)
|
||
if C_Item and C_Item.RequestLoadItemDataByID then pcall(C_Item.RequestLoadItemDataByID, item) end
|
||
end
|
||
|
||
-- Punkte und Stufe eines Gegenstands. nil, solange der Client ihn nicht kennt.
|
||
local function itemScore(link)
|
||
local _, _, rarity, level, _, _, _, _, equipLoc = GetItemInfo(link)
|
||
if not rarity or not level then
|
||
requestItem(link)
|
||
return
|
||
end
|
||
local slotMod = GS_SLOT[equipLoc]
|
||
if not slotMod then return 0, 0 end
|
||
if GetDetailedItemLevelInfo then -- tatsaechliche Stufe bei skalierenden Gegenstaenden
|
||
local ok, l = pcall(GetDetailedItemLevelInfo, link)
|
||
if ok and type(l) == "number" and l > 0 then level = l end
|
||
end
|
||
local scale = 1
|
||
if rarity == 5 or rarity == 6 then -- legendaer, Artefakt
|
||
scale, rarity = 1.3, 4
|
||
elseif rarity == 7 then -- Erbstueck zaehlt wie blau
|
||
rarity = 3
|
||
elseif rarity <= 1 then -- grau, weiss: fast nichts
|
||
scale, rarity = 0.005, 2
|
||
end
|
||
local tbl
|
||
if level < 100 and rarity == 4 then
|
||
tbl = GS_EPIC60
|
||
elseif (level < 168 and rarity == 4) or (level < 148 and rarity == 3)
|
||
or (level < 138 and rarity == 2) or level <= 120 then
|
||
tbl = GS_LOW
|
||
else
|
||
tbl = GS_HIGH
|
||
end
|
||
local f = tbl[rarity] or GS_LOW[rarity]
|
||
if not f then return 0, level end
|
||
local base = (level - f[1]) / f[2] * 1.8618
|
||
return math.max(math.floor(base * slotMod * scale), 0), level
|
||
end
|
||
|
||
-- true, solange Gegenstandsdaten fehlen; dann wird bei GET_ITEM_INFO_RECEIVED
|
||
-- neu gerechnet
|
||
local gsPending = false
|
||
|
||
-- GearScore und durchschnittliche Gegenstandsstufe der angelegten Ausruestung
|
||
-- (Plaetze 1-18 ohne Hemd, also auch ohne Wappenrock), beide wie in GearScore Forever.
|
||
local function gearScore()
|
||
local function equipLoc(link) return select(9, GetItemInfo(link)) end
|
||
local mh, oh = GetInventoryItemLink("player", 16), GetInventoryItemLink("player", 17)
|
||
local grip = 1 -- Titanengriff: zwei Zweihaender zaehlen je zur Haelfte
|
||
if mh and oh and (equipLoc(mh) == "INVTYPE_2HWEAPON" or equipLoc(oh) == "INVTYPE_2HWEAPON") then
|
||
grip = 0.5
|
||
end
|
||
local _, class = UnitClass("player")
|
||
local total, count, levels, complete = 0, 0, 0, true
|
||
for slot = 1, 18 do
|
||
if slot ~= 4 then
|
||
local link = GetInventoryItemLink("player", slot)
|
||
if link then
|
||
local score, level = itemScore(link)
|
||
if score then
|
||
if class == "HUNTER" and GS_HUNTER[slot] then score = score * GS_HUNTER[slot] end
|
||
if slot == 16 or slot == 17 then score = score * grip end
|
||
total, count, levels = total + score, count + 1, levels + level
|
||
else
|
||
complete = false
|
||
end
|
||
elseif GetInventoryItemID("player", slot) then
|
||
complete = false
|
||
requestItem(GetInventoryItemID("player", slot))
|
||
end
|
||
end
|
||
end
|
||
gsPending = not complete
|
||
return math.floor(total), count > 0 and math.floor(levels / count) or 0
|
||
end
|
||
|
||
-- Farbe wie in GearScore Forever. Dessen Skala waechst mit dem hoechsten
|
||
-- GearScore, den es je gesehen hat (auch bei anderen Spielern). Den liest
|
||
-- Goldbeutel aus dessen Einstellungen, falls das Addon installiert ist.
|
||
local function gsColor(score)
|
||
if score > 2000 then return "|cffff69b5" end -- rosa
|
||
local gdb = type(GearscoreForeverDB) == "table" and GearscoreForeverDB or {}
|
||
local seen = math.max(score, tonumber(gdb.maxScoreSeen) or 0)
|
||
-- 200 je Farbe wie in Classic, hoechstens 325, damit Orange bei 2000 endet
|
||
local step = math.min(325, math.max(200, math.ceil(seen / 5.5 / 25) * 25))
|
||
score = math.min(score, step * 6 - 1)
|
||
local q = GS_COLOR[math.ceil(score / step)]
|
||
local rgb = {}
|
||
for i, c in ipairs(q) do
|
||
local v = c[1] + (score - c[2] * step) * c[3] * c[4]
|
||
rgb[i] = math.floor(math.min(1, math.max(0, v)) * 255 + 0.5)
|
||
end
|
||
return string.format("|cff%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
||
end
|
||
|
||
-- Eine Zeile: Gold | 23 freie Taschenplaetze | 87% | GS 1234
|
||
local function frameText()
|
||
local parts = { formatMoney(GetMoney()) }
|
||
local free = bagSpace()
|
||
parts[#parts + 1] = paint(free, freeColor(free))
|
||
local low = durability()
|
||
if low then
|
||
parts[#parts + 1] = paint(math.floor(low) .. "%", pctColor(low))
|
||
end
|
||
local gs = gearScore()
|
||
if gs > 0 then
|
||
parts[#parts + 1] = LABEL .. "GS|r " .. paint(gs, gsColor(gs))
|
||
end
|
||
return table.concat(parts, SEP)
|
||
end
|
||
|
||
-- Felder aktualisieren statt den Eintrag zu ersetzen, damit der
|
||
-- Sitzungsstart (session) erhalten bleibt
|
||
local function record()
|
||
local chars = db.chars[realm]
|
||
local me = chars[player] or {}
|
||
chars[player] = me
|
||
local _, class = UnitClass("player")
|
||
me.money, me.class = GetMoney(), class
|
||
end
|
||
|
||
local function addStatusLines()
|
||
local free, total, sFree, sTotal = bagSpace()
|
||
GameTooltip:AddDoubleLine("Taschen frei:", paint(free, freeColor(free)) .. " / " .. total,
|
||
1, 0.82, 0, 1, 1, 1)
|
||
if sTotal > 0 then
|
||
GameTooltip:AddDoubleLine("Spezialtaschen frei:", sFree .. " / " .. sTotal, 1, 0.82, 0, 1, 1, 1)
|
||
end
|
||
|
||
local low, lowSlot, overall = durability()
|
||
if low then
|
||
GameTooltip:AddDoubleLine("Rüstung gesamt:", paint(math.floor(overall) .. "%", pctColor(overall)),
|
||
1, 0.82, 0, 1, 1, 1)
|
||
if low < 100 then
|
||
local link = GetInventoryItemLink("player", lowSlot) or "?"
|
||
GameTooltip:AddDoubleLine(" " .. link, paint(math.floor(low) .. "%", pctColor(low)),
|
||
1, 1, 1, 1, 1, 1)
|
||
end
|
||
end
|
||
|
||
local gs, ilvl = gearScore()
|
||
if gs > 0 then
|
||
GameTooltip:AddDoubleLine("GearScore:", paint(gs, gsColor(gs)), 1, 0.82, 0, 1, 1, 1)
|
||
GameTooltip:AddDoubleLine("Gegenstandsstufe:", ilvl, 1, 0.82, 0, 1, 1, 1)
|
||
end
|
||
end
|
||
|
||
local function showTooltip(self)
|
||
-- Tooltip zur Bildschirmmitte hin öffnen, damit er den Rahmen nicht verdeckt
|
||
local _, y = self:GetCenter()
|
||
local anchor = (y and y > UIParent:GetHeight() / 2) and "ANCHOR_BOTTOM" or "ANCHOR_TOP"
|
||
GameTooltip:SetOwner(self, anchor)
|
||
GameTooltip:AddLine("Goldbeutel")
|
||
addStatusLines()
|
||
GameTooltip:AddLine(" ")
|
||
|
||
local diff = GetMoney() - sessionStart
|
||
local sign, r, g, b = "", 1, 1, 1
|
||
if diff > 0 then
|
||
sign, r, g, b = "+", 0.2, 1, 0.2
|
||
elseif diff < 0 then
|
||
sign, r, g, b = "-", 1, 0.3, 0.3
|
||
end
|
||
GameTooltip:AddDoubleLine("Diese Sitzung:", sign .. formatMoney(math.abs(diff)), 1, 0.82, 0, r, g, b)
|
||
GameTooltip:AddLine(" ")
|
||
|
||
local list, total = {}, 0
|
||
for name, info in pairs(db.chars[realm]) do
|
||
local m = info.money or 0
|
||
list[#list + 1] = { name = name, money = m, class = info.class }
|
||
total = total + m
|
||
end
|
||
table.sort(list, function(a, b) return a.money > b.money end)
|
||
|
||
for _, e in ipairs(list) do
|
||
local label = classColored(e.name, e.class)
|
||
if e.name == player then label = label .. " *" end
|
||
GameTooltip:AddDoubleLine(label, formatMoney(e.money), 1, 1, 1, 1, 1, 1)
|
||
end
|
||
if #list > 1 then
|
||
GameTooltip:AddDoubleLine("Gesamt (" .. realm .. "):", formatMoney(total), 1, 0.82, 0, 1, 1, 1)
|
||
end
|
||
|
||
GameTooltip:AddLine(" ")
|
||
if db.locked then
|
||
GameTooltip:AddLine("Gesperrt. Rechtsklick zum Entsperren.", 0.6, 0.6, 0.6)
|
||
else
|
||
GameTooltip:AddLine("Ziehen: verschieben, Rechtsklick: sperren", 0.6, 0.6, 0.6)
|
||
end
|
||
GameTooltip:Show()
|
||
end
|
||
|
||
local function update()
|
||
record()
|
||
text:SetText(frameText())
|
||
frame:SetSize(math.ceil(text:GetStringWidth()) + 20, math.ceil(text:GetStringHeight()) + 14)
|
||
if GameTooltip:IsOwned(frame) then showTooltip(frame) end
|
||
end
|
||
|
||
-- Mehrere Ereignisse kurz hintereinander (Ausruestung wechseln, Taschen sortieren)
|
||
-- loesen nur eine Aktualisierung im naechsten Frame aus
|
||
local queued = false
|
||
local function queueUpdate()
|
||
if queued or not frame then return end
|
||
queued = true
|
||
C_Timer.After(0, function()
|
||
queued = false
|
||
update()
|
||
end)
|
||
end
|
||
|
||
local function toggleLock()
|
||
db.locked = not db.locked
|
||
say(db.locked and "Rahmen gesperrt." or "Rahmen entsperrt.")
|
||
if GameTooltip:IsOwned(frame) then showTooltip(frame) end
|
||
end
|
||
|
||
local function savePos()
|
||
local point, _, relPoint, x, y = frame:GetPoint(1)
|
||
db.pos = { point, relPoint, x, y }
|
||
end
|
||
|
||
local function restorePos()
|
||
frame:ClearAllPoints()
|
||
local p = db.pos
|
||
if p then
|
||
frame:SetPoint(p[1], UIParent, p[2], p[3], p[4])
|
||
else
|
||
frame:SetPoint("CENTER", UIParent, "CENTER", 0, -200)
|
||
end
|
||
end
|
||
|
||
local function createFrame()
|
||
frame = CreateFrame("Frame", "GoldbeutelFrame", UIParent, "BackdropTemplate")
|
||
frame:SetFrameStrata("MEDIUM")
|
||
frame:SetClampedToScreen(true)
|
||
frame:SetMovable(true)
|
||
frame:EnableMouse(true)
|
||
frame:RegisterForDrag("LeftButton")
|
||
-- Position speichern wir selbst, nicht im layout-cache des Clients
|
||
if frame.SetDontSavePosition then frame:SetDontSavePosition(true) end
|
||
|
||
frame:SetBackdrop({
|
||
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
|
||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
||
tile = true, tileSize = 16, edgeSize = 12,
|
||
insets = { left = 3, right = 3, top = 3, bottom = 3 },
|
||
})
|
||
frame:SetBackdropColor(0, 0, 0, 0.75)
|
||
frame:SetBackdropBorderColor(0.6, 0.6, 0.6, 1)
|
||
|
||
text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
|
||
text:SetPoint("CENTER")
|
||
|
||
frame:SetScript("OnDragStart", function(self)
|
||
if db.locked then return end
|
||
self.dragging = true
|
||
self:StartMoving()
|
||
end)
|
||
frame:SetScript("OnDragStop", function(self)
|
||
if not self.dragging then return end
|
||
self.dragging = false
|
||
self:StopMovingOrSizing()
|
||
savePos()
|
||
end)
|
||
frame:SetScript("OnMouseUp", function(_, button)
|
||
if button == "RightButton" then toggleLock() end
|
||
end)
|
||
frame:SetScript("OnEnter", showTooltip)
|
||
frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
||
|
||
restorePos()
|
||
frame:SetShown(not db.hidden)
|
||
end
|
||
|
||
local ev = CreateFrame("Frame")
|
||
ev:RegisterEvent("ADDON_LOADED")
|
||
ev:RegisterEvent("PLAYER_LOGIN")
|
||
ev:RegisterEvent("PLAYER_MONEY")
|
||
ev:RegisterEvent("PLAYER_LOGOUT")
|
||
ev:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||
-- Taschen, Ruestung, GearScore. pcall, falls ein Client eines davon nicht kennt.
|
||
for _, e in ipairs({ "BAG_UPDATE_DELAYED", "UPDATE_INVENTORY_DURABILITY",
|
||
"PLAYER_EQUIPMENT_CHANGED", "GET_ITEM_INFO_RECEIVED" }) do
|
||
pcall(ev.RegisterEvent, ev, e)
|
||
end
|
||
ev:SetScript("OnEvent", function(self, event, arg1, arg2)
|
||
if event == "ADDON_LOADED" then
|
||
if arg1 ~= ADDON then return end
|
||
GoldbeutelDB = GoldbeutelDB or {}
|
||
db = GoldbeutelDB
|
||
db.chars = db.chars or {}
|
||
self:UnregisterEvent("ADDON_LOADED")
|
||
elseif event == "PLAYER_LOGIN" then
|
||
realm, player = GetRealmName(), UnitName("player")
|
||
db.chars[realm] = db.chars[realm] or {}
|
||
sessionStart = GetMoney()
|
||
createFrame()
|
||
update()
|
||
elseif event == "PLAYER_ENTERING_WORLD" then
|
||
-- PLAYER_LOGIN kommt auch bei /reload. Erst hier steht fest, ob es nur ein
|
||
-- Reload war (arg2 = isReloadingUi); dann zaehlt die Sitzung weiter.
|
||
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
|
||
local me = db.chars[realm][player]
|
||
if arg2 and me.session then
|
||
sessionStart = me.session
|
||
else
|
||
me.session = sessionStart
|
||
end
|
||
-- Taschen und Ausruestung sind jetzt sicher vollstaendig geladen
|
||
queueUpdate()
|
||
elseif event == "PLAYER_LOGOUT" then
|
||
if realm then record() end
|
||
elseif event == "GET_ITEM_INFO_RECEIVED" then
|
||
-- kommt fuer jeden Gegenstand, den der Client laedt; nur interessant,
|
||
-- solange dem GearScore noch Daten fehlen
|
||
if gsPending then queueUpdate() end
|
||
else
|
||
-- PLAYER_MONEY und die Ereignisse fuer Taschen, Ruestung und Ausruestung
|
||
queueUpdate()
|
||
end
|
||
end)
|
||
|
||
SLASH_GOLDBEUTEL1 = "/gold"
|
||
SLASH_GOLDBEUTEL2 = "/goldbeutel"
|
||
SlashCmdList.GOLDBEUTEL = function(input)
|
||
local cmd, arg = strtrim(input or ""):match("^(%S*)%s*(.-)$")
|
||
cmd = cmd:lower()
|
||
|
||
if cmd == "" then
|
||
db.hidden = frame:IsShown()
|
||
frame:SetShown(not db.hidden)
|
||
if db.hidden then say("ausgeblendet. /gold blendet ihn wieder ein.") end
|
||
elseif cmd == "lock" then
|
||
toggleLock()
|
||
elseif cmd == "reset" then
|
||
db.pos, db.hidden = nil, false
|
||
restorePos()
|
||
frame:Show()
|
||
say("Position zurückgesetzt.")
|
||
elseif cmd == "forget" and arg ~= "" then
|
||
local chars, want = db.chars[realm], lower(arg)
|
||
for name in pairs(chars) do
|
||
if lower(name) == want and name ~= player then
|
||
chars[name] = nil
|
||
say(name .. " entfernt.")
|
||
return
|
||
end
|
||
end
|
||
say("Kein anderer Charakter namens '" .. arg .. "' auf " .. realm .. ".")
|
||
else
|
||
say("/gold (ein/aus), /gold lock, /gold reset, /gold forget <Name>")
|
||
end
|
||
end
|