@@ -11,13 +11,15 @@ wrap(() => {
1111 type, count, gold,
1212 } ) {
1313 if ( gold ) { // Gold error checking
14+ const goldCost = type === 'UTY' ? 200 : 100 ;
1415 const g = parseInt ( $ ( '#golds' ) . text ( ) , 10 ) ;
15- if ( g < 100 * count ) {
16+ if ( g < goldCost * count ) {
1617 throw new Error ( 'Not enough Gold' ) ;
1718 }
1819 } else { // UCP error checking
20+ const ucpCost = type === 'UTY' ? 20 : 10 ;
1921 const ucp = parseInt ( $ ( '#ucp' ) . text ( ) , 10 ) ;
20- if ( ucp < 10 * count ) {
22+ if ( ucp < ucpCost * count ) {
2123 throw new Error ( 'Not enough UCP' ) ;
2224 }
2325 }
@@ -34,21 +36,22 @@ wrap(() => {
3436 } ) ;
3537 }
3638
37- function getCount ( e , cost ) {
38- if ( e . ctrlKey ) return Math . floor ( parseInt ( $ ( cost ? '#ucp' : '#golds' ) . text ( ) , 10 ) / ( cost ? 10 : 100 ) ) ;
39+ function getCount ( e , cost , baseCost ) {
40+ if ( e . ctrlKey ) return Math . floor ( parseInt ( $ ( cost ? '#ucp' : '#golds' ) . text ( ) , 10 ) / ( cost ? baseCost / 10 : baseCost ) ) ;
3941 if ( e . altKey ) return 10 ;
4042 return 1 ;
4143 }
4244
4345 eventManager . on ( ':loaded:Packs' , ( ) => {
44- const types = [ '' , 'DR' ] ;
46+ const types = [ '' , 'DR' , 'UTY' ] ;
4547
4648 types . forEach ( ( type ) => {
4749 [ '' , 'Ucp' ] . forEach ( ( cost ) => {
4850 const el = document . querySelector ( `#btn${ cost } ${ type } Add` ) ;
4951 el . onclick = null ;
5052 el . addEventListener ( 'click' , ( e ) => {
51- const count = getCount ( e , cost ) ;
53+ const price = type === 'UTY' ? 200 : 100 ;
54+ const count = getCount ( e , cost , price ) ;
5255 if ( ! count ) return ;
5356 const data = {
5457 count,
@@ -58,7 +61,7 @@ wrap(() => {
5861 if ( cost && ! e . shiftKey ) {
5962 global ( 'BootstrapDialog' ) . show ( {
6063 title : 'Buy packs with UCP?' ,
61- message : $ . i18n ( `Buy ${ count } pack${ count > 1 ? 's' : '' } for {{UCP:${ count * 10 } }} UCP?` ) ,
64+ message : $ . i18n ( `Buy ${ count } pack${ count > 1 ? 's' : '' } for {{UCP:${ count * ( price / 10 ) } }} UCP?` ) ,
6265 buttons : [ {
6366 label : $ . i18n ( 'dialog-continue' ) ,
6467 cssClass : 'btn-success' ,
@@ -84,7 +87,7 @@ wrap(() => {
8487
8588 api . register ( 'buyPacks' , ( count , { type = '' , gold = true } = { } ) => {
8689 if ( ! types . includes ( type ) ) throw new Error ( `Unsupported Pack: ${ type } ` ) ;
87- if ( Number . isNaN ( count ) ) throw new Error ( `Count(${ count } ) must be a number` ) ;
90+ if ( ! Number . isInteger ( count ) || count < 1 ) throw new Error ( `Count(${ count } ) must be a number` ) ;
8891 buyPacks ( {
8992 type,
9093 count,
0 commit comments