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:
BeniS 2012-08-15 03:43:48 +12:00
parent 150059a561
commit b93ea86260
5 changed files with 60 additions and 74 deletions

View File

@ -9,6 +9,10 @@ function UIMiniWindowContainer.create()
return container
end
function UIMiniWindowContainer:getClassName()
return 'UIMiniWindowContainer'
end
function UIMiniWindowContainer:onDrop(widget, mousePos)
if widget:getClassName() == 'UIMiniWindow' then
local oldParent = widget:getParent()
@ -97,7 +101,3 @@ function UIMiniWindowContainer:saveChildren()
end
end
end
function UIMiniWindowContainer:getClassName()
return 'UIMiniWindowContainer'
end

View File

@ -45,6 +45,16 @@ function UIRadioGroup:selectWidget(selectedWidget)
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
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()
return self.selectedWidget
end

View File

@ -6,11 +6,6 @@
BeniS's Skype: benjiz69
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:
- Current Offers
- Offer History
@ -18,16 +13,19 @@
* Optimize Offer Updates:
- Cache and avoid dead loop runs
* Clean up the interface building
- Add a new market interface file to handle building?
* Optimize loading market items:
- Cache items to their categories
* Clean up the interface building
- Add a new market interface file to handle building?
* Add offer table column ordering.
- Player Name, Amount, Total Price, Peice Price and Ends At
* Add simple close button.
* Extend information features
- Hover over offers for purchase information (balance after transaction, etc)
]]
Market = {}
@ -77,10 +75,12 @@ detailsTable = nil
buyStatsTable = nil
sellStatsTable = nil
offerExhaust = {}
marketOffers = {}
marketItems = {}
information = {}
currentItems = {}
lastCreatedOffer = 0
fee = 0
local offerTableHeader = {
@ -399,50 +399,6 @@ local function updateBalance(balance)
balanceLabel:resizeToText()
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)
fee = math.ceil(price / 100 * amount)
if fee < 20 then
@ -511,7 +467,6 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
if offer:isEqual(selectedRow.ref) then
selectedOffer[MarketAction.Buy] = offer
buyButton:setEnabled(true)
end
end
@ -520,6 +475,7 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
local price = offer:getPrice()
if price > information.balance then
balanceLabel:setColor('#b22222')
buyButton:setEnabled(false)
else
local slice = (information.balance / 2)
if (price/slice) * 100 <= 40 then
@ -530,6 +486,7 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
color = '#ee9a00' -- orange
end
balanceLabel:setColor(color)
buyButton:setEnabled(true)
end
end
end
@ -767,6 +724,9 @@ function init()
g_ui.importStyle('ui/general/marketcombobox.otui')
g_ui.importStyle('ui/general/amountwindow.otui')
offerExhaust[MarketAction.Sell] = 10
offerExhaust[MarketAction.Buy] = 60
protocol.initProtocol()
connect(g_game, { onGameEnd = Market.reset })
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
@ -920,8 +880,6 @@ function Market.refreshItemsWidget(selectItem)
radioItemSet:addWidget(itemBox)
end
if select then
selectedItem.item = select.item
selectedItem.ref = select
select:setChecked(true)
end
@ -1029,21 +987,21 @@ function Market.createNewOffer()
elseif amount < amountEdit.minimum then
errorMsg = errorMsg..'Amount is too low.\n'
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
UIMessageBox.display('Error', errorMsg, MessageBoxOk)
displayInfoBox('Error', errorMsg)
return
end
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
if type == MarketAction.Sell then
--[[
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
lastCreatedOffer = os.time()
Market.resetCreateOffer()
end
@ -1058,7 +1016,6 @@ function Market.sellMarketOffer(amount, timestamp, counter)
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
local spriteId = selectedItem.item.ptr:getId()
updateDepotItemCount(spriteId, amount)
Market.refreshItemsWidget(spriteId)
end
end
@ -1088,6 +1045,14 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
end
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
Market.loadMarketItems(MarketCategory.First)
end

View File

@ -2,11 +2,12 @@ MarketProtocol = {}
-- private functions
local silent
local protocol
local statistics = runinsandbox('offerstatistic.lua')
local function send(msg)
if protocol then
if protocol and not silent then
protocol:send(msg)
end
end
@ -130,6 +131,8 @@ function initProtocol()
if g_game.isOnline() then
MarketProtocol.registerProtocol()
end
MarketProtocol.silent(false)
end
function terminateProtocol()
@ -165,6 +168,10 @@ function MarketProtocol.unregisterProtocol()
MarketProtocol.updateProtocol(nil)
end
function MarketProtocol.silent(mode)
silent = mode
end
-- sending protocols
function MarketProtocol.sendMarketLeave()

View File

@ -5,6 +5,10 @@ MarketTabBarButton < TabBarButton
font: verdana-11px-rounded
text-offset: 0 2
$!first:
anchors.left: prev.right
margin-left: 0
$hover !checked:
image-clip: 0 20 20 20
color: white