Market fixes for creating offers, got Tibia working properly with market, fixes to statistics.
This commit is contained in:
parent
497902736c
commit
6c281a828c
|
@ -31,6 +31,7 @@ function UITable:onDestroy()
|
||||||
self.columns = {}
|
self.columns = {}
|
||||||
self.headerRow = {}
|
self.headerRow = {}
|
||||||
self.selectedRow = nil
|
self.selectedRow = nil
|
||||||
|
self.dataSpace:destroyChildren()
|
||||||
self.dataSpace = nil
|
self.dataSpace = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,6 +70,9 @@ function UITable:clearData()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.dataSpace:destroyChildren()
|
self.dataSpace:destroyChildren()
|
||||||
|
self.selectedRow = nil
|
||||||
|
self.columns = {}
|
||||||
|
self.rows = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function UITable:addHeaderRow(data)
|
function UITable:addHeaderRow(data)
|
||||||
|
|
|
@ -122,8 +122,12 @@ local function refreshFee()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateOffers(offers)
|
local function updateOffers(offers)
|
||||||
|
selectedOffer[MarketAction.Buy] = {}
|
||||||
|
selectedOffer[MarketAction.Sell] = {}
|
||||||
|
|
||||||
marketOffers[MarketAction.Buy] = {}
|
marketOffers[MarketAction.Buy] = {}
|
||||||
marketOffers[MarketAction.Sell] = {}
|
marketOffers[MarketAction.Sell] = {}
|
||||||
|
|
||||||
if not buyOfferTable or not sellOfferTable then
|
if not buyOfferTable or not sellOfferTable then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -132,7 +136,7 @@ local function updateOffers(offers)
|
||||||
balanceLabel:setColor('#bbbbbb')
|
balanceLabel:setColor('#bbbbbb')
|
||||||
|
|
||||||
for k, offer in pairs(offers) do
|
for k, offer in pairs(offers) do
|
||||||
if offer and offer:getAction() == MarketAction.Buy then
|
if offer and offer:getType() == MarketAction.Buy then
|
||||||
local data = {
|
local data = {
|
||||||
{['text'] = offer:getPlayer(), ['width'] = 100},
|
{['text'] = offer:getPlayer(), ['width'] = 100},
|
||||||
{['text'] = offer:getAmount(), ['width'] = 60},
|
{['text'] = offer:getAmount(), ['width'] = 60},
|
||||||
|
@ -160,11 +164,6 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||||
if not selectedItem then
|
if not selectedItem then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
selectedItem.item.details = {
|
|
||||||
descriptions = descriptions,
|
|
||||||
purchaseStats = purchaseStats,
|
|
||||||
saleStats = saleStats
|
|
||||||
}
|
|
||||||
|
|
||||||
-- update item details
|
-- update item details
|
||||||
detailsTable:clearData()
|
detailsTable:clearData()
|
||||||
|
@ -181,21 +180,38 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||||
if table.empty(saleStats) then
|
if table.empty(saleStats) then
|
||||||
sellStatsTable:addRow({{['text'] = 'No information'}})
|
sellStatsTable:addRow({{['text'] = 'No information'}})
|
||||||
else
|
else
|
||||||
for k, stat in pairs(saleStats) do
|
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
||||||
if not table.empty(stat) then
|
for _, stat in pairs(saleStats) do
|
||||||
|
if not stat:isNull() then
|
||||||
|
transactions = transactions + stat:getTransactions()
|
||||||
|
totalPrice = totalPrice + stat:getTotalPrice()
|
||||||
|
local newHigh = stat:getHighestPrice()
|
||||||
|
if newHigh > highestPrice then
|
||||||
|
highestPrice = newHigh
|
||||||
|
end
|
||||||
|
local newLow = stat:getLowestPrice()
|
||||||
|
-- ?? getting '4294967295' result from lowest price in 9.60 cipsoft
|
||||||
|
if (lowestPrice == 0 or newLow < lowestPrice) and newLow ~= 4294967295 then
|
||||||
|
lowestPrice = newLow
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
sellStatsTable:addRow({{['text'] = 'Total Transations:'},
|
sellStatsTable:addRow({{['text'] = 'Total Transations:'},
|
||||||
{['text'] = stat[1], ['width'] = 270}})
|
{['text'] = transactions, ['width'] = 270}})
|
||||||
|
|
||||||
sellStatsTable:addRow({{['text'] = 'Highest Price:'},
|
sellStatsTable:addRow({{['text'] = 'Highest Price:'},
|
||||||
{['text'] = stat[3], ['width'] = 270}})
|
{['text'] = highestPrice, ['width'] = 270}})
|
||||||
|
|
||||||
|
if totalPrice > 0 and transactions > 0 then
|
||||||
sellStatsTable:addRow({{['text'] = 'Average Price:'},
|
sellStatsTable:addRow({{['text'] = 'Average Price:'},
|
||||||
{['text'] = math.floor(stat[2]/stat[1])}})
|
{['text'] = math.floor(totalPrice/transactions), ['width'] = 270}})
|
||||||
|
else
|
||||||
|
sellStatsTable:addRow({{['text'] = 'Average Price:'},
|
||||||
|
{['text'] = 0, ['width'] = 270}})
|
||||||
|
end
|
||||||
|
|
||||||
sellStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
sellStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
||||||
{['text'] = stat[4], ['width'] = 270}})
|
{['text'] = lowestPrice, ['width'] = 270}})
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update buy item statistics
|
-- update buy item statistics
|
||||||
|
@ -203,21 +219,38 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||||
if table.empty(purchaseStats) then
|
if table.empty(purchaseStats) then
|
||||||
buyStatsTable:addRow({{['text'] = 'No information'}})
|
buyStatsTable:addRow({{['text'] = 'No information'}})
|
||||||
else
|
else
|
||||||
for k, stat in pairs(purchaseStats) do
|
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
||||||
if not table.empty(stat) then
|
for _, stat in pairs(purchaseStats) do
|
||||||
|
if not stat:isNull() then
|
||||||
|
transactions = transactions + stat:getTransactions()
|
||||||
|
totalPrice = totalPrice + stat:getTotalPrice()
|
||||||
|
local newHigh = stat:getHighestPrice()
|
||||||
|
if newHigh > highestPrice then
|
||||||
|
highestPrice = newHigh
|
||||||
|
end
|
||||||
|
local newLow = stat:getLowestPrice()
|
||||||
|
-- ?? getting '4294967295' result from lowest price in 9.60 cipsoft
|
||||||
|
if (lowestPrice == 0 or newLow < lowestPrice) and newLow ~= 4294967295 then
|
||||||
|
lowestPrice = newLow
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
buyStatsTable:addRow({{['text'] = 'Total Transations:'},
|
buyStatsTable:addRow({{['text'] = 'Total Transations:'},
|
||||||
{['text'] = stat[1], ['width'] = 270}})
|
{['text'] = transactions, ['width'] = 270}})
|
||||||
|
|
||||||
buyStatsTable:addRow({{['text'] = 'Highest Price:'},
|
buyStatsTable:addRow({{['text'] = 'Highest Price:'},
|
||||||
{['text'] = stat[3], ['width'] = 270}})
|
{['text'] = highestPrice, ['width'] = 270}})
|
||||||
|
|
||||||
|
if totalPrice > 0 and transactions > 0 then
|
||||||
buyStatsTable:addRow({{['text'] = 'Average Price:'},
|
buyStatsTable:addRow({{['text'] = 'Average Price:'},
|
||||||
{['text'] = math.floor(stat[2]/stat[1]), ['width'] = 270}})
|
{['text'] = math.floor(totalPrice/transactions), ['width'] = 270}})
|
||||||
|
else
|
||||||
|
buyStatsTable:addRow({{['text'] = 'Average Price:'},
|
||||||
|
{['text'] = 0, ['width'] = 270}})
|
||||||
|
end
|
||||||
|
|
||||||
buyStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
buyStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
||||||
{['text'] = stat[4], ['width'] = 270}})
|
{['text'] = lowestPrice, ['width'] = 270}})
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -228,9 +261,8 @@ local function updateSelectedItem(newItem)
|
||||||
if Market.isItemSelected() then
|
if Market.isItemSelected() then
|
||||||
selectedItem:setItem(selectedItem.item.ptr)
|
selectedItem:setItem(selectedItem.item.ptr)
|
||||||
nameLabel:setText(selectedItem.item.marketData.name)
|
nameLabel:setText(selectedItem.item.marketData.name)
|
||||||
-- update offer types
|
|
||||||
Market.enableCreateOffer(true)
|
|
||||||
|
|
||||||
|
Market.enableCreateOffer(true)-- update offer types
|
||||||
MarketProtocol.sendMarketBrowse(selectedItem.item.ptr:getId()) -- send browsed msg
|
MarketProtocol.sendMarketBrowse(selectedItem.item.ptr:getId()) -- send browsed msg
|
||||||
else
|
else
|
||||||
Market.Market.clearSelectedItem()
|
Market.Market.clearSelectedItem()
|
||||||
|
@ -251,6 +283,42 @@ 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 depotItemCount <= 100 and depotItemCount >= amount then
|
||||||
|
if (depotItemCount - amount) <= 0 then
|
||||||
|
table.remove(information.depotItems, i)
|
||||||
|
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 i = 1, removeCount do
|
||||||
|
if i == removeCount and remainder > 0 then
|
||||||
|
updateDepotItemCount(itemId, remainder)
|
||||||
|
else
|
||||||
|
updateDepotItemCount(itemId, 100)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
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
|
||||||
|
@ -272,13 +340,13 @@ local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
|
||||||
|
|
||||||
local offer = selectedOffer[MarketAction.Sell]
|
local offer = selectedOffer[MarketAction.Sell]
|
||||||
if offer then
|
if offer then
|
||||||
if offer:getPrice() > information.balance then
|
if offer:getTotalPrice() > information.balance then
|
||||||
balanceLabel:setColor('#b22222')
|
balanceLabel:setColor('#b22222')
|
||||||
else
|
else
|
||||||
local slice = (information.balance / 2)
|
local slice = (information.balance / 2)
|
||||||
if (offer:getPrice()/slice) * 100 <= 40 then
|
if (offer:getTotalPrice()/slice) * 100 <= 40 then
|
||||||
color = '#008b00' -- green
|
color = '#008b00' -- green
|
||||||
elseif (offer:getPrice()/slice) * 100 <= 70 then
|
elseif (offer:getTotalPrice()/slice) * 100 <= 70 then
|
||||||
color = '#eec900' -- yellow
|
color = '#eec900' -- yellow
|
||||||
else
|
else
|
||||||
color = '#ee9a00' -- orange
|
color = '#ee9a00' -- orange
|
||||||
|
@ -313,10 +381,9 @@ local function onChangeCategory(combobox, option)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onChangeSubCategory(combobox, option)
|
local function onChangeSubCategory(combobox, option)
|
||||||
local id = getMarketCategoryId(option)
|
Market.loadMarketItems(getMarketCategoryId(option))
|
||||||
Market.loadMarketItems(id)
|
|
||||||
-- setup slot filter
|
|
||||||
slotFilterList:clearOptions()
|
slotFilterList:clearOptions()
|
||||||
|
|
||||||
local subId = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
local subId = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
||||||
local slots = MarketCategoryWeapons[subId].slots
|
local slots = MarketCategoryWeapons[subId].slots
|
||||||
for _, slot in pairs(slots) do
|
for _, slot in pairs(slots) do
|
||||||
|
@ -504,8 +571,8 @@ function init()
|
||||||
g_ui.importStyle('ui/general/markettabs.otui')
|
g_ui.importStyle('ui/general/markettabs.otui')
|
||||||
g_ui.importStyle('ui/general/marketbuttons.otui')
|
g_ui.importStyle('ui/general/marketbuttons.otui')
|
||||||
g_ui.importStyle('ui/general/marketcombobox.otui')
|
g_ui.importStyle('ui/general/marketcombobox.otui')
|
||||||
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)
|
||||||
marketWindow:hide()
|
marketWindow:hide()
|
||||||
|
@ -544,7 +611,7 @@ function Market.clearSelectedItem()
|
||||||
nameLabel:setText('No item selected.')
|
nameLabel:setText('No item selected.')
|
||||||
|
|
||||||
selectedItem:setItem(nil)
|
selectedItem:setItem(nil)
|
||||||
selectedItem.item = {}
|
selectedItem = {}
|
||||||
|
|
||||||
detailsTable:clearData()
|
detailsTable:clearData()
|
||||||
buyStatsTable:clearData()
|
buyStatsTable:clearData()
|
||||||
|
@ -562,7 +629,7 @@ function Market.depotContains(itemId)
|
||||||
local count = 0
|
local count = 0
|
||||||
for i = 1, #information.depotItems do
|
for i = 1, #information.depotItems do
|
||||||
local item = information.depotItems[i]
|
local item = information.depotItems[i]
|
||||||
if item.ptr:getId() == itemId then
|
if item and item.ptr:getId() == itemId then
|
||||||
count = count + item.ptr:getCount()
|
count = count + item.ptr:getCount()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -633,6 +700,7 @@ function Market.refreshItemsWidget(selectItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
local itemWidget = itemBox:getChildById('item')
|
local itemWidget = itemBox:getChildById('item')
|
||||||
|
item.ptr:setCount(1) -- reset item count for image
|
||||||
itemWidget:setItem(item.ptr)
|
itemWidget:setItem(item.ptr)
|
||||||
local amount = Market.depotContains(item.ptr:getId())
|
local amount = Market.depotContains(item.ptr:getId())
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
|
@ -674,10 +742,12 @@ function Market.loadDepotItems(depotItems)
|
||||||
local data = depotItems[i]
|
local data = depotItems[i]
|
||||||
local id, count = data[1], data[2]
|
local id, count = data[1], data[2]
|
||||||
|
|
||||||
local newItem = nil
|
|
||||||
if count > 100 then
|
if count > 100 then
|
||||||
local createCount = math.floor(count/100)
|
local createCount = math.floor(count/100)
|
||||||
local remainder = count % 100
|
local remainder = count % 100
|
||||||
|
if remainder > 0 then
|
||||||
|
createCount = createCount + 1
|
||||||
|
end
|
||||||
for i = 1, createCount do
|
for i = 1, createCount do
|
||||||
local newItem = Item.create(id)
|
local newItem = Item.create(id)
|
||||||
if i == createCount and remainder > 0 then
|
if i == createCount and remainder > 0 then
|
||||||
|
@ -718,7 +788,9 @@ function Market.createNewOffer()
|
||||||
if not Market.isItemSelected() then
|
if not Market.isItemSelected() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local spriteId = selectedItem.item.ptr:getId()
|
local item = selectedItem.item
|
||||||
|
local spriteId = item.ptr:getId()
|
||||||
|
|
||||||
local piecePrice = piecePriceEdit:getValue()
|
local piecePrice = piecePriceEdit:getValue()
|
||||||
local totalPrice = totalPriceEdit:getValue()
|
local totalPrice = totalPriceEdit:getValue()
|
||||||
local amount = amountEdit:getValue()
|
local amount = amountEdit:getValue()
|
||||||
|
@ -742,7 +814,10 @@ function Market.createNewOffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
|
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
|
||||||
|
if type == MarketAction.Sell then
|
||||||
|
updateDepotItemCount(spriteId, amount) -- remove count from depot tmp
|
||||||
Market.refreshItemsWidget(spriteId)
|
Market.refreshItemsWidget(spriteId)
|
||||||
|
end
|
||||||
Market.resetCreateOffer()
|
Market.resetCreateOffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -769,6 +844,12 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
||||||
Market.loadDepotItems(depotItems)
|
Market.loadDepotItems(depotItems)
|
||||||
if table.empty(currentItems) then
|
if table.empty(currentItems) then
|
||||||
Market.loadMarketItems(MarketCategory.First)
|
Market.loadMarketItems(MarketCategory.First)
|
||||||
|
--[[else
|
||||||
|
-- TODO: Create function to handle this on showing market (seperate from parsing!)
|
||||||
|
if Market.isItemSelected() then
|
||||||
|
local spriteId = selectedItem.item.ptr:getId()
|
||||||
|
Market.refreshItemsWidget(spriteId)
|
||||||
|
end]]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- build offer table header
|
-- build offer table header
|
||||||
|
|
|
@ -4,6 +4,6 @@ Module
|
||||||
author: BeniS
|
author: BeniS
|
||||||
website: www.otclient.info
|
website: www.otclient.info
|
||||||
sandboxed: true
|
sandboxed: true
|
||||||
scripts: [marketoffer.lua, marketprotocol.lua, market.lua]
|
scripts: [offerstatistic.lua, marketoffer.lua, marketprotocol.lua, market.lua]
|
||||||
@onLoad: init()
|
@onLoad: init()
|
||||||
@onUnload: terminate()
|
@onUnload: terminate()
|
||||||
|
|
|
@ -3,8 +3,8 @@ MarketWindow < MainWindow
|
||||||
!text: tr('Market')
|
!text: tr('Market')
|
||||||
size: 700 510
|
size: 700 510
|
||||||
|
|
||||||
@onEnter: self:hide() self:unlock() Market.clearSelectedItem()
|
@onEnter: self:hide() self:unlock() Market.clearSelectedItem() MarketProtocol.sendMarketLeave()
|
||||||
@onEscape: self:hide() self:unlock() Market.clearSelectedItem()
|
@onEscape: self:hide() self:unlock() Market.clearSelectedItem() MarketProtocol.sendMarketLeave()
|
||||||
|
|
||||||
// Main Panel Window
|
// Main Panel Window
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ MarketOffer.__index = MarketOffer
|
||||||
local OFFER_TIMESTAMP = 1
|
local OFFER_TIMESTAMP = 1
|
||||||
local OFFER_COUNTER = 2
|
local OFFER_COUNTER = 2
|
||||||
|
|
||||||
MarketOffer.new = function(offerId, action, item, amount, price, playerName, state)
|
MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
|
||||||
local offer = {
|
local offer = {
|
||||||
id = {},
|
id = {},
|
||||||
action = nil,
|
type = nil,
|
||||||
item = 0,
|
item = 0,
|
||||||
amount = 0,
|
amount = 0,
|
||||||
price = 0,
|
price = 0,
|
||||||
|
@ -20,11 +20,11 @@ MarketOffer.new = function(offerId, action, item, amount, price, playerName, sta
|
||||||
end
|
end
|
||||||
offer.id = offerId
|
offer.id = offerId
|
||||||
|
|
||||||
action = tonumber(action)
|
t = tonumber(t)
|
||||||
if action ~= MarketAction.Buy and action ~= MarketAction.Sell then
|
if t ~= MarketAction.Buy and t ~= MarketAction.Sell then
|
||||||
g_logger.error('MarketOffer.new - invalid action provided.')
|
g_logger.error('MarketOffer.new - invalid type provided.')
|
||||||
end
|
end
|
||||||
offer.action = action
|
offer.type = t
|
||||||
|
|
||||||
if not item then
|
if not item then
|
||||||
g_logger.error('MarketOffer.new - invalid item provided.')
|
g_logger.error('MarketOffer.new - invalid item provided.')
|
||||||
|
@ -71,15 +71,15 @@ function MarketOffer:getId()
|
||||||
return self.id
|
return self.id
|
||||||
end
|
end
|
||||||
|
|
||||||
function MarketOffer:setAction(action)
|
function MarketOffer:setType(t)
|
||||||
if not action or type(action) ~= 'number' then
|
if not t or type(t) ~= 'number' then
|
||||||
g_logger.error('MarketOffer.setItem - invalid action id provided.')
|
g_logger.error('MarketOffer.setItem - invalid type provided.')
|
||||||
end
|
end
|
||||||
self.action = action
|
self.type = type
|
||||||
end
|
end
|
||||||
|
|
||||||
function MarketOffer:getAction()
|
function MarketOffer:getType()
|
||||||
return self.action
|
return self.type
|
||||||
end
|
end
|
||||||
|
|
||||||
function MarketOffer:setItem(item)
|
function MarketOffer:setItem(item)
|
||||||
|
@ -115,6 +115,10 @@ function MarketOffer:getPrice()
|
||||||
return self.price
|
return self.price
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MarketOffer:getTotalPrice()
|
||||||
|
return self.price * self.amount
|
||||||
|
end
|
||||||
|
|
||||||
function MarketOffer:setPlayer(player)
|
function MarketOffer:setPlayer(player)
|
||||||
if not player or type(player) ~= 'number' then
|
if not player or type(player) ~= 'number' then
|
||||||
g_logger.error('MarketOffer.setPlayer - invalid player provided.')
|
g_logger.error('MarketOffer.setPlayer - invalid player provided.')
|
||||||
|
|
|
@ -3,6 +3,7 @@ MarketProtocol = {}
|
||||||
-- private functions
|
-- private functions
|
||||||
|
|
||||||
local protocol
|
local protocol
|
||||||
|
local statistics = runinsandbox('offerstatistic.lua')
|
||||||
|
|
||||||
local function send(msg)
|
local function send(msg)
|
||||||
if protocol then
|
if protocol then
|
||||||
|
@ -72,27 +73,30 @@ local function parseMarketDetail(msg)
|
||||||
msg:getU16()
|
msg:getU16()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local time = (os.time() / 1000) * statistics.SECONDS_PER_DAY;
|
||||||
|
|
||||||
local purchaseStats = {}
|
local purchaseStats = {}
|
||||||
local count = msg:getU8()
|
local count = msg:getU8()
|
||||||
for i=1,count do
|
for i=1, count do
|
||||||
local transactions = msg:getU32() -- transaction count
|
local transactions = msg:getU32() -- transaction count
|
||||||
local totalPrice = msg:getU32() -- total price
|
local totalPrice = msg:getU32() -- total price
|
||||||
local highestPrice = msg:getU32() -- highest price
|
local highestPrice = msg:getU32() -- highest price
|
||||||
local lowestPrice = msg: getU32() -- lowest price
|
local lowestPrice = msg:getU32() -- lowest price
|
||||||
|
|
||||||
table.insert(purchaseStats, {transactions, totalPrice, highestPrice, lowestPrice})
|
local tmp = time - statistics.SECONDS_PER_DAY
|
||||||
|
table.insert(purchaseStats, OfferStatistic.new(tmp, MarketAction.Buy, transactions, totalPrice, highestPrice, lowestPrice))
|
||||||
end
|
end
|
||||||
|
|
||||||
local saleStats = {}
|
local saleStats = {}
|
||||||
count = msg:getU8()
|
count = msg:getU8()
|
||||||
for i=1,count do
|
for i=1, count do
|
||||||
local transactions = msg:getU32() -- transaction count
|
local transactions = msg:getU32() -- transaction count
|
||||||
local totalPrice = msg:getU32() -- total price
|
local totalPrice = msg:getU32() -- total price
|
||||||
local highestPrice = msg:getU32() -- highest price
|
local highestPrice = msg:getU32() -- highest price
|
||||||
local lowestPrice = msg: getU32() -- lowest price
|
local lowestPrice = msg:getU32() -- lowest price
|
||||||
|
|
||||||
table.insert(saleStats, {transactions, totalPrice, highestPrice, lowestPrice})
|
local tmp = time - statistics.SECONDS_PER_DAY
|
||||||
|
table.insert(saleStats, OfferStatistic.new(tmp, MarketAction.Sell, transactions, totalPrice, highestPrice, lowestPrice))
|
||||||
end
|
end
|
||||||
|
|
||||||
signalcall(Market.onMarketDetail, itemId, descriptions, purchaseStats, saleStats)
|
signalcall(Market.onMarketDetail, itemId, descriptions, purchaseStats, saleStats)
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
OfferStatistic = {}
|
||||||
|
OfferStatistic.__index = OfferStatistic
|
||||||
|
|
||||||
|
SECONDS_PER_DAY = 86400
|
||||||
|
|
||||||
|
OfferStatistic.new = function(timestamp, t, transactions, totalPrice, highestPrice, lowestPrice)
|
||||||
|
local stat = {
|
||||||
|
time = 0,
|
||||||
|
type = nil,
|
||||||
|
transactions = 0,
|
||||||
|
totalPrice = 0,
|
||||||
|
highestPrice = 0,
|
||||||
|
lowestPrice = 0
|
||||||
|
}
|
||||||
|
stat.time = math.floor(timestamp / SECONDS_PER_DAY) * SECONDS_PER_DAY
|
||||||
|
|
||||||
|
if t ~= MarketAction.Buy and t ~= MarketAction.Sell then
|
||||||
|
g_logger.error('OfferStatistic.new - invalid type provided.')
|
||||||
|
end
|
||||||
|
stat.type = t
|
||||||
|
|
||||||
|
stat.transactions = transactions
|
||||||
|
stat.totalPrice = totalPrice
|
||||||
|
stat.highestPrice = highestPrice
|
||||||
|
stat.lowestPrice = lowestPrice
|
||||||
|
|
||||||
|
setmetatable(stat, OfferStatistic)
|
||||||
|
return stat
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:isNull()
|
||||||
|
return self.time == 0 or not self.type
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sets/Gets
|
||||||
|
|
||||||
|
function OfferStatistic:setTime(time)
|
||||||
|
if not time or type(time) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setTime - invalid time provided.')
|
||||||
|
end
|
||||||
|
self.time = time
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getTime()
|
||||||
|
return self.time
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:setType(t)
|
||||||
|
if not t or type(t) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setType - invalid type provided.')
|
||||||
|
end
|
||||||
|
self.type = t
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getType()
|
||||||
|
return self.type
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:setTransactions(transactions)
|
||||||
|
if not transactions or type(transactions) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setTransactions - invalid transactions provided.')
|
||||||
|
end
|
||||||
|
self.transactions = transactions
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getTransactions()
|
||||||
|
return self.transactions
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:setTotalPrice(amount)
|
||||||
|
if not totalPrice or type(totalPrice) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setTotalPrice - invalid total price provided.')
|
||||||
|
end
|
||||||
|
self.totalPrice = totalPrice
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getTotalPrice()
|
||||||
|
return self.totalPrice
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:setHighestPrice(highestPrice)
|
||||||
|
if not highestPrice or type(highestPrice) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setHighestPrice - invalid highestPrice provided.')
|
||||||
|
end
|
||||||
|
self.highestPrice = highestPrice
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getHighestPrice()
|
||||||
|
return self.highestPrice
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:setLowestPrice(lowestPrice)
|
||||||
|
if not lowestPrice or type(lowestPrice) ~= 'number' then
|
||||||
|
g_logger.error('OfferStatistic.setLowestPrice - invalid lowestPrice provided.')
|
||||||
|
end
|
||||||
|
self.lowestPrice = lowestPrice
|
||||||
|
end
|
||||||
|
|
||||||
|
function OfferStatistic:getLowestPrice()
|
||||||
|
return self.lowestPrice
|
||||||
|
end
|
|
@ -62,9 +62,10 @@ MiniWindow
|
||||||
enabled: true
|
enabled: true
|
||||||
@onClick: onButtonClick(self:getId())
|
@onClick: onButtonClick(self:getId())
|
||||||
|
|
||||||
ZoomInControl
|
ZoomOutControl
|
||||||
id: zoomIn
|
id: zoomOut
|
||||||
text: +
|
text: -
|
||||||
|
font: terminus-14px-bold
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin-right: 4
|
margin-right: 4
|
||||||
|
@ -72,10 +73,9 @@ MiniWindow
|
||||||
enabled: true
|
enabled: true
|
||||||
@onClick: onButtonClick(self:getId())
|
@onClick: onButtonClick(self:getId())
|
||||||
|
|
||||||
ZoomOutControl
|
ZoomInControl
|
||||||
id: zoomOut
|
id: zoomIn
|
||||||
text: -
|
text: +
|
||||||
font: terminus-14px-bold
|
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin-right: 4
|
margin-right: 4
|
||||||
|
|
Loading…
Reference in New Issue