Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Antidotes to Avatar Transformation Items should be added to Rewards by API #11353

Merged
merged 9 commits into from Oct 6, 2019
Merged
21 changes: 0 additions & 21 deletions website/client/components/tasks/column.vue
Expand Up @@ -273,7 +273,6 @@ import BuyQuestModal from 'client/components/shops/quests/buyQuestModal.vue';
import notifications from 'client/mixins/notifications';
import { shouldDo } from 'common/script/cron';
import inAppRewards from 'common/script/libs/inAppRewards';
import spells from 'common/script/content/spells';
import taskDefaults from 'common/script/libs/taskDefaults';

import {
Expand Down Expand Up @@ -379,26 +378,6 @@ export default {
let watchRefresh = this.forceRefresh; // eslint-disable-line
let rewards = inAppRewards(this.user);

// Add season rewards if user is affected
// @TODO: Add buff conditional
const seasonalSkills = {
snowball: 'salt',
spookySparkles: 'opaquePotion',
shinySeed: 'petalFreePotion',
seafoam: 'sand',
};

for (let key in seasonalSkills) {
if (this.getUserBuffs(key)) {
let debuff = seasonalSkills[key];
let item = Object.assign({}, spells.special[debuff]);
item.text = item.text();
item.notes = item.notes();
item.class = `shop_${key}`;
rewards.push(item);
}
}

return rewards;
},
hasRewardsList () {
Expand Down
7 changes: 7 additions & 0 deletions website/common/script/content/spells.js
Expand Up @@ -289,6 +289,8 @@ spells.special = {
cast (user) {
user.stats.buffs.snowball = false;
user.stats.gp -= 5;
// Remove antidote from pinned items
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('salt'));
},
},
spookySparkles: {
Expand Down Expand Up @@ -320,6 +322,8 @@ spells.special = {
cast (user) {
user.stats.buffs.spookySparkles = false;
user.stats.gp -= 5;
// Remove antidote from pinned items
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('opaquePotion'));
},
},
shinySeed: {
Expand Down Expand Up @@ -351,6 +355,8 @@ spells.special = {
cast (user) {
user.stats.buffs.shinySeed = false;
user.stats.gp -= 5;
// Remove antidote from pinned items
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('petalFreePotion'));
},
},
seafoam: {
Expand Down Expand Up @@ -382,6 +388,7 @@ spells.special = {
cast (user) {
user.stats.buffs.seafoam = false;
user.stats.gp -= 5;
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('sand'));
Xaz16 marked this conversation as resolved.
Show resolved Hide resolved
},
},
nye: {
Expand Down
3 changes: 3 additions & 0 deletions website/common/script/index.js
Expand Up @@ -77,6 +77,9 @@ api.updateStore = updateStore;
import inAppRewards from './libs/inAppRewards';
api.inAppRewards = inAppRewards;

import setDebuffPotionItem from './libs/setDebuffPotionItem';
paglias marked this conversation as resolved.
Show resolved Hide resolved
api.setDebuffPotionItem = setDebuffPotionItem;

import uuid from './libs/uuid';
api.uuid = uuid;

Expand Down
28 changes: 28 additions & 0 deletions website/common/script/libs/getDebuffPotionItem.js
@@ -0,0 +1,28 @@
module.exports = function getDebuffPotionItem (user) {
const items = [];
const userBuffs = user.stats.buffs;

if (user) {
// Add season rewards if user is affected
const seasonalSkills = {
snowball: 'salt',
spookySparkles: 'opaquePotion',
shinySeed: 'petalFreePotion',
seafoam: 'sand',
};

for (let key in seasonalSkills) {
if (userBuffs[key]) {
let debuff = seasonalSkills[key];
const item = {
path: `spells.special.${debuff}`,
type: 'debuffPotion',
};
items.push(item);
}
}


return items;
}
};
19 changes: 19 additions & 0 deletions website/common/script/libs/getItemInfo.js
Expand Up @@ -177,6 +177,25 @@ module.exports = function getItemInfo (user, type, item, officialPinnedItems, la
pinType: 'seasonalSpell',
};
break;
case 'debuffPotion':
itemInfo = {
paglias marked this conversation as resolved.
Show resolved Hide resolved
key: item.key,
mana: item.mana,
cast: item.cast,
immediateUse: item.immediateUse,
target: item.target,
text: item.text(language),
notes: item.notes(language),
value: item.value,
type: 'debuffPotion',
currency: 'gold',
locked: false,
purchaseType: 'debuffPotion',
class: `inventory_special_${item.key}`,
path: `spells.special.${item.key}`,
pinType: 'debuffPotion',
};
break;
case 'seasonalQuest':
itemInfo = {
key: item.key,
Expand Down
30 changes: 30 additions & 0 deletions website/common/script/libs/setDebuffPotionItem.js
@@ -0,0 +1,30 @@
import getDebuffPotionItem from './getDebuffPotionItem';


module.exports = function setDebuffPotionItem (user) {
const debuffPotionItems = getDebuffPotionItem(user);

if (debuffPotionItems.length) {
const isUserHaveDebuffInPinnedItems = user.pinnedItems.find(pinnedItem => {
let isPresent = false;
debuffPotionItems.forEach(debuffPotion => {
if (!isPresent) {
isPresent = debuffPotion.path === pinnedItem;
}
});
return isPresent;
});

if (!isUserHaveDebuffInPinnedItems) {
user.pinnedItems.push(...debuffPotionItems);
Xaz16 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
user.pinnedItems = user.pinnedItems.filter(item => {
return item.type !== 'debuffPotion';
});
}

return user;
};


26 changes: 16 additions & 10 deletions website/server/libs/spells.js
Expand Up @@ -68,6 +68,9 @@ async function castSelfSpell (req, user, spell, quantity = 1) {
for (let i = 0; i < quantity; i += 1) {
spell.cast(user, null, req);
}

common.setDebuffPotionItem(user);

await user.save();
}

Expand All @@ -94,34 +97,37 @@ async function castPartySpell (req, party, partyMembers, user, spell, quantity =
return partyMembers;
}

async function castUserSpell (res, req, party, partyMembers, targetId, user, spell, quantity = 1) {
async function castUserSpell (res, req, party, partyMember, targetId, user, spell, quantity = 1) {
if (!party && (!targetId || user._id === targetId)) {
partyMembers = user;
partyMember = user;
} else {
if (!targetId) throw new BadRequest(res.t('targetIdUUID'));
if (!party) throw new NotFound(res.t('partyNotFound'));
partyMembers = await User
partyMember = await User
.findOne({_id: targetId, 'party._id': party._id})
.select(partyMembersFields)
// We need all fields due to adding debuf spell to pinned items of target of the spell
// .select(partyMembersFields)
.exec();
}

if (!partyMembers) throw new NotFound(res.t('userWithIDNotFound', {userId: targetId}));
if (!partyMember) throw new NotFound(res.t('userWithIDNotFound', {userId: targetId}));

for (let i = 0; i < quantity; i += 1) {
spell.cast(user, partyMembers, req);
spell.cast(user, partyMember, req);
}

if (partyMembers !== user) {
common.setDebuffPotionItem(partyMember);

if (partyMember !== user) {
await Promise.all([
user.save(),
partyMembers.save(),
partyMember.save(),
]);
} else {
await partyMembers.save(); // partyMembers is user
await partyMember.save(); // partyMembers is user
}

return partyMembers;
return partyMember;
}

async function castSpell (req, res, {isV3 = false}) {
Expand Down