Trade
IdleKit provides Currency
trading functionality via the Trade
Entity. Trade
allows players to exchange one type of ICurrency
for another. This functionality is often used to allow players to exchange their excess common Upgradeable Currencies
for soft (or any other type of) Currency
.
Relationships
Each Trade
Entity contains two arrays of input and output Tag Datas
. At runtime, when CalculateCurrencyAmounts(System.Int32)
is called, these input and output Tags are converted into concrete input and output Currencies
. This method also randomly selects which of these concrete input/output Currencies
to offer for exchange. After this, the MakeTrade
method can be called to perform the actual exchange of the Currencies
.
Note
CalculateCurrencyAmounts(System.Int32)
must be called prior to calling MakeTrade
. If this is not performed, then the IsValid
check will fail and no exchange can be made.
Valid Trades
A Trade
must be valid before an exchange can be made. This is indicated via the IsValid
method. A Trade
may be invalid for a number of reasons:
- There are no input
Currencies
loaded that match the input Tag Ids specified. - There are no output
Currencies
loaded that match the output Tag Ids specified. - None of the possible input
Currencies
are affordable. - None of the input
Currencies
areAvailable
orObtained
. - None of the output
Currencies
areAvailable
orObtained
.
Multiple Tags
The Trade
Entity supports the ability to specify multiple input/output Tags, which allows for specializing the types of ICurrency
that are offered by the Trade
. For example, a trade may specify that eligible input Currencies
should include both the Rare
and Generator
Tags. To do so, the Tag Ids for these currencies would be specified via the InputCurrencyTagIds
array. The same functionality can be applied to output currency Tags.
Note
Specifying multiple input or output Tags narrow down the eligible Currency
that is randomly chosen by the Trade
. If you wish to have two different tagged input Currency
trades for the same output Currency
, two Trade
Entities should be created.
Cost
The cost to the player in making an exchange via a Trade
is calculated based on the Input Amount
specified. The amount of output Currency
received by the player is then dictated by the Exchange Rate
for the Trade
which is specified via ExchangeRateMultiplierId
". For more information, refer to Exchange Rate Multiplier.
TradeData
TradeData
is the data used by the Trade
Entity. This is where the Ids for the input/output Tag Ids, the input cost of the Trade
and the Exchange Rate
Id would be specified.