Checked off some Market TODO's.
* Added some market offer constraints: offer creation exhaustion and now checks balance to validate sell offers. * Fixed the depot updating issue (no longer requires updateDepotItemCount function) * Can now silence the MarketProtocol messages. * Few minor market fixes.
This commit is contained in:
parent
150059a561
commit
b93ea86260
|
@ -9,11 +9,15 @@ function UIMiniWindowContainer.create()
|
||||||
return container
|
return container
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UIMiniWindowContainer:getClassName()
|
||||||
|
return 'UIMiniWindowContainer'
|
||||||
|
end
|
||||||
|
|
||||||
function UIMiniWindowContainer:onDrop(widget, mousePos)
|
function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||||
if widget:getClassName() == 'UIMiniWindow' then
|
if widget:getClassName() == 'UIMiniWindow' then
|
||||||
local oldParent = widget:getParent()
|
local oldParent = widget:getParent()
|
||||||
if oldParent == self then
|
if oldParent == self then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if oldParent then
|
if oldParent then
|
||||||
|
@ -21,10 +25,10 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
|
||||||
end
|
end
|
||||||
|
|
||||||
if widget.movedWidget then
|
if widget.movedWidget then
|
||||||
local index = self:getChildIndex(widget.movedWidget)
|
local index = self:getChildIndex(widget.movedWidget)
|
||||||
self:insertChild(index + widget.movedIndex, widget)
|
self:insertChild(index + widget.movedIndex, widget)
|
||||||
else
|
else
|
||||||
self:addChild(widget)
|
self:addChild(widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -97,7 +101,3 @@ function UIMiniWindowContainer:saveChildren()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMiniWindowContainer:getClassName()
|
|
||||||
return 'UIMiniWindowContainer'
|
|
||||||
end
|
|
||||||
|
|
|
@ -45,6 +45,16 @@ function UIRadioGroup:selectWidget(selectedWidget)
|
||||||
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
|
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UIRadioGroup:clearSelected()
|
||||||
|
if not self.selectedWidget then return end
|
||||||
|
|
||||||
|
local previousSelectedWidget = self.selectedWidget
|
||||||
|
self.selectedWidget:setChecked(false)
|
||||||
|
self.selectedWidget = nil
|
||||||
|
|
||||||
|
signalcall(self.onSelectionChange, self, nil, previousSelectedWidget)
|
||||||
|
end
|
||||||
|
|
||||||
function UIRadioGroup:getSelectedWidget()
|
function UIRadioGroup:getSelectedWidget()
|
||||||
return self.selectedWidget
|
return self.selectedWidget
|
||||||
end
|
end
|
|
@ -6,11 +6,6 @@
|
||||||
BeniS's Skype: benjiz69
|
BeniS's Skype: benjiz69
|
||||||
|
|
||||||
List:
|
List:
|
||||||
* Add constraints for creating/buying offers:
|
|
||||||
- Add max market offers or a new method for updating depot items
|
|
||||||
- Add timer before you can create another offer (1 minute?)
|
|
||||||
- Add a check for buying offers (if you do not have enough balance)
|
|
||||||
|
|
||||||
* Add offer management:
|
* Add offer management:
|
||||||
- Current Offers
|
- Current Offers
|
||||||
- Offer History
|
- Offer History
|
||||||
|
@ -18,16 +13,19 @@
|
||||||
* Optimize Offer Updates:
|
* Optimize Offer Updates:
|
||||||
- Cache and avoid dead loop runs
|
- Cache and avoid dead loop runs
|
||||||
|
|
||||||
* Clean up the interface building
|
|
||||||
- Add a new market interface file to handle building?
|
|
||||||
|
|
||||||
* Optimize loading market items:
|
* Optimize loading market items:
|
||||||
- Cache items to their categories
|
- Cache items to their categories
|
||||||
|
|
||||||
|
* Clean up the interface building
|
||||||
|
- Add a new market interface file to handle building?
|
||||||
|
|
||||||
* Add offer table column ordering.
|
* Add offer table column ordering.
|
||||||
- Player Name, Amount, Total Price, Peice Price and Ends At
|
- Player Name, Amount, Total Price, Peice Price and Ends At
|
||||||
|
|
||||||
* Add simple close button.
|
* Add simple close button.
|
||||||
|
|
||||||
|
* Extend information features
|
||||||
|
- Hover over offers for purchase information (balance after transaction, etc)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
Market = {}
|
Market = {}
|
||||||
|
@ -77,10 +75,12 @@ detailsTable = nil
|
||||||
buyStatsTable = nil
|
buyStatsTable = nil
|
||||||
sellStatsTable = nil
|
sellStatsTable = nil
|
||||||
|
|
||||||
|
offerExhaust = {}
|
||||||
marketOffers = {}
|
marketOffers = {}
|
||||||
marketItems = {}
|
marketItems = {}
|
||||||
information = {}
|
information = {}
|
||||||
currentItems = {}
|
currentItems = {}
|
||||||
|
lastCreatedOffer = 0
|
||||||
fee = 0
|
fee = 0
|
||||||
|
|
||||||
local offerTableHeader = {
|
local offerTableHeader = {
|
||||||
|
@ -399,50 +399,6 @@ local function updateBalance(balance)
|
||||||
balanceLabel:resizeToText()
|
balanceLabel:resizeToText()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateDepotItemCount(itemId, amount)
|
|
||||||
if Market.depotContains(itemId) < amount then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
for i = 1, #information.depotItems do
|
|
||||||
local depotItem = information.depotItems[i]
|
|
||||||
if depotItem and itemId == depotItem.ptr:getId() then
|
|
||||||
local depotItemCount = depotItem.ptr:getCount()
|
|
||||||
|
|
||||||
if depotItem.ptr:isStackable() then
|
|
||||||
if depotItemCount <= 100 and depotItemCount >= amount then
|
|
||||||
if (depotItemCount - amount) <= 0 then
|
|
||||||
table.remove(information.depotItems, i) -- warning: this re-indexes
|
|
||||||
else
|
|
||||||
depotItem.ptr:setCount(depotItemCount - amount)
|
|
||||||
information.depotItems[i] = depotItem
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
local removeCount = math.floor(amount/100)
|
|
||||||
local remainder = amount % depotItemCount
|
|
||||||
if remainder > 0 then
|
|
||||||
removeCount = removeCount + 1
|
|
||||||
end
|
|
||||||
for j = 1, removeCount do
|
|
||||||
if j == removeCount and remainder > 0 then
|
|
||||||
updateDepotItemCount(itemId, remainder)
|
|
||||||
else
|
|
||||||
updateDepotItemCount(itemId, 100)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if amount > 0 then
|
|
||||||
information.depotItems[i] = nil
|
|
||||||
amount = amount - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function updateFee(price, amount)
|
local function updateFee(price, amount)
|
||||||
fee = math.ceil(price / 100 * amount)
|
fee = math.ceil(price / 100 * amount)
|
||||||
if fee < 20 then
|
if fee < 20 then
|
||||||
|
@ -511,7 +467,6 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
|
||||||
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
|
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
|
||||||
if offer:isEqual(selectedRow.ref) then
|
if offer:isEqual(selectedRow.ref) then
|
||||||
selectedOffer[MarketAction.Buy] = offer
|
selectedOffer[MarketAction.Buy] = offer
|
||||||
buyButton:setEnabled(true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -520,6 +475,7 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
|
||||||
local price = offer:getPrice()
|
local price = offer:getPrice()
|
||||||
if price > information.balance then
|
if price > information.balance then
|
||||||
balanceLabel:setColor('#b22222')
|
balanceLabel:setColor('#b22222')
|
||||||
|
buyButton:setEnabled(false)
|
||||||
else
|
else
|
||||||
local slice = (information.balance / 2)
|
local slice = (information.balance / 2)
|
||||||
if (price/slice) * 100 <= 40 then
|
if (price/slice) * 100 <= 40 then
|
||||||
|
@ -530,6 +486,7 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
|
||||||
color = '#ee9a00' -- orange
|
color = '#ee9a00' -- orange
|
||||||
end
|
end
|
||||||
balanceLabel:setColor(color)
|
balanceLabel:setColor(color)
|
||||||
|
buyButton:setEnabled(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -767,6 +724,9 @@ function init()
|
||||||
g_ui.importStyle('ui/general/marketcombobox.otui')
|
g_ui.importStyle('ui/general/marketcombobox.otui')
|
||||||
g_ui.importStyle('ui/general/amountwindow.otui')
|
g_ui.importStyle('ui/general/amountwindow.otui')
|
||||||
|
|
||||||
|
offerExhaust[MarketAction.Sell] = 10
|
||||||
|
offerExhaust[MarketAction.Buy] = 60
|
||||||
|
|
||||||
protocol.initProtocol()
|
protocol.initProtocol()
|
||||||
connect(g_game, { onGameEnd = Market.reset })
|
connect(g_game, { onGameEnd = Market.reset })
|
||||||
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
|
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
|
||||||
|
@ -920,8 +880,6 @@ function Market.refreshItemsWidget(selectItem)
|
||||||
radioItemSet:addWidget(itemBox)
|
radioItemSet:addWidget(itemBox)
|
||||||
end
|
end
|
||||||
if select then
|
if select then
|
||||||
selectedItem.item = select.item
|
|
||||||
selectedItem.ref = select
|
|
||||||
select:setChecked(true)
|
select:setChecked(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1029,21 +987,21 @@ function Market.createNewOffer()
|
||||||
elseif amount < amountEdit.minimum then
|
elseif amount < amountEdit.minimum then
|
||||||
errorMsg = errorMsg..'Amount is too low.\n'
|
errorMsg = errorMsg..'Amount is too low.\n'
|
||||||
end
|
end
|
||||||
|
local timeCheck = os.time() - lastCreatedOffer
|
||||||
|
print(timeCheck)
|
||||||
|
print(offerExhaust[type])
|
||||||
|
if timeCheck < offerExhaust[type] then
|
||||||
|
local waitTime = math.ceil((offerExhaust[type] - timeCheck))
|
||||||
|
errorMsg = errorMsg..'You must wait '.. waitTime ..' seconds before creating a new offer.\n'
|
||||||
|
end
|
||||||
|
|
||||||
if errorMsg ~= '' then
|
if errorMsg ~= '' then
|
||||||
UIMessageBox.display('Error', errorMsg, MessageBoxOk)
|
displayInfoBox('Error', errorMsg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
|
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
|
||||||
if type == MarketAction.Sell then
|
lastCreatedOffer = os.time()
|
||||||
--[[
|
|
||||||
This is required due to bot protected protocol (cannot update browse item without user input)
|
|
||||||
normal way is to use the new retrieved depot items in onMarketEnter and refresh the items widget.
|
|
||||||
]]
|
|
||||||
updateDepotItemCount(spriteId, amount)
|
|
||||||
Market.refreshItemsWidget(spriteId)
|
|
||||||
end
|
|
||||||
Market.resetCreateOffer()
|
Market.resetCreateOffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1058,7 +1016,6 @@ function Market.sellMarketOffer(amount, timestamp, counter)
|
||||||
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
|
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
|
||||||
|
|
||||||
local spriteId = selectedItem.item.ptr:getId()
|
local spriteId = selectedItem.item.ptr:getId()
|
||||||
updateDepotItemCount(spriteId, amount)
|
|
||||||
Market.refreshItemsWidget(spriteId)
|
Market.refreshItemsWidget(spriteId)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1088,6 +1045,14 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
||||||
end
|
end
|
||||||
|
|
||||||
Market.loadDepotItems(depotItems)
|
Market.loadDepotItems(depotItems)
|
||||||
|
-- update the items widget to match depot items
|
||||||
|
if Market.isItemSelected() then
|
||||||
|
local spriteId = selectedItem.item.ptr:getId()
|
||||||
|
MarketProtocol.silent(true) -- disable protocol messages
|
||||||
|
Market.refreshItemsWidget(spriteId)
|
||||||
|
MarketProtocol.silent(false) -- enable protocol messages
|
||||||
|
end
|
||||||
|
|
||||||
if table.empty(currentItems) then
|
if table.empty(currentItems) then
|
||||||
Market.loadMarketItems(MarketCategory.First)
|
Market.loadMarketItems(MarketCategory.First)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,12 @@ MarketProtocol = {}
|
||||||
|
|
||||||
-- private functions
|
-- private functions
|
||||||
|
|
||||||
|
local silent
|
||||||
local protocol
|
local protocol
|
||||||
local statistics = runinsandbox('offerstatistic.lua')
|
local statistics = runinsandbox('offerstatistic.lua')
|
||||||
|
|
||||||
local function send(msg)
|
local function send(msg)
|
||||||
if protocol then
|
if protocol and not silent then
|
||||||
protocol:send(msg)
|
protocol:send(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -130,6 +131,8 @@ function initProtocol()
|
||||||
if g_game.isOnline() then
|
if g_game.isOnline() then
|
||||||
MarketProtocol.registerProtocol()
|
MarketProtocol.registerProtocol()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
MarketProtocol.silent(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function terminateProtocol()
|
function terminateProtocol()
|
||||||
|
@ -165,6 +168,10 @@ function MarketProtocol.unregisterProtocol()
|
||||||
MarketProtocol.updateProtocol(nil)
|
MarketProtocol.updateProtocol(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MarketProtocol.silent(mode)
|
||||||
|
silent = mode
|
||||||
|
end
|
||||||
|
|
||||||
-- sending protocols
|
-- sending protocols
|
||||||
|
|
||||||
function MarketProtocol.sendMarketLeave()
|
function MarketProtocol.sendMarketLeave()
|
||||||
|
|
|
@ -5,6 +5,10 @@ MarketTabBarButton < TabBarButton
|
||||||
font: verdana-11px-rounded
|
font: verdana-11px-rounded
|
||||||
text-offset: 0 2
|
text-offset: 0 2
|
||||||
|
|
||||||
|
$!first:
|
||||||
|
anchors.left: prev.right
|
||||||
|
margin-left: 0
|
||||||
|
|
||||||
$hover !checked:
|
$hover !checked:
|
||||||
image-clip: 0 20 20 20
|
image-clip: 0 20 20 20
|
||||||
color: white
|
color: white
|
||||||
|
|
Loading…
Reference in New Issue