mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
Added Market/MarketProtocol module to begin the construction of the Market! Fixed some Minor Issues, and Some Cosmetics
* Added new protocol lib. * Added missing Game Features to game/const.lua * Added new Market module that will handle the market/market protocols too. * Finished Market protocol and begun on the market structure (MarketOffer etc). * Removed any traces of market protocol in the core (I think). * Moved minimap images to /images. * Removed old zoom images for minimap. * Fixed a bug with randomize outfit.
This commit is contained in:
137
modules/game_market/marketoffer.lua
Normal file
137
modules/game_market/marketoffer.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
MarketOffer = {}
|
||||
MarketOffer.__index = MarketOffer
|
||||
|
||||
local OFFER_TIMESTAMP = 1
|
||||
local OFFER_COUNTER = 2
|
||||
|
||||
MarketOffer.new = function(offerId, action, itemId, amount, price, playerName, state)
|
||||
local offer = {
|
||||
id = {},
|
||||
action = nil,
|
||||
item = 0,
|
||||
amount = 0,
|
||||
price = 0,
|
||||
player = '',
|
||||
state = 0
|
||||
}
|
||||
|
||||
if not offerId or type(offerId) ~= 'table' then
|
||||
g_logger.error('MarketOffer.new - invalid offer id provided.')
|
||||
end
|
||||
offer.id = offerId
|
||||
|
||||
action = tonumber(action)
|
||||
if action ~= MarketAction.Buy and action ~= MarketAction.Sell then
|
||||
g_logger.error('MarketOffer.new - invalid action provided.')
|
||||
end
|
||||
offer.action = action
|
||||
|
||||
offer.item = itemId
|
||||
offer.amount = amount
|
||||
offer.price = price
|
||||
offer.player = playerName
|
||||
|
||||
state = tonumber(state)
|
||||
if state ~= MarketOfferState.Active and state ~= MarketOfferState.Cancelled
|
||||
and state ~= MarketOfferState.Expired and state ~= MarketOfferState.Accepted then
|
||||
g_logger.error('MarketOffer.new - invalid state provided.')
|
||||
end
|
||||
offer.state = state
|
||||
|
||||
setmetatable(offer, MarketOffer)
|
||||
return offer
|
||||
end
|
||||
|
||||
function MarketOffer:isEqual(offer)
|
||||
return self.offer[OFFER_TIMESTAMP] == offer[OFFER_TIMESTAMP] and self.offer[OFFER_COUNTER] == offer[OFFER_COUNTER]
|
||||
end
|
||||
|
||||
function MarketOffer:isLessThan(offer)
|
||||
return self.offer[OFFER_TIMESTAMP] <= offer[OFFER_TIMESTAMP] and self.offer[OFFER_COUNTER] < offer[OFFER_COUNTER]
|
||||
end
|
||||
|
||||
function MarketOffer:isNull(offer)
|
||||
return table.empty(self.id)
|
||||
end
|
||||
|
||||
-- Sets/Gets
|
||||
|
||||
function MarketOffer:setId(id)
|
||||
if not id or type(id) ~= 'table' then
|
||||
g_logger.error('MarketOffer.setId - invalid id provided.')
|
||||
end
|
||||
self.id = id
|
||||
end
|
||||
|
||||
function MarketOffer:getId()
|
||||
return self.id
|
||||
end
|
||||
|
||||
function MarketOffer:setItem(item)
|
||||
if not item or type(item) ~= 'number' then
|
||||
g_logger.error('MarketOffer.setItem - invalid item id provided.')
|
||||
end
|
||||
self.item = item
|
||||
end
|
||||
|
||||
function MarketOffer:getItem()
|
||||
return self.item
|
||||
end
|
||||
|
||||
function MarketOffer:setAmount(amount)
|
||||
if not amount or type(amount) ~= 'number' then
|
||||
g_logger.error('MarketOffer.setAmount - invalid amount provided.')
|
||||
end
|
||||
self.amount = amount
|
||||
end
|
||||
|
||||
function MarketOffer:getAmount()
|
||||
return self.amount
|
||||
end
|
||||
|
||||
function MarketOffer:setPrice(price)
|
||||
if not price or type(price) ~= 'number' then
|
||||
g_logger.error('MarketOffer.setPrice - invalid price provided.')
|
||||
end
|
||||
self.price = price
|
||||
end
|
||||
|
||||
function MarketOffer:getPrice()
|
||||
return self.price
|
||||
end
|
||||
|
||||
function MarketOffer:setPlayer(player)
|
||||
if not player or type(player) ~= 'number' then
|
||||
g_logger.error('MarketOffer.setPlayer - invalid player provided.')
|
||||
end
|
||||
self.player = player
|
||||
end
|
||||
|
||||
function MarketOffer:getPlayer()
|
||||
return self.player
|
||||
end
|
||||
|
||||
function MarketOffer:setState(state)
|
||||
if not state or type(state) ~= 'number' then
|
||||
g_logger.error('MarketOffer.setState - invalid state provided.')
|
||||
end
|
||||
self.state = state
|
||||
end
|
||||
|
||||
function MarketOffer:getState()
|
||||
return self.state
|
||||
end
|
||||
|
||||
function MarketOffer:getTimeStamp()
|
||||
if table.empty(self.id) or #self.id < OFFER_TIMESTAMP then
|
||||
return
|
||||
end
|
||||
return self.id[OFFER_TIMESTAMP]
|
||||
end
|
||||
|
||||
function MarketOffer:getCounter()
|
||||
if table.empty(self.id) or #self.id < OFFER_COUNTER then
|
||||
return
|
||||
end
|
||||
return self.id[OFFER_COUNTER]
|
||||
end
|
Reference in New Issue
Block a user