|
|
|
@ -26,6 +26,9 @@ local ignoreCapacity = false
|
|
|
|
|
local ignoreEquipped = true
|
|
|
|
|
local showOnlyHolding = false
|
|
|
|
|
|
|
|
|
|
local CURRENCY = 'gold'
|
|
|
|
|
local WEIGHT_UNIT = 'oz'
|
|
|
|
|
|
|
|
|
|
-- public functions
|
|
|
|
|
function NPCTrade.init()
|
|
|
|
|
cacheItems = {}
|
|
|
|
@ -85,7 +88,8 @@ function NPCTrade.terminate()
|
|
|
|
|
cacheItems = nil
|
|
|
|
|
cacheGoods = nil
|
|
|
|
|
|
|
|
|
|
disconnect(g_game, { onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
|
|
|
|
|
disconnect(g_game, { onGameEnd = NPCTrade.hide,
|
|
|
|
|
onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
|
|
|
|
|
onPlayerGoods = NPCTrade.onPlayerGoods,
|
|
|
|
|
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
|
|
|
|
|
end
|
|
|
|
@ -129,9 +133,13 @@ function NPCTrade.updateSetup()
|
|
|
|
|
if offerSelected then
|
|
|
|
|
if radioItems.selectedWidget:isEnabled() then
|
|
|
|
|
if setupButton:getText() == 'Buy' then
|
|
|
|
|
quantityScroll:setMaximum(math.max(0, math.min(100, math.floor(moneyGoods/NPCTrade.getOfferPrice(offerSelected)))))
|
|
|
|
|
else
|
|
|
|
|
quantityScroll:setMaximum(math.max(0, math.min(100, cacheGoods[offerSelected[1]:getId()])))
|
|
|
|
|
local capacityMaxCount = math.floor(100*g_game.getLocalPlayer():getFreeCapacity()/offerSelected[3])
|
|
|
|
|
local priceMaxCount = math.floor(moneyGoods/NPCTrade.getOfferPrice(offerSelected))
|
|
|
|
|
quantityScroll:setMaximum(math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount))))
|
|
|
|
|
else
|
|
|
|
|
if cacheGoods[offerSelected[1]:getId()] then -- list might be empty.
|
|
|
|
|
quantityScroll:setMaximum(math.max(0, math.min(100, cacheGoods[offerSelected[1]:getId()])))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
NPCTrade.resetSetup()
|
|
|
|
@ -163,9 +171,9 @@ function NPCTrade.setItem(widget)
|
|
|
|
|
local price = NPCTrade.getOfferPrice(widget.offer)
|
|
|
|
|
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
|
|
|
|
|
nameLabel:setText(offer[2])
|
|
|
|
|
weightLabel:setText(string.format("%.2f", offer[3]/100) .. " oz")
|
|
|
|
|
priceLabel:setText(price .. " gold")
|
|
|
|
|
capacityLabel:setText(string.format("%.2f", freeCapacity) .. " oz")
|
|
|
|
|
weightLabel:setText(string.format('%.2f', offer[3]/100) .. ' ' .. WEIGHT_UNIT)
|
|
|
|
|
priceLabel:setText(price .. ' ' .. CURRENCY)
|
|
|
|
|
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
|
|
|
|
|
|
|
|
|
|
quantityLabel:setText(1)
|
|
|
|
|
quantityScroll:setValue(1)
|
|
|
|
@ -178,8 +186,8 @@ function NPCTrade.setQuantity(quantity)
|
|
|
|
|
if quantityLabel and offerSelected then
|
|
|
|
|
local price = NPCTrade.getOfferPrice(offerSelected)
|
|
|
|
|
quantityLabel:setText(quantity)
|
|
|
|
|
weightLabel:setText(string.format("%.2f", offerSelected[3]*quantity/100) .. " oz")
|
|
|
|
|
priceLabel:setText(price .. " gold")
|
|
|
|
|
weightLabel:setText(string.format('%.2f', offerSelected[3]*quantity/100) .. ' ' .. WEIGHT_UNIT)
|
|
|
|
|
priceLabel:setText(price .. ' ' .. CURRENCY)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -209,7 +217,7 @@ end
|
|
|
|
|
function NPCTrade.switchBuyWithBackpack()
|
|
|
|
|
buyWithBackpack = not buyWithBackpack
|
|
|
|
|
if offerSelected then
|
|
|
|
|
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. " gold")
|
|
|
|
|
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. ' ' .. CURRENCY)
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
@ -251,8 +259,8 @@ function NPCTrade.createItemsOnPanel()
|
|
|
|
|
itemBox.offer = v
|
|
|
|
|
itemBox:getChildById('item'):setItem(v[1])
|
|
|
|
|
itemBox:getChildById('nameLabel'):setText(v[2])
|
|
|
|
|
itemBox:getChildById('weightLabel'):setText(string.format("%.2f", v[3]/100) .. " oz")
|
|
|
|
|
itemBox:getChildById('priceLabel'):setText(price .. " gold")
|
|
|
|
|
itemBox:getChildById('weightLabel'):setText(string.format('%.2f', v[3]/100) .. ' ' .. WEIGHT_UNIT)
|
|
|
|
|
itemBox:getChildById('priceLabel'):setText(price .. ' ' .. CURRENCY)
|
|
|
|
|
|
|
|
|
|
itemBox.onMouseRelease = NPCTrade.itemPopup
|
|
|
|
|
itemBox:getChildById('item').onMouseRelease = function (self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end
|
|
|
|
@ -282,7 +290,7 @@ function NPCTrade.refreshFilters()
|
|
|
|
|
local items = itemsPanel:getChildCount()
|
|
|
|
|
for i = 1, items do
|
|
|
|
|
local itemWidget = itemsPanel:getChildByIndex(i)
|
|
|
|
|
if filter ~= "" then
|
|
|
|
|
if filter ~= '' then
|
|
|
|
|
if string.find(itemWidget.offer[2], filter) and NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
|
|
|
|
|
itemWidget:show()
|
|
|
|
|
else
|
|
|
|
@ -325,9 +333,9 @@ end
|
|
|
|
|
function NPCTrade.onPlayerGoods(money, goods)
|
|
|
|
|
moneyGoods = money
|
|
|
|
|
|
|
|
|
|
moneyLabel:setText(money .. " gold")
|
|
|
|
|
moneyLabel:setText(money .. ' ' .. CURRENCY)
|
|
|
|
|
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
|
|
|
|
|
capacityLabel:setText(string.format("%.2f", freeCapacity) .. " oz")
|
|
|
|
|
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
|
|
|
|
|
|
|
|
|
|
cacheGoods = {}
|
|
|
|
|
for i,v in pairs(goods) do
|
|
|
|
|