Skip to main content
Skip to main content

BuyHandToolData

BuyHandToolData

Description

Class to store and sync the data that is required to buy a new handtool

Functions

buy

Description

Execute the purchase and load the handtool

Definition

buy(function? callback, table? callbackTarget, table? callbackArguments)

Arguments

function?callbackcallback that is called after all vehicles have been loaded (optional)
table?callbackTargetoptional callback target
table?callbackArgumentsoptional callback arguments

Code

function BuyHandToolData:buy(callback, callbackTarget, callbackArguments)
local data = HandToolLoadingData.new()
data:setStoreItem( self.storeItem)
data:setOwnerFarmId( self.ownerFarmId)
data:setHolder( self.holder)
data:load( self.onBought, self , { callback = callback, callbackTarget = callbackTarget, callbackArguments = callbackArguments } )
end

isValid

Description

Returns if all required data is set and the handtool can be bought

Definition

isValid()

Return Values

table?isValidis valid

Code

function BuyHandToolData:isValid()
if self.storeItem = = nil then
return false
end

if GS_IS_CONSOLE_VERSION and not fileExists( self.storeItem.xmlFilename) then
return false
end

return true
end

new

Description

Creates a new instance of BuyHandToolData

Definition

new()

Arguments

anycustomMt

Return Values

anyBuyHandToolDataBuyHandToolData instance

Code

function BuyHandToolData.new(customMt)
local self = setmetatable( { } , customMt or BuyHandToolData _mt)

self.storeItem = nil
self.isFreeOfCharge = false
self.ownerFarmId = AccessHandler.EVERYONE
self.price = 0
self.holder = nil

return self
end

readStream

Description

Read data from stream

Definition

readStream(integer streamId, table connection)

Arguments

integerstreamIdstreamId
tableconnectionconnection

Code

function BuyHandToolData:readStream(streamId, connection)
local xmlFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId))
self.storeItem = g_storeManager:getItemByXMLFilename( string.lower(xmlFilename))
self.isFreeOfCharge = streamReadBool(streamId)
self.ownerFarmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
end

setIsFreeOfCharge

Description

Sets if the handtool is free of charge (e.g. achievement)

Definition

setIsFreeOfCharge(boolean isFreeOfCharge)

Arguments

booleanisFreeOfChargeisFreeOfCharge

Code

function BuyHandToolData:setIsFreeOfCharge(isFreeOfCharge)
self.isFreeOfCharge = isFreeOfCharge
end

setOwnerFarmId

Description

Sets the owner of the handtool

Definition

setOwnerFarmId(integer ownerFarmId)

Arguments

integerownerFarmIdownerFarmId

Code

function BuyHandToolData:setOwnerFarmId(ownerFarmId)
self.ownerFarmId = ownerFarmId
end

setPrice

Description

Sets a custom price for the purchase

Definition

setPrice(integer price)

Arguments

integerpriceprice

Code

function BuyHandToolData:setPrice(price)
self.price = price
end

setStoreItem

Description

Sets the store item

Definition

setStoreItem(table storeItem)

Arguments

tablestoreItemstoreItem

Code

function BuyHandToolData:setStoreItem(storeItem)
self.storeItem = storeItem
end

updatePrice

Description

Updates to price depending on the store item + configurations

Definition

updatePrice()

Code

function BuyHandToolData:updatePrice()
self.price = g_currentMission.economyManager:getBuyPrice( self.storeItem)
end

writeStream

Description

Write data to stream

Definition

writeStream(integer streamId, table connection)

Arguments

integerstreamIdstreamId
tableconnectionconnection

Code

function BuyHandToolData:writeStream(streamId, connection)
streamWriteString(streamId, NetworkUtil.convertToNetworkFilename( self.storeItem.xmlFilename))
streamWriteBool(streamId, self.isFreeOfCharge)
streamWriteUIntN(streamId, self.ownerFarmId, FarmManager.FARM_ID_SEND_NUM_BITS)
end