Skip to content

Commit

Permalink
fix show, claim items, expire items
Browse files Browse the repository at this point in the history
  • Loading branch information
sogladev committed Aug 7, 2024
1 parent 7644e28 commit 2f77f5e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 15 deletions.
33 changes: 20 additions & 13 deletions DKPClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local Status = {
PENDING = 1,
BIDDING = 2,
ASSIGNED = 3,
CLAIMED = 4,
}

local Separator = {
Expand All @@ -37,7 +38,7 @@ end

-- Handlers
function DKPHandlers.ShowFrame(player)
frame:Show()
DKP.client.window:Show()
end

function DKP.Split(str, sep)
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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)
52 changes: 50 additions & 2 deletions DKPServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 2f77f5e

Please sign in to comment.