@ -1,33 +1,201 @@
NPCTrade = { }
NPCTrade = { }
-- private variables
local BUY = 1
local SELL = 2
local CURRENCY = ' gold '
local WEIGHT_UNIT = ' oz '
local LAST_INVENTORY = 10
local npcWindow
local npcWindow
local itemsPanel
local itemsPanel
local radioTabs
local radioTabs
local radioItems
local radioItems
local buyTab
local sellTab
local searchText
local searchText
local setupPanel
local setupPanel
local quantity
local quantity
local quantityScroll
local quantityScroll
local nameLabel
local nameLabel
local priceLabel
local priceLabel
local moneyGoods
local moneyLabel
local moneyLabel
local weightLabel
local weightLabel
local capacityLabel
local capacityLabel
local offerSelected
local tradeButton
local setupButton
local buyTab
local cacheItems
local sellTab
local cacheGoods
local buyWithBackpack = false
local buyWithBackpack
local ignoreCapacity = false
local ignoreCapacity
local ignoreEquipped = true
local ignoreEquipped
local show OnlyHolding = false
local show AllItems
local CURRENCY = ' gold '
local playerFreeCapacity
local WEIGHT_UNIT = ' oz '
local playerMoney
local tradeItems = { }
local playerItems
local selectedItem
-- private functions
local function clearSelectedItem ( )
nameLabel : clearText ( )
weightLabel : clearText ( )
priceLabel : clearText ( )
quantityLabel : clearText ( )
tradeButton : disable ( )
quantityScroll : setMaximum ( 1 )
if selectedItem then
radioItems : selectWidget ( nil )
selectedItem = nil
end
end
local function getCurrentTradeType ( )
if tradeButton : getText ( ) == tr ( ' Buy ' ) then
return BUY
else
return SELL
end
end
local function getItemPrice ( item )
if getCurrentTradeType ( ) == BUY then
if buyWithBackpack : isChecked ( ) then
if item.ptr : isStackable ( ) then
return item.price * quantityScroll : getValue ( ) + 20 ;
else
return item.price * quantityScroll : getValue ( ) + math.ceil ( quantityScroll : getValue ( ) / 20 ) * 20
end
end
end
return item.price * quantityScroll : getValue ( )
end
local function getSellQuantity ( item )
if not playerItems [ item.ptr : getId ( ) ] then
return 0
end
local removeAmount = 0
if ignoreEquipped : isChecked ( ) then
local localPlayer = g_game.getLocalPlayer ( )
for i = 1 , LAST_INVENTORY do
local inventoryItem = localPlayer : getInventoryItem ( i )
if inventoryItem and inventoryItem : getId ( ) == item.ptr : getId ( ) then
removeAmount = removeAmount + inventoryItem : getCount ( )
end
end
end
return playerItems [ item.ptr : getId ( ) ] - removeAmount
end
local function canTradeItem ( item )
if getCurrentTradeType ( ) == BUY then
return ( ignoreCapacity : isChecked ( ) or ( not ignoreCapacity : isChecked ( ) and playerFreeCapacity >= item.weight ) ) and playerMoney >= getItemPrice ( item )
else
return getSellQuantity ( item ) > 0
end
end
local function refreshItem ( item )
nameLabel : setText ( item.name )
weightLabel : setText ( string.format ( ' %.2f ' , item.weight ) .. ' ' .. WEIGHT_UNIT )
priceLabel : setText ( getItemPrice ( item ) .. ' ' .. CURRENCY )
quantityLabel : setText ( 1 )
quantityScroll : setValue ( 1 )
if getCurrentTradeType ( ) == BUY then
local capacityMaxCount = math.floor ( playerFreeCapacity / item.weight )
if ignoreCapacity : isChecked ( ) then
capacityMaxCount = 100
end
local priceMaxCount = math.floor ( playerMoney / getItemPrice ( item ) )
quantityScroll : setMaximum ( math.max ( 0 , math.min ( 100 , math.min ( priceMaxCount , capacityMaxCount ) ) ) )
else
local removeAmount = 0
if ignoreEquipped : isChecked ( ) then
local localPlayer = g_game.getLocalPlayer ( )
for i = 1 , LAST_INVENTORY do
local inventoryItem = localPlayer : getInventoryItem ( i )
if inventoryItem and inventoryItem : getId ( ) == item.ptr : getId ( ) then
removeAmount = removeAmount + inventoryItem : getCount ( )
end
end
end
quantityScroll : setMaximum ( math.max ( 0 , math.min ( 100 , getSellQuantity ( item ) ) ) )
end
setupPanel : enable ( )
end
local function refreshTradeItems ( )
local layout = itemsPanel : getLayout ( )
layout : disableUpdates ( )
clearSelectedItem ( )
searchText : clearText ( )
setupPanel : disable ( )
itemsPanel : destroyChildren ( )
if radioItems then
radioItems : destroy ( )
end
radioItems = RadioGroup.create ( )
local currentTradeItems = tradeItems [ getCurrentTradeType ( ) ]
for key , item in pairs ( currentTradeItems ) do
local itemBox = createWidget ( ' NPCItemBox ' , itemsPanel )
itemBox.item = item
itemBox : getChildById ( ' item ' ) : setItem ( item.ptr )
itemBox : getChildById ( ' nameLabel ' ) : setText ( item.name )
itemBox : getChildById ( ' weightLabel ' ) : setText ( string.format ( ' %.2f ' , item.weight ) .. ' ' .. WEIGHT_UNIT )
itemBox : getChildById ( ' priceLabel ' ) : setText ( item.price .. ' ' .. CURRENCY )
itemBox.onMouseRelease = NPCTrade.itemPopup
itemBox : getChildById ( ' item ' ) . onMouseRelease = function ( self , mousePosition , mouseButton ) NPCTrade.itemPopup ( itemBox , mousePosition , mouseButton ) end
radioItems : addWidget ( itemBox )
end
layout : enableUpdates ( )
layout : update ( )
end
local function refreshPlayerGoods ( )
moneyLabel : setText ( playerMoney .. ' ' .. CURRENCY )
capacityLabel : setText ( string.format ( ' %.2f ' , playerFreeCapacity ) .. ' ' .. WEIGHT_UNIT )
local currentTradeType = getCurrentTradeType ( )
local searchFilter = searchText : getText ( )
local foundSelectedItem = false
local items = itemsPanel : getChildCount ( )
for i = 1 , items do
local itemWidget = itemsPanel : getChildByIndex ( i )
local item = itemWidget.item
local canTrade = canTradeItem ( item )
itemWidget : setEnabled ( canTrade )
local searchCondition = ( searchFilter == ' ' ) or ( searchFilter ~= ' ' and string.find ( item.name , searchFilter ) ~= nil )
local showAllItemsCondition = ( currentTradeType == BUY ) or ( showAllItems : isChecked ( ) ) or ( currentTradeType == SELL and not showAllItems : isChecked ( ) and canTrade )
itemWidget : setVisible ( searchCondition and showAllItemsCondition )
if selectedItem == item and itemWidget : isEnabled ( ) and itemWidget : isVisible ( ) then
foundSelectedItem = true
end
end
if not foundSelectedItem then
clearSelectedItem ( )
end
if selectedItem then
refreshItem ( selectedItem )
end
end
-- public functions
-- public functions
function NPCTrade . init ( )
function NPCTrade . init ( )
@ -38,9 +206,7 @@ function NPCTrade.init()
npcWindow : setVisible ( false )
npcWindow : setVisible ( false )
itemsPanel = npcWindow : recursiveGetChildById ( ' itemsPanel ' )
itemsPanel = npcWindow : recursiveGetChildById ( ' itemsPanel ' )
buyTab = npcWindow : getChildById ( ' buyTab ' )
searchText = npcWindow : recursiveGetChildById ( ' searchText ' )
sellTab = npcWindow : getChildById ( ' sellTab ' )
searchText = npcWindow : getChildById ( ' searchText ' )
setupPanel = npcWindow : recursiveGetChildById ( ' setupPanel ' )
setupPanel = npcWindow : recursiveGetChildById ( ' setupPanel ' )
quantityLabel = setupPanel : getChildById ( ' quantity ' )
quantityLabel = setupPanel : getChildById ( ' quantity ' )
@ -50,18 +216,33 @@ function NPCTrade.init()
moneyLabel = setupPanel : getChildById ( ' money ' )
moneyLabel = setupPanel : getChildById ( ' money ' )
weightLabel = setupPanel : getChildById ( ' weight ' )
weightLabel = setupPanel : getChildById ( ' weight ' )
capacityLabel = setupPanel : getChildById ( ' capacity ' )
capacityLabel = setupPanel : getChildById ( ' capacity ' )
setupButton = setupPanel : getChildById ( ' setupButton ' )
tradeButton = npcWindow : recursiveGetChildById ( ' tradeButton ' )
buyWithBackpack = npcWindow : recursiveGetChildById ( ' buyWithBackpack ' )
ignoreCapacity = npcWindow : recursiveGetChildById ( ' ignoreCapacity ' )
ignoreEquipped = npcWindow : recursiveGetChildById ( ' ignoreEquipped ' )
showAllItems = npcWindow : recursiveGetChildById ( ' showAllItems ' )
buyTab = npcWindow : getChildById ( ' buyTab ' )
sellTab = npcWindow : getChildById ( ' sellTab ' )
radioTabs = RadioGroup.create ( )
radioTabs = RadioGroup.create ( )
radioTabs : addWidget ( buyTab )
radioTabs : addWidget ( buyTab )
radioTabs : addWidget ( sellTab )
radioTabs : addWidget ( sellTab )
radioTabs : selectWidget ( buyTab )
radioTabs : selectWidget ( buyTab )
radioTabs.onSelectionChange = NPCTrade.setList
radioTabs.onSelectionChange = NPCTrade.onTradeTypeChange
if g_game.isOnline ( ) then -- event wont be sent again when reloading modules
playerFreeCapacity = g_game.getLocalPlayer ( ) : getFreeCapacity ( )
end
connect ( g_game , { onGameEnd = NPCTrade.hide ,
connect ( g_game , { onGameEnd = NPCTrade.hide ,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade ,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade ,
onPlayerGoods = NPCTrade.onPlayerGoods ,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade ,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
onPlayerGoods = NPCTrade.onPlayerGoods } )
connect ( LocalPlayer , { onFreeCapacityChange = NPCTrade.onFreeCapacityChange ,
onInventoryChange = NPCTrade.onInventoryChange } )
end
end
function NPCTrade . terminate ( )
function NPCTrade . terminate ( )
@ -73,6 +254,8 @@ function NPCTrade.terminate()
buyButton = nil
buyButton = nil
sellButton = nil
sellButton = nil
searchText = nil
searchText = nil
buyTab = nil
sellTab = nil
setupPanel = nil
setupPanel = nil
quantityLabel = nil
quantityLabel = nil
@ -83,24 +266,28 @@ function NPCTrade.terminate()
weightLabel = nil
weightLabel = nil
capacityLabel = nil
capacityLabel = nil
offerSelected = nil
offerSelected = nil
setupButton = nil
tradeButton = nil
cacheItems = nil
cacheGoods = nil
buyTab = nil
sellTab = nil
disconnect ( g_game , { onGameEnd = NPCTrade.hide ,
disconnect ( g_game , { onGameEnd = NPCTrade.hide ,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade ,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade ,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade ,
onPlayerGoods = NPCTrade.onPlayerGoods ,
onPlayerGoods = NPCTrade.onPlayerGoods ,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
onFreeCapacityChange = NPCTrade.onFreeCapacityChange } )
disconnect ( LocalPlayer , { onFreeCapacityChange = NPCTrade.onFreeCapacityChange ,
onInventoryChange = NPCTrade.onInventoryChange } )
NPCTrade = nil
NPCTrade = nil
end
end
-- private functions
function NPCTrade . show ( )
function NPCTrade . show ( )
if g_game.isOnline ( ) then
if g_game.isOnline ( ) then
if # tradeItems [ BUY ] > 0 then
radioTabs : selectWidget ( buyTab )
else
radioTabs : selectWidget ( sellTab )
end
npcWindow : show ( )
npcWindow : show ( )
npcWindow : raise ( )
npcWindow : raise ( )
end
end
@ -110,246 +297,132 @@ function NPCTrade.hide()
npcWindow : hide ( )
npcWindow : hide ( )
end
end
function NPCTrade . setList ( radioTabs , selected , deselected )
function NPCTrade . onItemBoxChecked ( widget )
setupButton : setText ( selected : getText ( ) )
if widget : isChecked ( ) then
selected : setOn ( true )
local item = widget.item
deselected : setOn ( false )
selectedItem = item
NPCTrade.createItemsOnPanel ( )
refreshItem ( item )
tradeButton : enable ( )
NPCTrade.resetSetup ( )
NPCTrade.refreshItemsPanel ( )
NPCTrade.refreshFilters ( )
end
function NPCTrade . resetSetup ( )
nameLabel : clearText ( )
weightLabel : clearText ( )
priceLabel : clearText ( )
searchText : clearText ( )
if offerSelected then
radioItems.selectedWidget : setChecked ( false )
offerSelected = nil
end
end
setupPanel : disable ( )
end
end
function NPCTrade . updateSetup ( )
function NPCTrade . onQuantityValueChange ( quantity )
if offerSelected then
if quantityLabel and selectedItem then
if radioItems.selectedWidget : isEnabled ( ) then
quantityLabel : setText ( quantity )
if setupButton : getText ( ) == tr ( ' Buy ' ) then
weightLabel : setText ( string.format ( ' %.2f ' , selectedItem.weight * quantity ) .. ' ' .. WEIGHT_UNIT )
local capacityMaxCount = math.floor ( 100 * g_game.getLocalPlayer ( ) : getFreeCapacity ( ) / offerSelected [ 3 ] )
priceLabel : setText ( getItemPrice ( selectedItem ) .. ' ' .. CURRENCY )
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 ( )
end
end
end
function NPCTrade . getOfferPrice ( offer )
if setupButton : getText ( ) == tr ( ' Buy ' ) then
local price = offer [ 4 ]
if buyWithBackpack then
if offer [ 1 ] : isStackable ( ) then
return price * quantityScroll : getValue ( ) + 20 ;
else
return price * quantityScroll : getValue ( ) + math.ceil ( quantityScroll : getValue ( ) / 20 ) * 20
end
else
return price * quantityScroll : getValue ( )
end
else
return offer [ 5 ] * quantityScroll : getValue ( )
end
end
end
end
function NPCTrade . setItem ( widget )
function NPCTrade . onTradeTypeChange ( radioTabs , selected , deselected )
offerSelected = widget.offer
tradeButton : setText ( selected : getText ( ) )
selected : setOn ( true )
local offer = widget.offer
deselected : setOn ( false )
local price = NPCTrade.getOfferPrice ( widget.offer )
local freeCapacity = g_game.getLocalPlayer ( ) : getFreeCapacity ( )
nameLabel : setText ( offer [ 2 ] )
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 )
NPCTrade.updateSetup ( )
setupPanel : enable ( )
local currentTradeType = getCurrentTradeType ( )
end
buyWithBackpack : setVisible ( currentTradeType == BUY )
ignoreCapacity : setVisible ( currentTradeType == BUY )
ignoreEquipped : setVisible ( currentTradeType == SELL )
showAllItems : setVisible ( currentTradeType == SELL )
function NPCTrade . setQuantity ( quantity )
refreshTradeItems ( )
if quantityLabel and offerSelected then
refreshPlayerGoods ( )
local price = NPCTrade.getOfferPrice ( offerSelected )
quantityLabel : setText ( quantity )
weightLabel : setText ( string.format ( ' %.2f ' , offerSelected [ 3 ] * quantity / 100 ) .. ' ' .. WEIGHT_UNIT )
priceLabel : setText ( price .. ' ' .. CURRENCY )
end
end
end
function NPCTrade . setupButt on( )
function NPCTrade . onTradeClick ( )
if setupButton: getText ( ) == ' Buy ' then
if getCurrentTradeType ( ) == BUY then
g_game.buyItem ( offerSelected[ 1 ] , quantityScroll : getValue ( ) , buyWithBackpack , ignoreCapacity )
g_game.buyItem ( selectedItem.ptr , quantityScroll : getValue ( ) , buyWithBackpack : isChecked ( ) , ignoreCapacity : isChecked ( ) )
else
else
g_game.sellItem ( offerSelected[ 1 ] , quantityScroll : getValue ( ) , ignoreEquipped )
g_game.sellItem ( selectedItem.ptr , quantityScroll : getValue ( ) , ignoreEquipped : isChecked ( ) )
end
end
end
end
function NPCTrade . onOpenNpcTrade ( items )
function NPCTrade . onSearchTextChange ( )
-- items[item] = item
refreshPlayerGoods ( )
-- item[1] = ItemPtr
-- item[2] = name
-- item[3] = weight
-- item[4] = buyPrice
-- item[5] = sellPrice
cacheItems = items
NPCTrade.createItemsOnPanel ( )
NPCTrade.show ( )
end
function NPCTrade . switchBuyWithBackpack ( )
buyWithBackpack = not buyWithBackpack
if offerSelected then
priceLabel : setText ( NPCTrade.getOfferPrice ( offerSelected ) .. ' ' .. CURRENCY )
end
return true
end
end
function NPCTrade . itemPopup ( self , mousePosition , mouseButton )
function NPCTrade . itemPopup ( self , mousePosition , mouseButton )
if mouseButton == MouseRightButton then
if mouseButton == MouseRightButton then
local menu = createWidget ( ' PopupMenu ' )
local menu = createWidget ( ' PopupMenu ' )
menu : addOption ( tr ( ' Look ' ) , function ( ) return g_game.inspectNpcTrade ( self.offer [ 1 ] ) end )
menu : addOption ( tr ( ' Look ' ) , function ( ) return g_game.inspectNpcTrade ( self.offer [ 1 ] ) end )
menu : addSeparator ( )
if setupButton : getText ( ) == tr ( ' Buy ' ) then
menu : addOption ( ( buyWithBackpack and tr ( ' Buy no backpack ' ) or tr ( ' Buy with backpack ' ) ) , NPCTrade.switchBuyWithBackpack )
menu : addOption ( ( ignoreCapacity and tr ( ' Consider capacity ' ) or tr ( ' Ignore capacity ' ) ) , function ( ) ignoreCapacity = not ignoreCapacity return true end )
else
menu : addOption ( ( ignoreEquipped and tr ( ' Consider equipped ' ) or tr ( ' Ignore equipped ' ) ) , function ( ) ignoreEquipped = not ignoreEquipped return true end )
menu : addOption ( ( showOnlyHolding and tr ( ' Show all items ' ) or tr ( ' Show only holding items ' ) ) , function ( ) showOnlyHolding = not showOnlyHolding NPCTrade.refreshFilters ( ) return true end )
end
menu : display ( mousePosition )
menu : display ( mousePosition )
end
end
end
end
function NPCTrade . createItemsOnPanel ( )
function NPCTrade . onBuyWithBackpackChange ( )
local layout = itemsPanel : getLayout ( )
if selectedItem then
layout : disableUpdates ( )
refreshItem ( selectedItem )
NPCTrade.resetSetup ( )
offerSelected = nil
itemsPanel : destroyChildren ( )
if radioItems then
radioItems : destroy ( )
end
end
radioItems = RadioGroup.create ( )
end
for i , v in pairs ( cacheItems ) do
local price = NPCTrade.getOfferPrice ( v )
if price > 0 then
local itemBox = createWidget ( ' NPCItemBox ' , itemsPanel )
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 ) .. ' ' .. WEIGHT_UNIT )
itemBox : getChildById ( ' priceLabel ' ) : setText ( price .. ' ' .. CURRENCY )
itemBox.onMouseRelease = NPCTrade.itemPopup
function NPCTrade . onIgnoreCapacityChange ( )
itemBox : getChildById ( ' item ' ) . onMouseRelease = function ( self , mousePosition , mouseButton ) NPCTrade.itemPopup ( itemBox , mousePosition , mouseButton ) end
refreshPlayerGoods ( )
end
radioItems : addWidget ( itemBox )
function NPCTrade . onIgnoreEquippedChange ( )
end
refreshPlayerGoods ( )
end
end
layout : enableUpdates ( )
function NPCTrade . onShowAllItemsChange ( )
layout: update ( )
refreshPlayerGoods ( )
end
end
function NPCTrade . extraFilters ( widget , showOnlyHolding )
-- hooked functions
if setupButton : getText ( ) == tr ( ' Sell ' ) then
function NPCTrade . onOpenNpcTrade ( items )
if not showOnlyHolding or cacheGoods [ widget.offer [ 1 ] : getId ( ) ] then
tradeItems [ BUY ] = { }
return true
tradeItems [ SELL ] = { }
for key , item in pairs ( items ) do
local newItem = { }
newItem.ptr = item [ 1 ]
newItem.name = item [ 2 ]
newItem.weight = item [ 3 ] / 100
if item [ 4 ] >= 0 then
newItem.price = item [ 4 ]
table.insert ( tradeItems [ BUY ] , newItem )
elseif item [ 5 ] >= 0 then
newItem.price = item [ 5 ]
table.insert ( tradeItems [ SELL ] , newItem )
else
else
return false
error ( " server error: item name " .. item [ 1 ] .. " has neither buy or sell price. " )
end
end
end
end
return true
refreshTradeItems ( )
addEvent ( NPCTrade.show ) -- player goods has not been parsed yet
end
end
function NPCTrade . refreshFilters ( )
function NPCTrade . onCloseNpcTrade ( )
local filter = searchText : getText ( )
NPCTrade.hide ( )
local items = itemsPanel : getChildCount ( )
for i = 1 , items do
local itemWidget = itemsPanel : getChildByIndex ( i )
if filter ~= ' ' then
if string.find ( itemWidget.offer [ 2 ] , filter ) and NPCTrade.extraFilters ( itemWidget , showOnlyHolding ) then
itemWidget : show ( )
else
itemWidget : hide ( )
end
else
if NPCTrade.extraFilters ( itemWidget , showOnlyHolding ) then
itemWidget : show ( )
else
itemWidget : hide ( )
end
end
end
end
end
function NPCTrade . refreshItemsPanel ( )
function NPCTrade . onPlayerGoods ( money , items )
if setupButton : getText ( ) == tr ( ' Buy ' ) then
playerMoney = money
local items = itemsPanel : getChildCount ( )
for i = 1 , items do
playerItems = { }
local itemWidget = itemsPanel : getChildByIndex ( i )
for key , item in pairs ( items ) do
if moneyGoods < NPCTrade.getOfferPrice ( itemWidget.offer ) then
local id = item [ 1 ] : getId ( )
itemWidget : disable ( )
if not playerItems [ id ] then
else
playerItems [ id ] = item [ 2 ]
itemWidget : enable ( )
else
end
playerItems [ id ] = playerItems [ id ] + item [ 2 ]
end
else
local items = itemsPanel : getChildCount ( )
for i = 1 , items do
local itemWidget = itemsPanel : getChildByIndex ( i )
if cacheGoods [ itemWidget.offer [ 1 ] : getId ( ) ] then
itemWidget : enable ( )
else
itemWidget : disable ( )
end
end
end
end
end
end
function NPCTrade . onPlayerGoods ( money , goods )
refreshPlayerGoods ( )
moneyGoods = money
end
moneyLabel : setText ( money .. ' ' .. CURRENCY )
function NPCTrade . onFreeCapacityChange ( localPlayer , freeCapacity , oldFreeCapacity )
local freeCapacity = g_game.getLocalPlayer ( ) : getFreeCapacity ( )
playerFreeCapacity = freeCapacity
capacityLabel : setText ( string.format ( ' %.2f ' , freeCapacity ) .. ' ' .. WEIGHT_UNIT )
cacheGoods = { }
if npcWindow : isVisible ( ) then
for i , v in pairs ( goods ) do
refreshPlayerGoods ( )
cacheGoods [ v [ 1 ] : getId ( ) ] = v [ 2 ]
end
end
NPCTrade.refreshItemsPanel ( )
NPCTrade.updateSetup ( )
end
end
function NPCTrade . onCloseNpcTrade ( )
function NPCTrade . onInventoryChange ( inventory , item , oldeItem )
NPCTrade.hide ( )
if selectedItem then
refreshItem ( selectedItem )
end
end
end