-
Notifications
You must be signed in to change notification settings - Fork 4k
/
shops.js
120 lines (104 loc) · 3.43 KB
/
shops.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import axios from 'axios';
import buyOp from 'common/script/ops/buy';
import buyQuestOp from 'common/script/ops/buyQuest';
import purchaseOp from 'common/script/ops/purchaseWithSpell';
import buyMysterySetOp from 'common/script/ops/buyMysterySet';
import hourglassPurchaseOp from 'common/script/ops/hourglassPurchase';
import sellOp from 'common/script/ops/sell';
import unlockOp from 'common/script/ops/unlock';
import buyArmoire from 'common/script/ops/buyArmoire';
export function buyItem (store, params) {
const user = store.state.user.data;
let opResult = buyOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy/${params.key}`),
};
}
export function buyQuestItem (store, params) {
const user = store.state.user.data;
let opResult = buyQuestOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy-quest/${params.key}`),
};
}
export function purchase (store, params) {
const user = store.state.user.data;
let opResult = purchaseOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/purchase/${params.type}/${params.key}`),
};
}
export function purchaseMysterySet (store, params) {
const user = store.state.user.data;
let opResult = buyMysterySetOp(user, {params, noConfirm: true});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy-mystery-set/${params.key}`),
};
}
export function purchaseHourglassItem (store, params) {
const user = store.state.user.data;
let opResult = hourglassPurchaseOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/purchase-hourglass/${params.type}/${params.key}`),
};
}
export function unlock (store, params) {
const user = store.state.user.data;
let opResult = unlockOp(user, params);
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/unlock?path=${params.query.path}`),
};
}
export function genericPurchase (store, params) {
switch (params.pinType) {
case 'mystery_set':
return purchaseMysterySet(store, params);
case 'armoire': // eslint-disable-line
let buyResult = buyArmoire(store.state.user.data);
// @TODO: We might need to abstract notifications to library rather than mixin
if (buyResult[1]) {
store.state.notificationStore.push({
title: '',
text: buyResult[1],
type: 'drop',
timeout: true,
});
}
axios.post('/api/v3/user/buy-armoire');
return;
case 'potion':
case 'marketGear':
return buyItem(store, params);
case 'background':
return unlock(store, {
query: {
path: `background.${params.key}`,
},
});
default:
if (params.pinType === 'quests' && params.currency === 'gold') {
return buyQuestItem(store, params);
} else if (params.key === 'rebirth_orb') {
return store.dispatch('user:rebirth');
} else if (params.currency === 'hourglasses') {
return purchaseHourglassItem(store, params);
} else {
return purchase(store, params);
}
}
}
export function sellItems (store, params) {
const user = store.state.user.data;
sellOp(user, {params, query: {amount: params.amount}});
axios
.post(`/api/v3/user/sell/${params.type}/${params.key}?amount=${params.amount}`);
// TODO
// .then((res) => console.log('equip', res))
// .catch((err) => console.error('equip', err));
}