2017-07-27 17:41:23 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import buyOp from 'common/script/ops/buy';
|
2017-11-16 09:06:45 +00:00
|
|
|
import content from 'common/script/content/index';
|
2017-07-31 23:04:40 +00:00
|
|
|
import purchaseOp from 'common/script/ops/purchaseWithSpell';
|
2017-08-24 05:16:18 +00:00
|
|
|
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-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
|
|
|
|
2017-10-23 21:05:35 +00:00
|
|
|
// @TODO: Purchase means gems and buy means gold. That wording is misused below, but we should also change
|
|
|
|
|
// the generic buy functions to something else. Or have a Gold Vendor and Gem Vendor, etc
|
|
|
|
|
|
2017-07-27 17:41:23 +00:00
|
|
|
export function buyItem (store, params) {
|
2017-10-23 21:05:35 +00:00
|
|
|
const quantity = params.quantity || 1;
|
2017-07-27 17:41:23 +00:00
|
|
|
const user = store.state.user.data;
|
2018-02-02 18:22:25 +00:00
|
|
|
|
|
|
|
|
const userPinned = user.pinnedItems.slice();
|
2017-10-23 21:05:35 +00:00
|
|
|
let opResult = buyOp(user, {params, quantity});
|
2017-08-26 10:18:55 +00:00
|
|
|
|
2018-02-02 18:22:25 +00:00
|
|
|
// @TODO: Currently resetting the pinned items will reset the market. Purchasing some items does not reset pinned.
|
|
|
|
|
// For now, I've added this hack for items like contributor gear to update while I am working on add more computed
|
|
|
|
|
// properties to the market. We will use this quick fix while testing the other changes.
|
|
|
|
|
user.pinnedItems = userPinned;
|
|
|
|
|
|
|
|
|
|
|
2017-08-26 10:18:55 +00:00
|
|
|
return {
|
|
|
|
|
result: opResult,
|
|
|
|
|
httpCall: axios.post(`/api/v3/user/buy/${params.key}`),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buyQuestItem (store, params) {
|
2017-10-23 21:05:35 +00:00
|
|
|
const quantity = params.quantity || 1;
|
2017-08-26 10:18:55 +00:00
|
|
|
const user = store.state.user.data;
|
2017-10-23 21:05:35 +00:00
|
|
|
let opResult = buyOp(user, {
|
|
|
|
|
params,
|
|
|
|
|
type: 'quest',
|
|
|
|
|
quantity,
|
|
|
|
|
});
|
2017-08-26 10:18:55 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
2017-11-28 01:33:08 +00:00
|
|
|
httpCall: axios.post(`/api/v3/user/buy/${params.key}`, {type: 'quest', quantity}),
|
2017-08-26 10:18:55 +00:00
|
|
|
};
|
2017-07-27 17:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-23 21:05:35 +00:00
|
|
|
async function buyArmoire (store, params) {
|
|
|
|
|
const quantity = params.quantity || 1;
|
2017-11-16 09:06:45 +00:00
|
|
|
let armoire = content.armoire;
|
2017-10-23 21:05:35 +00:00
|
|
|
|
2017-11-16 09:06:45 +00:00
|
|
|
// We need the server result because Armoire has random item in the result
|
2017-10-23 21:05:35 +00:00
|
|
|
let result = await axios.post('/api/v3/user/buy/armoire', {
|
|
|
|
|
type: 'armoire',
|
|
|
|
|
quantity,
|
|
|
|
|
});
|
2017-11-16 09:06:45 +00:00
|
|
|
let buyResult = result.data.data;
|
2017-10-23 21:05:35 +00:00
|
|
|
|
|
|
|
|
if (buyResult) {
|
|
|
|
|
const resData = buyResult;
|
|
|
|
|
const item = resData.armoire;
|
2018-02-05 18:43:30 +00:00
|
|
|
const message = result.data.message;
|
2017-10-23 21:05:35 +00:00
|
|
|
|
|
|
|
|
const isExperience = item.type === 'experience';
|
|
|
|
|
if (item.type === 'gear') {
|
|
|
|
|
store.state.user.data.items.gear.owned[item.dropKey] = true;
|
|
|
|
|
}
|
2017-12-06 15:50:15 +00:00
|
|
|
store.state.user.data.stats.gp -= armoire.value;
|
2017-10-23 21:05:35 +00:00
|
|
|
|
|
|
|
|
// @TODO: We might need to abstract notifications to library rather than mixin
|
2018-02-05 18:43:30 +00:00
|
|
|
const notificationOptions = isExperience ?
|
|
|
|
|
{
|
|
|
|
|
text: `+ ${item.value}`,
|
|
|
|
|
type: 'xp',
|
|
|
|
|
flavorMessage: message,
|
|
|
|
|
} :
|
|
|
|
|
{
|
|
|
|
|
text: message,
|
|
|
|
|
type: 'drop',
|
|
|
|
|
icon: getDropClass({type: item.type, key: item.dropKey}),
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-23 21:05:35 +00:00
|
|
|
store.dispatch('snackbars:add', {
|
|
|
|
|
title: '',
|
|
|
|
|
timeout: true,
|
2018-02-05 18:43:30 +00:00
|
|
|
...notificationOptions,
|
2017-10-23 21:05:35 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 23:04:40 +00:00
|
|
|
export function purchase (store, params) {
|
2017-10-23 21:05:35 +00:00
|
|
|
const quantity = params.quantity || 1;
|
2017-07-31 23:04:40 +00:00
|
|
|
const user = store.state.user.data;
|
2017-10-23 21:05:35 +00:00
|
|
|
let opResult = purchaseOp(user, {params, quantity});
|
2017-08-26 10:18:55 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
2017-10-23 21:05:35 +00:00
|
|
|
httpCall: axios.post(`/api/v3/user/purchase/${params.type}/${params.key}`, {quantity}),
|
2017-08-26 10:18:55 +00:00
|
|
|
};
|
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-10-23 21:05:35 +00:00
|
|
|
let opResult = buyOp(user, {params, noConfirm: true, type: 'mystery'});
|
2017-08-26 10:18:55 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
result: opResult,
|
2017-10-23 21:05:35 +00:00
|
|
|
httpCall: axios.post(`/api/v3/user/buy/${params.key}`, {type: 'mystery'}),
|
2017-08-26 10:18:55 +00:00
|
|
|
};
|
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
|
2017-10-23 21:05:35 +00:00
|
|
|
await buyArmoire(store, params);
|
2017-09-12 17:56:06 +00:00
|
|
|
return;
|
2017-09-27 23:06:07 +00:00
|
|
|
case 'fortify': {
|
2017-11-17 09:31:29 +00:00
|
|
|
let rerollResult = rerollOp(store.state.user.data, store.state.tasks.data);
|
2017-09-27 23:06:07 +00:00
|
|
|
|
2017-11-17 09:31:29 +00:00
|
|
|
await axios.post('/api/v3/user/reroll');
|
|
|
|
|
await Promise.all([
|
|
|
|
|
store.dispatch('user:fetch', {forceLoad: true}),
|
|
|
|
|
store.dispatch('tasks:fetchUserTasks', {forceLoad: true}),
|
|
|
|
|
]);
|
2017-09-27 23:06:07 +00:00
|
|
|
|
|
|
|
|
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}});
|
2017-10-23 21:05:35 +00:00
|
|
|
axios.post(`/api/v3/user/sell/${params.type}/${params.key}?amount=${params.amount}`);
|
2017-07-27 17:41:23 +00:00
|
|
|
}
|