2017-07-27 17:41:23 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import buyOp from 'common/script/ops/buy';
|
2017-08-26 10:18:55 +00:00
|
|
|
import buyQuestOp from 'common/script/ops/buyQuest';
|
2017-07-31 23:04:40 +00:00
|
|
|
import purchaseOp from 'common/script/ops/purchaseWithSpell';
|
2017-08-24 05:16:18 +00:00
|
|
|
import buyMysterySetOp from 'common/script/ops/buyMysterySet';
|
|
|
|
|
import hourglassPurchaseOp from 'common/script/ops/hourglassPurchase';
|
2017-07-27 17:41:23 +00:00
|
|
|
import sellOp from 'common/script/ops/sell';
|
2017-08-26 10:18:55 +00:00
|
|
|
import unlockOp from 'common/script/ops/unlock';
|
2017-09-12 17:56:06 +00:00
|
|
|
import buyArmoire from 'common/script/ops/buyArmoire';
|
2017-09-27 23:06:07 +00:00
|
|
|
import rerollOp from 'common/script/ops/reroll';
|
2017-10-01 21:25:32 +00:00
|
|
|
import { getDropClass } from 'client/libs/notifications';
|
2017-07-27 17:41:23 +00:00
|
|
|
|
|
|
|
|
export function buyItem (store, params) {
|
|
|
|
|
const user = store.state.user.data;
|
2017-08-26 10:18:55 +00:00
|
|
|
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}`),
|
|
|
|
|
};
|
2017-07-27 17:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-31 23:04:40 +00:00
|
|
|
export function purchase (store, params) {
|
|
|
|
|
const user = store.state.user.data;
|
2017-08-26 10:18:55 +00:00
|
|
|
let opResult = purchaseOp(user, {params});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
|
|
|
|
httpCall: axios.post(`/api/v3/user/purchase/${params.type}/${params.key}`),
|
|
|
|
|
};
|
2017-07-31 23:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 05:16:18 +00:00
|
|
|
export function purchaseMysterySet (store, params) {
|
|
|
|
|
const user = store.state.user.data;
|
2017-08-31 20:56:53 +00:00
|
|
|
let opResult = buyMysterySetOp(user, {params, noConfirm: true});
|
2017-08-26 10:18:55 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
|
|
|
|
httpCall: axios.post(`/api/v3/user/buy-mystery-set/${params.key}`),
|
|
|
|
|
};
|
2017-08-24 05:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function purchaseHourglassItem (store, params) {
|
|
|
|
|
const user = store.state.user.data;
|
2017-08-26 10:18:55 +00:00
|
|
|
let opResult = hourglassPurchaseOp(user, {params});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
|
|
|
|
httpCall: axios.post(`/api/v3/user/purchase-hourglass/${params.type}/${params.key}`),
|
|
|
|
|
};
|
2017-08-24 05:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-26 10:18:55 +00:00
|
|
|
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}`),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-02 17:51:17 +00:00
|
|
|
export async function genericPurchase (store, params) {
|
2017-08-26 10:18:55 +00:00
|
|
|
switch (params.pinType) {
|
|
|
|
|
case 'mystery_set':
|
|
|
|
|
return purchaseMysterySet(store, params);
|
2017-09-12 17:56:06 +00:00
|
|
|
case 'armoire': // eslint-disable-line
|
|
|
|
|
let buyResult = buyArmoire(store.state.user.data);
|
|
|
|
|
|
2017-10-02 17:51:17 +00:00
|
|
|
// We need the server result because armoir has random item in the result
|
|
|
|
|
let result = await axios.post('/api/v3/user/buy-armoire');
|
|
|
|
|
buyResult = result.data.data;
|
|
|
|
|
|
|
|
|
|
if (buyResult) {
|
|
|
|
|
const resData = buyResult;
|
2017-10-01 21:25:32 +00:00
|
|
|
const item = resData.armoire;
|
|
|
|
|
|
2017-10-02 21:01:27 +00:00
|
|
|
const isExperience = item.type === 'experience';
|
|
|
|
|
|
2017-10-09 19:40:45 +00:00
|
|
|
if (item.type === 'gear') {
|
|
|
|
|
store.state.user.data.items.gear.owned[item.dropKey] = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-02 21:01:27 +00:00
|
|
|
// @TODO: We might need to abstract notifications to library rather than mixin
|
2017-09-12 17:56:06 +00:00
|
|
|
store.state.notificationStore.push({
|
|
|
|
|
title: '',
|
2017-10-02 21:01:27 +00:00
|
|
|
text: isExperience ? item.value : item.dropText,
|
|
|
|
|
type: isExperience ? 'xp' : 'drop',
|
|
|
|
|
icon: isExperience ? null : getDropClass({type: item.type, key: item.dropKey}),
|
2017-09-12 17:56:06 +00:00
|
|
|
timeout: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
2017-09-27 23:06:07 +00:00
|
|
|
case 'fortify': {
|
|
|
|
|
let rerollResult = rerollOp(store.state.user.data);
|
|
|
|
|
|
|
|
|
|
axios.post('/api/v3/user/reroll');
|
|
|
|
|
|
|
|
|
|
return rerollResult;
|
|
|
|
|
}
|
|
|
|
|
case 'rebirth_orb':
|
|
|
|
|
return store.dispatch('user:rebirth');
|
2017-09-22 11:34:00 +00:00
|
|
|
case 'potion':
|
2017-08-26 10:18:55 +00:00
|
|
|
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);
|
2017-08-31 20:56:53 +00:00
|
|
|
} else if (params.currency === 'hourglasses') {
|
|
|
|
|
return purchaseHourglassItem(store, params);
|
2017-08-26 10:18:55 +00:00
|
|
|
} else {
|
|
|
|
|
return purchase(store, params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-24 05:16:18 +00:00
|
|
|
|
2017-07-27 17:41:23 +00:00
|
|
|
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));
|
|
|
|
|
}
|