diff --git a/DKPClient.lua b/DKPClient.lua index 5a6cba1..92693ff 100644 --- a/DKPClient.lua +++ b/DKPClient.lua @@ -17,6 +17,7 @@ local Status = { PENDING = 1, BIDDING = 2, ASSIGNED = 3, + CLAIMED = 4, } local Separator = { @@ -37,7 +38,7 @@ end -- Handlers function DKPHandlers.ShowFrame(player) - frame:Show() + DKP.client.window:Show() end function DKP.Split(str, sep) @@ -295,8 +296,16 @@ function Client:ConfigureRow(row, item) row.bidButton:Enable() row.bidButton:SetText("Bid") elseif item.status == Status.ASSIGNED then - row.bidButton:Enable() - row.bidButton:SetText("Claim") + if item.topBidder == UnitName("player") then + row.bidButton:SetText("Claim") + row.bidButton:Enable() + else + row.bidButton:SetText("") + row.bidButton:Disable() + end + elseif item.status == Status.CLAIMED then + row.bidButton:SetText("Claimed") + row.bidButton:Disable() else row.bidButton:Disable() row.bidButton:SetText("Pending") @@ -306,12 +315,9 @@ function Client:ConfigureRow(row, item) row.topBidAmountText:SetText(item.bid ~= 0 and item.bid or "No bid") row.countdownBar:CountdownItem(item) - end - - -- Create auction rows function Client:CreateRow(parent, item) local row = CreateFrame("Frame", nil, parent) @@ -397,11 +403,12 @@ function Client:CreateRow(parent, item) self.bidBox:ClearFocus() local item = self.item if not item then return end - -- if self.bidButton:GetText() == "OS" then - -- elseif item.pendingBid then - item.pendingBid = 69 -- TODO: read value set from bidBox - AIO.Handle(ADDON_NAME, "RequestBid", item.id, item.pendingBid) - -- end + if self.bidButton:GetText() == "Claim" then + AIO.Handle(ADDON_NAME, "RequestClaim", item.id) + else + item.pendingBid = 69 -- TODO: read value set from bidBox + AIO.Handle(ADDON_NAME, "RequestBid", item.id, item.pendingBid) + end end @@ -498,8 +505,8 @@ local client = Client:Create() DKP.client = client client.window = client:CreateWindow() -- add test items -local testStr = "1^39252^1+2^39251^1+3^23070^1" +-- local testStr = "1^39252^1+2^39251^1+3^23070^1" -- local testStr = "1^39252^1+2^39251^1+3^23070^1+4^23000^1+5^22801^1+6^22808^1+7^22803^1+8^22353^1+9^22804^1+10^22805^1" -- cache -DKPHandlers.SyncResponse(nil, testStr) +-- DKPHandlers.SyncResponse(nil, testStr) print(DKP.items) diff --git a/DKPServer.lua b/DKPServer.lua index 10bd910..8d7824a 100644 --- a/DKPServer.lua +++ b/DKPServer.lua @@ -243,9 +243,17 @@ function DKPHandlers.RequestClaim(player, id) local itemId = item.itemId -- add item if item.status ~= Status.CLAIMED then - player:AddItem(itemId, 1) -- (entry, count) - session:SetItemClaimed(id) + -- check top bid + if item.topBidderGUID == player:GetGUID() then + local priceInCopper = item.bid * 10000 + if player:GetCoinage() >= priceInCopper then + player:ModifyMoney(-priceInCopper) + player:AddItem(itemId, 1) -- (entry, count) + session:SetItemClaimed(id) + end + end end + session:OnChange() end @@ -279,5 +287,45 @@ local function OnCommand(event, player, command) end end + +function Session:ExpireItems() + -- assign items on expire + local anyExpired = false + for i, item in ipairs(self.items) do + if item.status == Status.BIDDING then + if item.expiration < GetGameTime() then + self.items[i].status = Status.ASSIGNED + anyExpired = true + end + end + end + return anyExpired +end + +local function OnTimedLuaEvent(eventId, delay, repeats) + -- loop through sessions + for instanceId, session in pairs(Sessions) do + print("session!") + local anyExpired = session:ExpireItems() + if anyExpired then + session:OnChange() + end + end +end + RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand) RegisterPacketEvent(CMSG_LOOT, PACKET_EVENT_ON_PACKET_RECEIVE, OnLootFrameOpen) +CreateLuaEvent(OnTimedLuaEvent, 1000, 0) -- ( function, delay, repeats ) + +local function DoPayoutGold(player, payout) + -- if (payout + player:GetCoinage()) > COINAGE_MAX then + -- SendMail(DR.Config.mail.subject, string.format(DR.Config.mail.body, player:GetName()), + -- player:GetGUIDLow(), DR.Config.mail.senderGUID, DR.Config.mail.stationary, 0, payout) + -- AIO.Handle(player, ADDON_NAME, "SentPayoutByMail") + -- else + -- player:ModifyMoney(payout) + -- end +end +function DKPHandlers.RequestPayout(player) + -- +end