Created
January 12, 2013 18:13
-
-
Save teliosdev/4519698 to your computer and use it in GitHub Desktop.
Steam's Currency Trading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 6: | |
var template = null; | |
var bAmountChanged = false; | |
var newAmount = parseInt( event.amount ); | |
var oldAmount = parseInt( event.old_amount ); | |
if ( event.amount == 0 ) | |
{ | |
template = bTheirAction ? EventLogRemoveThemTemplate : EventLogRemoveYouTemplate; | |
} | |
else if ( event.old_amount == 0 ) | |
{ | |
template = bTheirAction ? EventLogAddThemTemplate : EventLogAddYouTemplate; | |
} | |
else if ( newAmount > oldAmount ) | |
{ | |
bAmountChanged = true; | |
template = bTheirAction ? EventLogIncreaseCurrencyThemTemplate : EventLogIncreaseCurrencyYouTemplate; | |
} | |
else if ( newAmount < oldAmount ) | |
{ | |
bAmountChanged = true; | |
template = bTheirAction ? EventLogDecreaseCurrencyThemTemplate : EventLogDecreaseCurrencyYouTemplate; | |
} | |
var user = bTheirAction ? UserThem : UserYou; | |
var currency = user.FindCurrency( event.appid, event.contextid, event.currencyid ); | |
if ( !currency && user.BIsLoadingInventoryData() ) | |
{ | |
bNeedInventoryLoad = true; | |
break; | |
} | |
var currencyname = ( currency ) ? currency.name : 'Unknown Item'; | |
var formatFunc; | |
if ( CurrencyIsWalletFunds( currency ) ) | |
{ | |
if ( bTheirAction ) | |
{ | |
var bShouldConvert = typeof(g_rgWalletInfo) != 'undefined' && | |
g_rgWalletInfo['wallet_currency'] != g_rgWalletInfo['wallet_other_currency']; | |
var nNewAmountAfterFee = newAmount - CalculateFeeAmount( newAmount ); | |
if ( bShouldConvert ) | |
{ | |
nNewAmountAfterFee = ConvertToOurCurrencyForDisplay( nNewAmountAfterFee ); | |
} | |
var bPreviouslyOverMax = g_bWalletBalanceWouldBeOverMax; | |
g_bWalletBalanceWouldBeOverMax = newAmount > 0 && ( typeof(g_rgWalletInfo) != 'undefined' && nNewAmountAfterFee + g_rgWalletInfo['wallet_balance'] > g_rgWalletInfo['wallet_max_balance'] ); | |
if ( g_bWalletBalanceWouldBeOverMax ) | |
{ | |
strAfterEvent = | |
'<%1$s>Error:<%2$s> You can\'t accept %3$s\'s offer of %4$s. You currently have %5$s in your Steam Wallet, but this offer would put you over the maximum of %6$s.' | |
.replace( '%1$s', 'span class="warning"' ) | |
.replace( '%2$s', '/span' ) | |
.replace( '%3$s', g_strTradePartnerPersonaName ) | |
.replace( '%4$s', v_currencyformat( nNewAmountAfterFee, GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) ) | |
.replace( '%5$s', v_currencyformat( g_rgWalletInfo['wallet_balance'], GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) ) | |
.replace( '%6$s', v_currencyformat( g_rgWalletInfo['wallet_max_balance'], GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) ); | |
} | |
if ( g_bWalletBalanceWouldBeOverMax != bPreviouslyOverMax ) | |
{ | |
UpdateReadyButtons(); | |
} | |
} | |
// Don't show a currency name unless we're changing value ( ex: "increased the amount of Wallet Funds to $1.23" ) | |
currencyname = bAmountChanged ? 'Wallet Funds' : ''; | |
formatFunc = function( x ) { | |
var nPostFeeAmount = x - CalculateFeeAmount( x ); | |
if ( bShouldConvert ) | |
{ | |
// return "OurCurrency / TheirCurrency"; | |
if ( g_rgWalletInfo['wallet_other_currency'] == ( currency.id % 1000 ) ) | |
{ | |
return v_currencyformat( ConvertToOurCurrencyForDisplay( nPostFeeAmount ), GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) + ' / ' + v_currencyformat( nPostFeeAmount, currency.name ); | |
} | |
else if ( g_rgWalletInfo['wallet_currency'] == ( currency.id % 1000 ) ) | |
{ | |
return v_currencyformat( nPostFeeAmount, currency.name ) + ' / ' + v_currencyformat( ConvertToTheirCurrency( nPostFeeAmount ), GetCurrencyCode( g_rgWalletInfo['wallet_other_currency'] ) ); | |
} | |
} | |
return v_currencyformat( nPostFeeAmount, currency.name ); | |
}; | |
} | |
else | |
{ | |
formatFunc = v_numberformat; | |
} | |
var itemname = formatFunc( event.amount == 0 ? event.old_amount : event.amount ) + ' ' + currencyname; | |
var itemstyle = ( currency && currency.name_color ) ? 'color: #' + currency.name_color + ';' : ''; | |
strEvent = template.evaluate( | |
{ | |
theirname: g_strTradePartnerPersonaName, | |
itemname: itemname, | |
currencyname: currencyname, | |
itemstyle: itemstyle, | |
amount: formatFunc( event.amount ) | |
} | |
); | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment