@@ -11,13 +11,15 @@ wrap(() => {
11
11
type, count, gold,
12
12
} ) {
13
13
if ( gold ) { // Gold error checking
14
+ const goldCost = type === 'UTY' ? 200 : 100 ;
14
15
const g = parseInt ( $ ( '#golds' ) . text ( ) , 10 ) ;
15
- if ( g < 100 * count ) {
16
+ if ( g < goldCost * count ) {
16
17
throw new Error ( 'Not enough Gold' ) ;
17
18
}
18
19
} else { // UCP error checking
20
+ const ucpCost = type === 'UTY' ? 20 : 10 ;
19
21
const ucp = parseInt ( $ ( '#ucp' ) . text ( ) , 10 ) ;
20
- if ( ucp < 10 * count ) {
22
+ if ( ucp < ucpCost * count ) {
21
23
throw new Error ( 'Not enough UCP' ) ;
22
24
}
23
25
}
@@ -34,21 +36,22 @@ wrap(() => {
34
36
} ) ;
35
37
}
36
38
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 ) ) ;
39
41
if ( e . altKey ) return 10 ;
40
42
return 1 ;
41
43
}
42
44
43
45
eventManager . on ( ':loaded:Packs' , ( ) => {
44
- const types = [ '' , 'DR' ] ;
46
+ const types = [ '' , 'DR' , 'UTY' ] ;
45
47
46
48
types . forEach ( ( type ) => {
47
49
[ '' , 'Ucp' ] . forEach ( ( cost ) => {
48
50
const el = document . querySelector ( `#btn${ cost } ${ type } Add` ) ;
49
51
el . onclick = null ;
50
52
el . addEventListener ( 'click' , ( e ) => {
51
- const count = getCount ( e , cost ) ;
53
+ const price = type === 'UTY' ? 200 : 100 ;
54
+ const count = getCount ( e , cost , price ) ;
52
55
if ( ! count ) return ;
53
56
const data = {
54
57
count,
@@ -58,7 +61,7 @@ wrap(() => {
58
61
if ( cost && ! e . shiftKey ) {
59
62
global ( 'BootstrapDialog' ) . show ( {
60
63
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?` ) ,
62
65
buttons : [ {
63
66
label : $ . i18n ( 'dialog-continue' ) ,
64
67
cssClass : 'btn-success' ,
@@ -84,7 +87,7 @@ wrap(() => {
84
87
85
88
api . register ( 'buyPacks' , ( count , { type = '' , gold = true } = { } ) => {
86
89
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` ) ;
88
91
buyPacks ( {
89
92
type,
90
93
count,
0 commit comments