generated from azerothcore/skeleton-module
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
238 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
local ADDON_NAME = "AIODKP" | ||
local AIO = AIO or require("AIO") | ||
if AIO.AddAddon() then | ||
return | ||
end | ||
local DKPHandlers = {} | ||
local DKP = {} | ||
AIO.AddHandlers(ADDON_NAME, DKPHandlers) | ||
|
||
-- local find, format, gmatch, gsub, tolower, match, toupper, join, split, trim = string.find, string.format, string.gmatch, string.gsub, string.lower, string.match, string.upper, string.join, string.split, string.trim | ||
|
||
DKP.Config = { | ||
addonMsgPrefix = "|TInterface/MoneyFrame/UI-GoldIcon:14:14:2:0|t|cfffff800DKP|r", | ||
} | ||
|
||
local Status = { | ||
PENDING = 1, | ||
BIDDING = 2, | ||
ASSIGNED = 3, | ||
} | ||
|
||
local Separator = { | ||
ARG = ";", | ||
ELEMENT = "+", | ||
LIST_ELEMENT = "^", | ||
MESSAGE = "&", | ||
SUBLIST_ELEMENT = "/", | ||
} | ||
|
||
-- print with addon prefix | ||
function DKP.print(message) | ||
print(DKP.Config.addonMsgPrefix .. " " .. message) | ||
end | ||
function DKP.Error(message) | ||
print(DKP.Config.addonMsgPrefix .. " ERROR: " .. message) | ||
end | ||
|
||
local frame = CreateFrame("Frame", "DKPFrame", UIParent) | ||
frame:SetSize(800, 500) | ||
frame:SetPoint("CENTER") | ||
frame:SetToplevel(true) | ||
frame:SetClampedToScreen(true) | ||
|
||
-- This enables saving of the position of the frame over reload of the UI or restarting game | ||
AIO.SavePosition(frame) | ||
|
||
-- baseframe: Enable dragging | ||
frame:RegisterForDrag("LeftButton") | ||
frame:SetMovable(true) | ||
frame:EnableMouse(true) | ||
frame:SetScript("OnDragStart", frame.StartMoving) | ||
frame:SetScript("OnHide", frame.StopMovingOrSizing) | ||
frame:SetScript("OnDragStop", frame.StopMovingOrSizing) | ||
|
||
-- baseframe: Close button | ||
frame.closeButton = CreateFrame("Button", nil, frame, "UIPanelCloseButton") | ||
frame.closeButton:SetPoint("TOPRIGHT", frame, "TOPRIGHT") | ||
frame.closeButton:SetScript("OnClick", function(self) | ||
frame:Hide() | ||
end) | ||
-- baseframe: title | ||
frame.title = frame:CreateFontString(nil, "OVERLAY") | ||
frame.title:SetFontObject("GameFontNormalMed3") | ||
frame.title:SetPoint("TOP", frame, "TOP", 0, -15) | ||
frame.title:SetText("DKP") | ||
frame:SetPoint("CENTER") | ||
frame:SetToplevel(true) | ||
frame:SetClampedToScreen(true) | ||
-- baseframe: Set background | ||
frame:SetBackdrop({ | ||
bgFile = "Interface/DialogFrame/UI-DialogBox-Background", | ||
edgeFile = "Interface/DialogFrame/UI-DialogBox-Border", | ||
tile = true, tileSize = 32, edgeSize = 32, | ||
insets = { left = 11, right = 12, top = 12, bottom = 11 } | ||
}) | ||
frame:SetBackdropColor(0, 0, 0, 1) | ||
|
||
-- Handlers | ||
function DKPHandlers.ShowFrame(player) | ||
frame:Show() | ||
end | ||
|
||
function DKP.Split(str, sep) | ||
print("DKP.Split") | ||
local t = {} | ||
for s in str:gmatch("([^"..sep.."]+)") do | ||
table.insert(t, s) | ||
end | ||
return t | ||
end | ||
|
||
local Item = {} | ||
Item.__index = Item | ||
DKP.Item = Item | ||
function Item:CreateForId(itemId) | ||
itemId = tonumber(itemId) | ||
print("Item:CreateForId: ", itemId) | ||
local item = {id = itemId, isBound = false} | ||
setmetatable(item, Item) | ||
item:PopulateStaticProperties() | ||
return item | ||
end | ||
|
||
function Item:PopulateStaticProperties() | ||
print("Item:PopulateStaticProperties") | ||
print(self.id) | ||
self.name, self.link, self.quality, self.ilvl, self.minLevel, self.itemType, self.itemSubType, _, self.equipLoc, self.texture, _, self.classId, self.subclassId = GetItemInfo(self.id) | ||
if not self.name then | ||
DKP:Error("Invalid itemId", self.id) | ||
end | ||
end | ||
|
||
function DKP.DecodeRow(encodedStr) | ||
DKP.print("DKP.DecodeRow") | ||
print(encodedStr) | ||
local elements = DKP.Split(encodedStr, Separator.LIST_ELEMENT) | ||
local item = Item:CreateForId(elements[2]) | ||
local row = { | ||
id = tonumber(elements[1]), | ||
status = tonumber(elements[3]), | ||
} | ||
item:PopulateStaticProperties() | ||
row.item = item | ||
return row | ||
end | ||
|
||
function DKPHandlers.SyncResponse(player, encodedItems) | ||
DKP.print("SyncResponse") | ||
print(encodedItems) | ||
local splitRows = DKP.Split(encodedItems, Separator.ELEMENT) | ||
DKP.rows = {} | ||
for _, row in pairs(splitRows) do | ||
print("Row: ", row) | ||
local decodedRow = DKP.DecodeRow(row) | ||
table.insert(DKP.rows, decodedRow) | ||
print(decodedRow.item.link) | ||
end | ||
for _, row in pairs(DKP.rows) do | ||
DKP.print(string.format("%d %s", row.id, row.item.link)) | ||
end | ||
frame:Show() | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
local ADDON_NAME = "AIODKP" | ||
local AIO = AIO or require("AIO") | ||
local DKPHandlers = {} | ||
local DKP = {} | ||
AIO.AddHandlers(ADDON_NAME, DKPHandlers) | ||
|
||
local PLAYER_EVENT_ON_STORE_NEW_ITEM = 53 | ||
local PLAYER_EVENT_ON_COMMAND = 42 -- (event, player, command, chatHandler) - player is nil if command used from console. Can return false | ||
|
||
local Blacklist = { | ||
[47241]=true, -- Emblem of Triumph | ||
} | ||
|
||
local Status = { | ||
PENDING = 1, | ||
BIDDING = 2, | ||
ASSIGNED = 3, | ||
} | ||
|
||
local Separator = { | ||
ARG = ";", | ||
ELEMENT = "+", | ||
LIST_ELEMENT = "^", | ||
MESSAGE = "&", | ||
SUBLIST_ELEMENT = "/", | ||
} | ||
|
||
local sessions = {} | ||
|
||
local function OnPlayerEventOnStoreNewItem(event, player, item, count) | ||
print("OnPlayerEventOnStoreNewItem") | ||
print(player:GetName() .. " won " .. item:GetName() .. " (x" .. count .. ")") | ||
-- check if item is on blacklist | ||
if Blacklist[item:GetEntry()] then print("OnPlayerEventOnStoreNewItem:blacklist") return end | ||
-- add item to session tied to instance | ||
local instanceId = player:GetInstanceId() | ||
-- get session from instanceId | ||
sessions[instanceId] = sessions[instanceId] or {} -- new session if not exists | ||
sessions[instanceId].rows = sessions[instanceId].rows or {} -- new rows if not exists | ||
local rowId = #sessions[instanceId].rows+1 | ||
local itemRow = {id=rowId, item=item, itemId=item:GetEntry(), guid=item:GetGUIDLow(), status=Status.PENDING} | ||
table.insert(sessions[instanceId].rows, rowId, itemRow) | ||
print(string.format("Added item (Entry: %d, GUIDLow: %d) to session instanceId %d", item:GetEntry(), item:GetGUIDLow(), instanceId)) | ||
-- remove item from player | ||
item:SaveToDB() -- Save item to DB before we remove it from the player | ||
player:SaveToDB() -- must be called before RemoveItem else crash | ||
player:RemoveItem(item, count) | ||
end | ||
|
||
RegisterPlayerEvent(PLAYER_EVENT_ON_STORE_NEW_ITEM, OnPlayerEventOnStoreNewItem) | ||
|
||
function DKP.EncodeRow(row) | ||
return table.concat({row.id, row.itemId, row.status}, Separator.LIST_ELEMENT) | ||
end | ||
|
||
function DKP.EncodeSession(session) | ||
local encodedRows = {} | ||
local rows = session.rows or {} | ||
for _, row in pairs(rows) do | ||
local encodedRow = DKP.EncodeRow(row) | ||
table.insert(encodedRows, encodedRow) | ||
end | ||
return table.concat(encodedRows, Separator.ELEMENT) | ||
end | ||
|
||
function DKPHandlers.RequestSync(player) | ||
PrintInfo(string.format("%s:DKPHandlers.RequestSync(player) by account-name (%d-%s)", ADDON_NAME, player:GetAccountId(), player:GetName())) | ||
local instanceId = player:GetInstanceId() | ||
local session = sessions[instanceId] or {} -- new session if not exists | ||
local encodedSession = DKP.EncodeSession(session) | ||
AIO.Handle(player, ADDON_NAME, "SyncResponse", encodedSession) | ||
end | ||
|
||
local function OnCommand(event, player, command) | ||
PrintInfo(string.format("%s:OnCommand %s by account-name (%d-%s)", ADDON_NAME, command, player:GetAccountId(), player:GetName())) | ||
if command == "dkp" then | ||
PrintInfo(string.format("%s:OnCommand .dkp by account-name (%d-%s)", ADDON_NAME, player:GetAccountId(), player:GetName())) | ||
AIO.Handle(player, ADDON_NAME, "ShowFrame") | ||
return false | ||
end | ||
if command == "dkpopen" then | ||
PrintInfo(string.format("%s:OnCommand .dkpopen by account-name (%d-%s)", ADDON_NAME, player:GetAccountId(), player:GetName())) | ||
-- DKPHandlers.RequestPayout(player, true) | ||
return false | ||
end | ||
if command == "dkpsync" then | ||
PrintInfo(string.format("%s:OnCommand .dkpsync by account-name (%d-%s)", ADDON_NAME, player:GetAccountId(), player:GetName())) | ||
DKPHandlers.RequestSync(player) | ||
return false | ||
end | ||
end | ||
|
||
RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand) |