From 9cbdf0df421ee7b84ddd6222dab9397d4a505360 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 19:57:07 +0300 Subject: [PATCH 01/10] Fix: reassign object for user.items.gear.owned to trigger change in vue view --- website/client/src/store/actions/shops.js | 5 +- .../common/script/content/loginIncentives.js | 125 ++++++++++++++---- website/common/script/fns/resetGear.js | 5 +- website/common/script/ops/buy/buyArmoire.js | 5 +- .../common/script/ops/buy/buyMysterySet.js | 5 +- website/common/script/ops/buy/purchase.js | 5 +- website/common/script/ops/changeClass.js | 12 +- website/common/script/ops/openMysteryItem.js | 5 +- website/common/script/ops/pinnedGearUtils.js | 5 +- website/common/script/ops/revive.js | 5 +- 10 files changed, 142 insertions(+), 35 deletions(-) diff --git a/website/client/src/store/actions/shops.js b/website/client/src/store/actions/shops.js index e79beb187f..c0ee965045 100644 --- a/website/client/src/store/actions/shops.js +++ b/website/client/src/store/actions/shops.js @@ -60,7 +60,10 @@ async function buyArmoire (store, params) { const isExperience = item.type === 'experience'; if (item.type === 'gear') { - store.state.user.data.items.gear.owned[item.dropKey] = true; + store.state.user.data.items.gear.owned = { + ...store.state.user.data.items.gear.owned, + [item.dropKey]: true, + }; } if (item.type === 'food') { diff --git a/website/common/script/content/loginIncentives.js b/website/common/script/content/loginIncentives.js index c63b8b4fdd..c878111b7c 100644 --- a/website/common/script/content/loginIncentives.js +++ b/website/common/script/content/loginIncentives.js @@ -9,7 +9,10 @@ export default function getLoginIncentives (api) { rewardKey: ['armor_special_bardRobes'], reward: [api.gear.flat.armor_special_bardRobes], assignReward: function assignReward (user) { - user.items.gear.owned.armor_special_bardRobes = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_bardRobes: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -30,7 +33,10 @@ export default function getLoginIncentives (api) { rewardKey: ['head_special_bardHat'], reward: [api.gear.flat.head_special_bardHat], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_bardHat = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_bardHat: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -91,7 +97,10 @@ export default function getLoginIncentives (api) { rewardKey: ['weapon_special_bardInstrument'], reward: [api.gear.flat.weapon_special_bardInstrument], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_bardInstrument = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_bardInstrument: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -177,7 +186,10 @@ export default function getLoginIncentives (api) { rewardKey: ['slim_armor_special_pageArmor'], reward: [api.gear.flat.armor_special_pageArmor], assignReward: function assignReward (user) { - user.items.gear.owned.armor_special_pageArmor = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_pageArmor: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -194,7 +206,10 @@ export default function getLoginIncentives (api) { rewardKey: ['head_special_pageHelm'], reward: [api.gear.flat.head_special_pageHelm], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_pageHelm = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_pageHelm: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -211,7 +226,10 @@ export default function getLoginIncentives (api) { rewardKey: ['weapon_special_pageBanner'], reward: [api.gear.flat.weapon_special_pageBanner], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_pageBanner = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_pageBanner: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -228,7 +246,10 @@ export default function getLoginIncentives (api) { rewardKey: ['shield_special_diamondStave'], reward: [api.gear.flat.shield_special_diamondStave], assignReward: function assignReward (user) { - user.items.gear.owned.shield_special_diamondStave = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + shield_special_diamondStave: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -389,8 +410,14 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_weapon_special_skeletonKey', 'shop_shield_special_lootBag'], reward: [api.gear.flat.weapon_special_skeletonKey, api.gear.flat.shield_special_lootBag], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_skeletonKey = true; // eslint-disable-line camelcase - user.items.gear.owned.shield_special_lootBag = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_skeletonKey: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + shield_special_lootBag: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -410,8 +437,14 @@ export default function getLoginIncentives (api) { api.gear.flat.armor_special_sneakthiefRobes, ], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_clandestineCowl = true; // eslint-disable-line camelcase - user.items.gear.owned.armor_special_sneakthiefRobes = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_clandestineCowl: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_sneakthiefRobes: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -431,8 +464,14 @@ export default function getLoginIncentives (api) { api.gear.flat.armor_special_snowSovereignRobes, ], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_snowSovereignCrown = true; // eslint-disable-line camelcase, max-len - user.items.gear.owned.armor_special_snowSovereignRobes = true; // eslint-disable-line camelcase, max-len + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_snowSovereignCrown: true, + }; // eslint-disable-line camelcase, max-len + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_snowSovereignRobes: true, + }; // eslint-disable-line camelcase, max-len if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -449,8 +488,14 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_shield_special_wintryMirror', 'shop_back_special_snowdriftVeil'], reward: [api.gear.flat.shield_special_wintryMirror, api.gear.flat.back_special_snowdriftVeil], assignReward: function assignReward (user) { - user.items.gear.owned.shield_special_wintryMirror = true; // eslint-disable-line camelcase - user.items.gear.owned.back_special_snowdriftVeil = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + shield_special_wintryMirror: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + back_special_snowdriftVeil: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -479,8 +524,14 @@ export default function getLoginIncentives (api) { api.gear.flat.armor_special_nomadsCuirass, ], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_nomadsScimitar = true; // eslint-disable-line camelcase - user.items.gear.owned.armor_special_nomadsCuirass = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_nomadsScimitar: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_nomadsCuirass: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -488,7 +539,10 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_head_special_spikedHelm'], reward: [api.gear.flat.head_special_spikedHelm], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_spikedHelm = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_spikedHelm: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -557,7 +611,10 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_head_special_dandyHat'], reward: [api.gear.flat.head_special_dandyHat], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_dandyHat = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_dandyHat: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -565,8 +622,14 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_weapon_special_fencingFoil', 'shop_armor_special_dandySuit'], reward: [api.gear.flat.weapon_special_fencingFoil, api.gear.flat.armor_special_dandySuit], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_fencingFoil = true; // eslint-disable-line camelcase - user.items.gear.owned.armor_special_dandySuit = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_fencingFoil: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_dandySuit: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -655,8 +718,14 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_weapon_special_tachi', 'shop_armor_special_samuraiArmor'], reward: [api.gear.flat.weapon_special_tachi, api.gear.flat.armor_special_samuraiArmor], assignReward: function assignReward (user) { - user.items.gear.owned.weapon_special_tachi = true; // eslint-disable-line camelcase - user.items.gear.owned.armor_special_samuraiArmor = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + weapon_special_tachi: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + armor_special_samuraiArmor: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, @@ -664,8 +733,14 @@ export default function getLoginIncentives (api) { rewardKey: ['shop_head_special_kabuto', 'shop_shield_special_wakizashi'], reward: [api.gear.flat.head_special_kabuto, api.gear.flat.shield_special_wakizashi], assignReward: function assignReward (user) { - user.items.gear.owned.head_special_kabuto = true; // eslint-disable-line camelcase - user.items.gear.owned.shield_special_wakizashi = true; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + head_special_kabuto: true, + }; // eslint-disable-line camelcase + user.items.gear.owned = { + ...user.items.gear.owned, + shield_special_wakizashi: true, + }; // eslint-disable-line camelcase if (user.markModified) user.markModified('items.gear.owned'); }, }, diff --git a/website/common/script/fns/resetGear.js b/website/common/script/fns/resetGear.js index 008b1a13b9..9ad23b727e 100644 --- a/website/common/script/fns/resetGear.js +++ b/website/common/script/fns/resetGear.js @@ -16,7 +16,10 @@ export default function resetGear (user) { // The content.gear.flat[k] check should prevent this causing an error each(gear.owned, (v, k) => { if (gear.owned[k] && content.gear.flat[k] && content.gear.flat[k].value) { - gear.owned[k] = false; + gear.owned = { + ...gear.owned, + [k]: false, + }; } }); diff --git a/website/common/script/ops/buy/buyArmoire.js b/website/common/script/ops/buy/buyArmoire.js index 97d5213aca..ce7a978512 100644 --- a/website/common/script/ops/buy/buyArmoire.js +++ b/website/common/script/ops/buy/buyArmoire.js @@ -90,7 +90,10 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation { // eslint-d throw new NotAuthorized(this.i18n('equipmentAlreadyOwned')); } - user.items.gear.owned[drop.key] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [drop.key]: true, + }; if (user.markModified) user.markModified('items.gear.owned'); user.flags.armoireOpened = true; diff --git a/website/common/script/ops/buy/buyMysterySet.js b/website/common/script/ops/buy/buyMysterySet.js index 018322cba8..4e1765c013 100644 --- a/website/common/script/ops/buy/buyMysterySet.js +++ b/website/common/script/ops/buy/buyMysterySet.js @@ -25,7 +25,10 @@ export default function buyMysterySet (user, req = {}, analytics) { } each(mysterySet.items, item => { - user.items.gear.owned[item.key] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [item.key]: true, + }; if (analytics) { analytics.track('acquire item', { uuid: user._id, diff --git a/website/common/script/ops/buy/purchase.js b/website/common/script/ops/buy/purchase.js index f4156f7683..67b65224eb 100644 --- a/website/common/script/ops/buy/purchase.js +++ b/website/common/script/ops/buy/purchase.js @@ -46,7 +46,10 @@ function purchaseItem (user, item, price, type, key) { user.balance -= price; if (type === 'gear') { - user.items.gear.owned[key] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [key]: true, + }; if (user.markModified) user.markModified('items.gear.owned'); } else if (type === 'bundles') { const subType = item.type; diff --git a/website/common/script/ops/changeClass.js b/website/common/script/ops/changeClass.js index 460786c6bd..a9d7104fa3 100644 --- a/website/common/script/ops/changeClass.js +++ b/website/common/script/ops/changeClass.js @@ -53,8 +53,16 @@ export default function changeClass (user, req = {}, analytics) { addPinnedGearByClass(user); - user.items.gear.owned[`weapon_${klass}_0`] = true; - if (klass === 'rogue') user.items.gear.owned[`shield_${klass}_0`] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [`weapon_${klass}_0`]: true, + }; + if (klass === 'rogue') { + user.items.gear.owned = { + ...user.items.gear.owned, + [`shield_${klass}_0`]: true, + }; + } if (user.markModified) user.markModified('items.gear.owned'); removePinnedItemsByOwnedGear(user); diff --git a/website/common/script/ops/openMysteryItem.js b/website/common/script/ops/openMysteryItem.js index 0ab7926c40..7df705aeb3 100644 --- a/website/common/script/ops/openMysteryItem.js +++ b/website/common/script/ops/openMysteryItem.js @@ -23,7 +23,10 @@ export default function openMysteryItem (user, req = {}, analytics) { item = cloneDeep(content.gear.flat[item]); item.text = content.gear.flat[item.key].text(user.preferences.language); - user.items.gear.owned[item.key] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [item.key]: true, + }; if (user.markModified) { user.markModified('purchased.plan.mysteryItems'); diff --git a/website/common/script/ops/pinnedGearUtils.js b/website/common/script/ops/pinnedGearUtils.js index 5c919c51a1..c69d9d30ed 100644 --- a/website/common/script/ops/pinnedGearUtils.js +++ b/website/common/script/ops/pinnedGearUtils.js @@ -95,7 +95,10 @@ export function removePinnedGearAddPossibleNewOnes (user, itemPath, newItemKey) // remove the old pinned gear items and add the new gear back removePinnedGearByClass(user); - user.items.gear.owned[newItemKey] = true; + user.items.gear.owned = { + ...user.items.gear.owned, + [newItemKey]: true, + }; if (user.markModified) user.markModified('items.gear.owned'); addPinnedGearByClass(user); diff --git a/website/common/script/ops/revive.js b/website/common/script/ops/revive.js index e8ce46010b..b50c1ca7e5 100644 --- a/website/common/script/ops/revive.js +++ b/website/common/script/ops/revive.js @@ -89,7 +89,10 @@ export default function revive (user, req = {}, analytics) { if (item) { removePinnedGearByClass(user); - user.items.gear.owned[lostItem] = false; + user.items.gear.owned = { + ...user.items.gear.owned, + [lostItem]: false, + }; if (user.markModified) user.markModified('items.gear.owned'); addPinnedGearByClass(user); From 3e476c4f52a20d9def375632750910c3df14e874 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 20:05:11 +0300 Subject: [PATCH 02/10] Fix: reassign object for items.pets to trigger change in vue view --- website/common/script/ops/buy/hourglassPurchase.js | 5 ++++- website/common/script/ops/feed.js | 5 ++++- website/common/script/ops/hatch.js | 5 ++++- website/common/script/ops/releaseBoth.js | 5 ++++- website/common/script/ops/releasePets.js | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/website/common/script/ops/buy/hourglassPurchase.js b/website/common/script/ops/buy/hourglassPurchase.js index f721acbc43..29f089d8c7 100644 --- a/website/common/script/ops/buy/hourglassPurchase.js +++ b/website/common/script/ops/buy/hourglassPurchase.js @@ -47,7 +47,10 @@ export default function purchaseHourglass (user, req = {}, analytics, quantity = user.purchased.plan.consecutive.trinkets -= 1; if (type === 'pets') { - user.items.pets[key] = 5; + user.items.pets = { + ...user.items.pets, + [key]: 5, + }; if (user.markModified) user.markModified('items.pets'); } diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index 92fb47bd92..d7f970dae0 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -13,7 +13,10 @@ import { import errorMessage from '../libs/errorMessage'; function evolve (user, pet, req) { - user.items.pets[pet.key] = -1; + user.items.pets = { + ...user.items.pets, + [pet.key]: -1, + }; user.items.mounts[pet.key] = true; if (user.markModified) { diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index 7a60e92ac1..b0c6d6ea40 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -40,7 +40,10 @@ export default function hatch (user, req = {}) { throw new NotAuthorized(i18n.t('messageAlreadyPet', req.language)); } - user.items.pets[pet] = 5; + user.items.pets = { + ...user.items.pets, + [pet]: 5, + }; user.items.eggs[egg] -= 1; user.items.hatchingPotions[hatchingPotion] -= 1; if (user.markModified) { diff --git a/website/common/script/ops/releaseBoth.js b/website/common/script/ops/releaseBoth.js index 80a7c81241..ec405a3544 100644 --- a/website/common/script/ops/releaseBoth.js +++ b/website/common/script/ops/releaseBoth.js @@ -60,7 +60,10 @@ export default function releaseBoth (user, req = {}) { giveMountMasterAchievement = false; } - user.items.pets[animal] = 0; + user.items.pets = { + ...user.items.pets, + [animal]: 0, + }; user.items.mounts[animal] = null; } diff --git a/website/common/script/ops/releasePets.js b/website/common/script/ops/releasePets.js index df7596a1a3..6dc1fbd7e6 100644 --- a/website/common/script/ops/releasePets.js +++ b/website/common/script/ops/releasePets.js @@ -28,7 +28,10 @@ export default function releasePets (user, req = {}, analytics) { if (!user.items.pets[pet]) { giveBeastMasterAchievement = false; } - user.items.pets[pet] = 0; + user.items.pets = { + ...user.items.pets, + [pet]: 0, + }; } if (user.markModified) user.markModified('items.pets'); From aea02d735efe52df433856ad0d529feeaa0de69f Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 20:22:47 +0300 Subject: [PATCH 03/10] Fix: reassign object for user.items.eggs to trigger change in vue view --- .../common/script/content/loginIncentives.js | 135 ++++++++++++++---- website/common/script/fns/randomDrop.js | 10 +- website/common/script/fns/updateStats.js | 10 +- website/common/script/ops/hatch.js | 5 +- 4 files changed, 128 insertions(+), 32 deletions(-) diff --git a/website/common/script/content/loginIncentives.js b/website/common/script/content/loginIncentives.js index c878111b7c..cf16dc0888 100644 --- a/website/common/script/content/loginIncentives.js +++ b/website/common/script/content/loginIncentives.js @@ -289,23 +289,50 @@ export default function getLoginIncentives (api) { rewardName: 'oneOfAllPetEggs', assignReward: function assignReward (user) { if (!user.items.eggs.BearCub) user.items.eggs.BearCub = 0; - user.items.eggs.BearCub += 1; + user.items.eggs = { + ...user.items.eggs, + BearCub: user.items.eggs.BearCub + 1, + }; if (!user.items.eggs.Cactus) user.items.eggs.Cactus = 0; - user.items.eggs.Cactus += 1; + user.items.eggs = { + ...user.items.eggs, + Cactus: user.items.eggs.Cactus + 1, + }; if (!user.items.eggs.Dragon) user.items.eggs.Dragon = 0; - user.items.eggs.Dragon += 1; + user.items.eggs = { + ...user.items.eggs, + Dragon: user.items.eggs.Dragon + 1, + }; if (!user.items.eggs.FlyingPig) user.items.eggs.FlyingPig = 0; - user.items.eggs.FlyingPig += 1; + user.items.eggs = { + ...user.items.eggs, + FlyingPig: user.items.eggs.FlyingPig + 1, + }; if (!user.items.eggs.Fox) user.items.eggs.Fox = 0; - user.items.eggs.Fox += 1; + user.items.eggs = { + ...user.items.eggs, + Fox: user.items.eggs.Fox + 1, + }; if (!user.items.eggs.LionCub) user.items.eggs.LionCub = 0; - user.items.eggs.LionCub += 1; + user.items.eggs = { + ...user.items.eggs, + LionCub: user.items.eggs.LionCub + 1, + }; if (!user.items.eggs.PandaCub) user.items.eggs.PandaCub = 0; - user.items.eggs.PandaCub += 1; + user.items.eggs = { + ...user.items.eggs, + PandaCub: user.items.eggs.PandaCub + 1, + }; if (!user.items.eggs.TigerCub) user.items.eggs.TigerCub = 0; - user.items.eggs.TigerCub += 1; + user.items.eggs = { + ...user.items.eggs, + TigerCub: user.items.eggs.TigerCub + 1, + }; if (!user.items.eggs.Wolf) user.items.eggs.Wolf = 0; - user.items.eggs.Wolf += 1; + user.items.eggs = { + ...user.items.eggs, + Wolf: user.items.eggs.Wolf + 1, + }; if (user.markModified) user.markModified('items.eggs'); }, }, @@ -587,23 +614,50 @@ export default function getLoginIncentives (api) { rewardName: 'twoOfAllPetEggs', assignReward: function assignReward (user) { if (!user.items.eggs.BearCub) user.items.eggs.BearCub = 0; - user.items.eggs.BearCub += 2; + user.items.eggs = { + ...user.items.eggs, + BearCub: user.items.eggs.BearCub + 2, + }; if (!user.items.eggs.Cactus) user.items.eggs.Cactus = 0; - user.items.eggs.Cactus += 2; + user.items.eggs = { + ...user.items.eggs, + Cactus: user.items.eggs.Cactus + 2, + }; if (!user.items.eggs.Dragon) user.items.eggs.Dragon = 0; - user.items.eggs.Dragon += 2; + user.items.eggs = { + ...user.items.eggs, + Dragon: user.items.eggs.Dragon + 2, + }; if (!user.items.eggs.FlyingPig) user.items.eggs.FlyingPig = 0; - user.items.eggs.FlyingPig += 2; + user.items.eggs = { + ...user.items.eggs, + FlyingPig: user.items.eggs.FlyingPig + 2, + }; if (!user.items.eggs.Fox) user.items.eggs.Fox = 0; - user.items.eggs.Fox += 2; + user.items.eggs = { + ...user.items.eggs, + Fox: user.items.eggs.Fox + 2, + }; if (!user.items.eggs.LionCub) user.items.eggs.LionCub = 0; - user.items.eggs.LionCub += 2; + user.items.eggs = { + ...user.items.eggs, + LionCub: user.items.eggs.LionCub + 2, + }; if (!user.items.eggs.PandaCub) user.items.eggs.PandaCub = 0; - user.items.eggs.PandaCub += 2; + user.items.eggs = { + ...user.items.eggs, + PandaCub: user.items.eggs.PandaCub + 2, + }; if (!user.items.eggs.TigerCub) user.items.eggs.TigerCub = 0; - user.items.eggs.TigerCub += 2; + user.items.eggs = { + ...user.items.eggs, + TigerCub: user.items.eggs.TigerCub + 2, + }; if (!user.items.eggs.Wolf) user.items.eggs.Wolf = 0; - user.items.eggs.Wolf += 2; + user.items.eggs = { + ...user.items.eggs, + Wolf: user.items.eggs.Wolf + 2, + }; if (user.markModified) user.markModified('items.eggs'); }, }, @@ -652,23 +706,50 @@ export default function getLoginIncentives (api) { rewardName: 'threeOfAllPetEggs', assignReward: function assignReward (user) { if (!user.items.eggs.BearCub) user.items.eggs.BearCub = 0; - user.items.eggs.BearCub += 3; + user.items.eggs = { + ...user.items.eggs, + BearCub: user.items.eggs.BearCub + 3, + }; if (!user.items.eggs.Cactus) user.items.eggs.Cactus = 0; - user.items.eggs.Cactus += 3; + user.items.eggs = { + ...user.items.eggs, + Cactus: user.items.eggs.Cactus + 3, + }; if (!user.items.eggs.Dragon) user.items.eggs.Dragon = 0; - user.items.eggs.Dragon += 3; + user.items.eggs = { + ...user.items.eggs, + Dragon: user.items.eggs.Dragon + 3, + }; if (!user.items.eggs.FlyingPig) user.items.eggs.FlyingPig = 0; - user.items.eggs.FlyingPig += 3; + user.items.eggs = { + ...user.items.eggs, + FlyingPig: user.items.eggs.FlyingPig + 3, + }; if (!user.items.eggs.Fox) user.items.eggs.Fox = 0; - user.items.eggs.Fox += 3; + user.items.eggs = { + ...user.items.eggs, + Fox: user.items.eggs.Fox + 3, + }; if (!user.items.eggs.LionCub) user.items.eggs.LionCub = 0; - user.items.eggs.LionCub += 3; + user.items.eggs = { + ...user.items.eggs, + LionCub: user.items.eggs.LionCub + 3, + }; if (!user.items.eggs.PandaCub) user.items.eggs.PandaCub = 0; - user.items.eggs.PandaCub += 3; + user.items.eggs = { + ...user.items.eggs, + PandaCub: user.items.eggs.PandaCub + 3, + }; if (!user.items.eggs.TigerCub) user.items.eggs.TigerCub = 0; - user.items.eggs.TigerCub += 3; + user.items.eggs = { + ...user.items.eggs, + TigerCub: user.items.eggs.TigerCub + 3, + }; if (!user.items.eggs.Wolf) user.items.eggs.Wolf = 0; - user.items.eggs.Wolf += 3; + user.items.eggs = { + ...user.items.eggs, + Wolf: user.items.eggs.Wolf + 3, + }; if (user.markModified) user.markModified('items.eggs'); }, }, diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index a3f8101424..50892c2d5a 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -91,8 +91,14 @@ export default function randomDrop (user, options, req = {}, analytics) { } else if (rarity > 0.3) { // eggs 30% chance drop = cloneDropItem(randomVal(content.dropEggs)); - user.items.eggs[drop.key] = user.items.eggs[drop.key] || 0; - user.items.eggs[drop.key] += 1; + user.items.eggs = { + ...user.items.eggs, + [drop.key]: user.items.eggs[drop.key] || 0, + }; + user.items.eggs = { + ...user.items.eggs, + [drop.key]: drop.key += 1, + }; if (user.markModified) user.markModified('items.eggs'); drop.type = 'Egg'; diff --git a/website/common/script/fns/updateStats.js b/website/common/script/fns/updateStats.js index 49ca605959..7eb672eb24 100644 --- a/website/common/script/fns/updateStats.js +++ b/website/common/script/fns/updateStats.js @@ -71,9 +71,15 @@ export default function updateStats (user, stats, req = {}, analytics) { if (user.addNotification) user.addNotification('DROPS_ENABLED'); if (user.items.eggs.Wolf > 0) { - user.items.eggs.Wolf += 1; + user.items.eggs = { + ...user.items.eggs, + Wolf: user.items.eggs.Wolf + 1, + }; } else { - user.items.eggs.Wolf = 1; + user.items.eggs = { + ...user.items.eggs, + Wolf: 1, + }; } if (user.markModified) user.markModified('items.eggs'); diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index b0c6d6ea40..551ef89463 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -44,7 +44,10 @@ export default function hatch (user, req = {}) { ...user.items.pets, [pet]: 5, }; - user.items.eggs[egg] -= 1; + user.items.eggs = { + ...user.items.eggs, + [egg]: user.items.eggs - 1, + }; user.items.hatchingPotions[hatchingPotion] -= 1; if (user.markModified) { user.markModified('items.pets'); From dec0488b082ebb3f75ae85cf63479fee8e1a50c4 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 20:26:53 +0300 Subject: [PATCH 04/10] Fix: reassign object for user.items.mounts to trigger change in vue view --- website/common/script/ops/buy/buyMount.js | 5 ++++- website/common/script/ops/buy/hourglassPurchase.js | 5 ++++- website/common/script/ops/feed.js | 6 ++++-- website/common/script/ops/releaseBoth.js | 5 ++++- website/common/script/ops/releaseMounts.js | 5 ++++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/website/common/script/ops/buy/buyMount.js b/website/common/script/ops/buy/buyMount.js index 660b78b1dd..dbc4517938 100644 --- a/website/common/script/ops/buy/buyMount.js +++ b/website/common/script/ops/buy/buyMount.js @@ -34,7 +34,10 @@ export class BuyHourglassMountOperation extends AbstractHourglassItemOperation { } executeChanges (user) { - user.items.mounts[this.key] = true; + user.items.mounts = { + ...user.items.mounts, + [this.key]: true, + }; if (user.markModified) user.markModified('items.mounts'); diff --git a/website/common/script/ops/buy/hourglassPurchase.js b/website/common/script/ops/buy/hourglassPurchase.js index 29f089d8c7..3181bc49b4 100644 --- a/website/common/script/ops/buy/hourglassPurchase.js +++ b/website/common/script/ops/buy/hourglassPurchase.js @@ -55,7 +55,10 @@ export default function purchaseHourglass (user, req = {}, analytics, quantity = } if (type === 'mounts') { - user.items.mounts[key] = true; + user.items.mounts = { + ...user.items.mounts, + [key]: true, + }; if (user.markModified) user.markModified('items.mounts'); } } diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index d7f970dae0..05170ddba4 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -17,8 +17,10 @@ function evolve (user, pet, req) { ...user.items.pets, [pet.key]: -1, }; - user.items.mounts[pet.key] = true; - + user.items.mounts = { + ...user.items.mounts, + [pet.key]: true, + }; if (user.markModified) { user.markModified('items.pets'); user.markModified('items.mounts'); diff --git a/website/common/script/ops/releaseBoth.js b/website/common/script/ops/releaseBoth.js index ec405a3544..c97d352e9e 100644 --- a/website/common/script/ops/releaseBoth.js +++ b/website/common/script/ops/releaseBoth.js @@ -64,7 +64,10 @@ export default function releaseBoth (user, req = {}) { ...user.items.pets, [animal]: 0, }; - user.items.mounts[animal] = null; + user.items.mounts = { + ...user.items.mounts, + [animal]: null, + }; } if (user.markModified) { diff --git a/website/common/script/ops/releaseMounts.js b/website/common/script/ops/releaseMounts.js index b41e50d861..e63a1ec4c5 100644 --- a/website/common/script/ops/releaseMounts.js +++ b/website/common/script/ops/releaseMounts.js @@ -28,7 +28,10 @@ export default function releaseMounts (user, req = {}, analytics) { if (user.items.mounts[mount] === null || user.items.mounts[mount] === undefined) { giveMountMasterAchievement = false; } - user.items.mounts[mount] = null; + user.items.mounts = { + ...user.items.mounts, + [mount]: null, + }; } if (user.markModified) user.markModified('items.mounts'); From 8b780eaf0d75d8ac632f8b07e138e1824d336e85 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 22:00:34 +0300 Subject: [PATCH 05/10] Fix: pet tests --- website/common/script/ops/feed.js | 12 ++++++------ website/common/script/ops/hatch.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index 05170ddba4..58a204fe22 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -17,6 +17,7 @@ function evolve (user, pet, req) { ...user.items.pets, [pet.key]: -1, }; + user.items.mounts = { ...user.items.mounts, [pet.key]: true, @@ -52,9 +53,8 @@ export default function feed (user, req = {}) { throw new NotFound(errorMessage('invalidFoodName', req.language)); } - const userPets = user.items.pets; - if (!userPets[pet.key]) { + if (!user.items.pets[pet.key]) { throw new NotFound(i18n.t('messagePetNotFound', req.language)); } @@ -81,16 +81,16 @@ export default function feed (user, req = {}) { }; if (food.target === pet.potion || pet.type === 'premium') { - userPets[pet.key] += 5; + user.items.pets[pet.key] += 5; message = i18n.t('messageLikesFood', messageParams, req.language); } else { - userPets[pet.key] += 2; + user.items.pets[pet.key] += 2; message = i18n.t('messageDontEnjoyFood', messageParams, req.language); } if (user.markModified) user.markModified('items.pets'); - if (userPets[pet.key] >= 50 && !user.items.mounts[pet.key]) { + if (user.items.pets[pet.key] >= 50 && !user.items.mounts[pet.key]) { message = evolve(user, pet, req); } } @@ -116,7 +116,7 @@ export default function feed (user, req = {}) { }); return [ - userPets[pet.key], + user.items.pets[pet.key], message, ]; } diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index 551ef89463..86eca5dcd0 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -46,7 +46,7 @@ export default function hatch (user, req = {}) { }; user.items.eggs = { ...user.items.eggs, - [egg]: user.items.eggs - 1, + [egg]: Number.isInteger(user.items.eggs) ? user.items.eggs - 1 : 0, }; user.items.hatchingPotions[hatchingPotion] -= 1; if (user.markModified) { From 0f755ab80da3ecac1eeacd703e832d00160905cf Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 22:09:07 +0300 Subject: [PATCH 06/10] Fix: reassign object for user.items.hatchingPotions to trigger change in vue view --- .../common/script/content/loginIncentives.js | 140 ++++++++++++++---- website/common/script/fns/randomDrop.js | 10 +- website/common/script/ops/hatch.js | 6 +- 3 files changed, 125 insertions(+), 31 deletions(-) diff --git a/website/common/script/content/loginIncentives.js b/website/common/script/content/loginIncentives.js index cf16dc0888..569d8265b3 100644 --- a/website/common/script/content/loginIncentives.js +++ b/website/common/script/content/loginIncentives.js @@ -45,7 +45,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -76,7 +79,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -118,7 +124,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -142,7 +151,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -160,7 +172,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -178,7 +193,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -198,7 +216,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -218,7 +239,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -238,7 +262,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -258,7 +285,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -276,7 +306,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -341,7 +374,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -357,29 +393,59 @@ export default function getLoginIncentives (api) { rewardName: 'oneOfAllHatchingPotions', assignReward: function assignReward (user) { if (!user.items.hatchingPotions.Base) user.items.hatchingPotions.Base = 0; - user.items.hatchingPotions.Base += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Base: user.items.hatchingPotions.Base + 1, + }; if (!user.items.hatchingPotions.CottonCandyBlue) { user.items.hatchingPotions.CottonCandyBlue = 0; } - user.items.hatchingPotions.CottonCandyBlue += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + CottonCandyBlue: user.items.hatchingPotions.CottonCandyBlue + 1, + }; if (!user.items.hatchingPotions.CottonCandyPink) { user.items.hatchingPotions.CottonCandyPink = 0; } - user.items.hatchingPotions.CottonCandyPink += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + CottonCandyPink: user.items.hatchingPotions.CottonCandyPink + 1, + }; if (!user.items.hatchingPotions.Desert) user.items.hatchingPotions.Desert = 0; - user.items.hatchingPotions.Desert += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Desert: user.items.hatchingPotions.Desert + 1, + }; if (!user.items.hatchingPotions.Golden) user.items.hatchingPotions.Golden = 0; - user.items.hatchingPotions.Golden += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Golden: user.items.hatchingPotions.Golden + 1, + }; if (!user.items.hatchingPotions.Red) user.items.hatchingPotions.Red = 0; - user.items.hatchingPotions.Red += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Red: user.items.hatchingPotions.Red + 1, + }; if (!user.items.hatchingPotions.Shade) user.items.hatchingPotions.Shade = 0; - user.items.hatchingPotions.Shade += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Shade: user.items.hatchingPotions.Shade + 1, + }; if (!user.items.hatchingPotions.Skeleton) user.items.hatchingPotions.Skeleton = 0; - user.items.hatchingPotions.Skeleton += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Skeleton: user.items.hatchingPotions.Skeleton + 1, + }; if (!user.items.hatchingPotions.White) user.items.hatchingPotions.White = 0; - user.items.hatchingPotions.White += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + White: user.items.hatchingPotions.White + 1, + }; if (!user.items.hatchingPotions.Zombie) user.items.hatchingPotions.Zombie = 0; - user.items.hatchingPotions.Zombie += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + Zombie: user.items.hatchingPotions.Zombie + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -388,7 +454,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -429,7 +498,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -453,7 +525,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -480,7 +555,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -507,7 +585,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, @@ -531,7 +612,10 @@ export default function getLoginIncentives (api) { reward: [api.hatchingPotions.RoyalPurple], assignReward: function assignReward (user) { if (!user.items.hatchingPotions.RoyalPurple) user.items.hatchingPotions.RoyalPurple = 0; - user.items.hatchingPotions.RoyalPurple += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + RoyalPurple: user.items.hatchingPotions.RoyalPurple + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); }, }, diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index 50892c2d5a..5c95bf4505 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -120,8 +120,14 @@ export default function randomDrop (user, options, req = {}, analytics) { randomVal(pickBy(content.hatchingPotions, (v, k) => acceptableDrops.indexOf(k) >= 0)), ); - user.items.hatchingPotions[drop.key] = user.items.hatchingPotions[drop.key] || 0; - user.items.hatchingPotions[drop.key] += 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + [drop.key]: user.items.hatchingPotions[drop.key] || 0, + }; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + [drop.key]: drop.key + 1, + }; if (user.markModified) user.markModified('items.hatchingPotions'); drop.type = 'HatchingPotion'; diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index 86eca5dcd0..4ecb1f308d 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -48,7 +48,11 @@ export default function hatch (user, req = {}) { ...user.items.eggs, [egg]: Number.isInteger(user.items.eggs) ? user.items.eggs - 1 : 0, }; - user.items.hatchingPotions[hatchingPotion] -= 1; + user.items.hatchingPotions = { + ...user.items.hatchingPotions, + [hatchingPotion]: + Number.isInteger(user.items.hatchingPotion) ? user.items.hatchingPotion - 1 : 0, + }; if (user.markModified) { user.markModified('items.pets'); user.markModified('items.eggs'); From 6e183c3927a0dc18d0fb53b3d19a657cfd0a8eac Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 22:14:40 +0300 Subject: [PATCH 07/10] Fix: reassign object for user.items.food to trigger change in vue view --- .../common/script/content/loginIncentives.js | 225 ++++++++++++++---- website/common/script/fns/randomDrop.js | 10 +- website/common/script/ops/buy/buyArmoire.js | 9 +- website/common/script/ops/feed.js | 5 +- 4 files changed, 199 insertions(+), 50 deletions(-) diff --git a/website/common/script/content/loginIncentives.js b/website/common/script/content/loginIncentives.js index 569d8265b3..88cd142ed6 100644 --- a/website/common/script/content/loginIncentives.js +++ b/website/common/script/content/loginIncentives.js @@ -57,11 +57,20 @@ export default function getLoginIncentives (api) { reward: [api.food.Chocolate, api.food.Meat, api.food.CottonCandyPink], assignReward: function assignReward (user) { if (!user.items.food.Chocolate) user.items.food.Chocolate = 0; - user.items.food.Chocolate += 1; + user.items.food = { + ...user.items.food, + Chocolate: user.items.food.Chocolate + 1, + }; if (!user.items.food.Meat) user.items.food.Meat = 0; - user.items.food.Meat += 1; + user.items.food = { + ...user.items.food, + Meat: user.items.food.Meat + 1, + }; if (!user.items.food.CottonCandyPink) user.items.food.CottonCandyPink = 0; - user.items.food.CottonCandyPink += 1; + user.items.food = { + ...user.items.food, + CottonCandyPink: user.items.food.CottonCandyPink + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -91,11 +100,20 @@ export default function getLoginIncentives (api) { reward: [api.food.Strawberry, api.food.Potatoe, api.food.CottonCandyBlue], assignReward: function assignReward (user) { if (!user.items.food.Strawberry) user.items.food.Strawberry = 0; - user.items.food.Strawberry += 1; + user.items.food = { + ...user.items.food, + Strawberry: user.items.food.Strawberry + 1, + }; if (!user.items.food.Potatoe) user.items.food.Potatoe = 0; - user.items.food.Potatoe += 1; + user.items.food = { + ...user.items.food, + Potatoe: user.items.food.Potatoe + 1, + }; if (!user.items.food.CottonCandyBlue) user.items.food.CottonCandyBlue = 0; - user.items.food.CottonCandyBlue += 1; + user.items.food = { + ...user.items.food, + CottonCandyBlue: user.items.food.CottonCandyBlue + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -136,13 +154,25 @@ export default function getLoginIncentives (api) { reward: [api.food.Fish, api.food.Milk, api.food.RottenMeat, api.food.Honey], assignReward: function assignReward (user) { if (!user.items.food.Fish) user.items.food.Fish = 0; - user.items.food.Fish += 1; + user.items.food = { + ...user.items.food, + Fish: user.items.food.Fish + 1, + }; if (!user.items.food.Milk) user.items.food.Milk = 0; - user.items.food.Milk += 1; + user.items.food = { + ...user.items.food, + Milk: user.items.food.Milk + 1, + }; if (!user.items.food.RottenMeat) user.items.food.RottenMeat = 0; - user.items.food.RottenMeat += 1; + user.items.food = { + ...user.items.food, + RottenMeat: user.items.food.RottenMeat + 1, + }; if (!user.items.food.Honey) user.items.food.Honey = 0; - user.items.food.Honey += 1; + user.items.food = { + ...user.items.food, + Honey: user.items.food.Honey + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -184,7 +214,10 @@ export default function getLoginIncentives (api) { reward: [api.food.Saddle], assignReward: function assignReward (user) { if (!user.items.food.Saddle) user.items.food.Saddle = 0; - user.items.food.Saddle += 1; + user.items.food = { + ...user.items.food, + Saddle: user.items.food.Saddle + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -297,7 +330,10 @@ export default function getLoginIncentives (api) { reward: [api.food.Saddle], assignReward: function assignReward (user) { if (!user.items.food.Saddle) user.items.food.Saddle = 0; - user.items.food.Saddle += 1; + user.items.food = { + ...user.items.food, + Saddle: user.items.food.Saddle + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -471,25 +507,55 @@ export default function getLoginIncentives (api) { rewardName: 'threeOfEachFood', assignReward: function assignReward (user) { if (!user.items.food.Meat) user.items.food.Meat = 0; - user.items.food.Meat += 3; + user.items.food = { + ...user.items.food, + Meat: user.items.food.Meat + 3, + }; if (!user.items.food.CottonCandyBlue) user.items.food.CottonCandyBlue = 0; - user.items.food.CottonCandyBlue += 3; + user.items.food = { + ...user.items.food, + CottonCandyBlue: user.items.food.CottonCandyBlue + 3, + }; if (!user.items.food.CottonCandyPink) user.items.food.CottonCandyPink = 0; - user.items.food.CottonCandyPink += 3; + user.items.food = { + ...user.items.food, + CottonCandyPink: user.items.food.CottonCandyPink + 3, + }; if (!user.items.food.Potatoe) user.items.food.Potatoe = 0; - user.items.food.Potatoe += 3; + user.items.food = { + ...user.items.food, + Potatoe: user.items.food.Potatoe + 3, + }; if (!user.items.food.Honey) user.items.food.Honey = 0; - user.items.food.Honey += 3; + user.items.food = { + ...user.items.food, + Honey: user.items.food.Honey + 3, + }; if (!user.items.food.Strawberry) user.items.food.Strawberry = 0; - user.items.food.Strawberry += 3; + user.items.food = { + ...user.items.food, + Strawberry: user.items.food.Strawberry + 3, + }; if (!user.items.food.Chocolate) user.items.food.Chocolate = 0; - user.items.food.Chocolate += 3; + user.items.food = { + ...user.items.food, + Chocolate: user.items.food.Chocolate + 3, + }; if (!user.items.food.Fish) user.items.food.Fish = 0; - user.items.food.Fish += 3; + user.items.food = { + ...user.items.food, + Fish: user.items.food.Fish + 3, + }; if (!user.items.food.Milk) user.items.food.Milk = 0; - user.items.food.Milk += 3; + user.items.food = { + ...user.items.food, + Milk: user.items.food.Milk + 3, + }; if (!user.items.food.RottenMeat) user.items.food.RottenMeat = 0; - user.items.food.RottenMeat += 3; + user.items.food = { + ...user.items.food, + RottenMeat: user.items.food.RottenMeat + 3, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -624,7 +690,10 @@ export default function getLoginIncentives (api) { reward: [api.food.Saddle], assignReward: function assignReward (user) { if (!user.items.food.Saddle) user.items.food.Saddle = 0; - user.items.food.Saddle += 1; + user.items.food = { + ...user.items.food, + Saddle: user.items.food.Saddle + 1, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -667,25 +736,55 @@ export default function getLoginIncentives (api) { rewardName: 'threeOfEachFood', assignReward: function assignReward (user) { if (!user.items.food.Meat) user.items.food.Meat = 0; - user.items.food.Meat += 3; + user.items.food = { + ...user.items.food, + Meat: user.items.food.Meat + 3, + }; if (!user.items.food.CottonCandyBlue) user.items.food.CottonCandyBlue = 0; - user.items.food.CottonCandyBlue += 3; + user.items.food = { + ...user.items.food, + CottonCandyBlue: user.items.food.CottonCandyBlue + 3, + }; if (!user.items.food.CottonCandyPink) user.items.food.CottonCandyPink = 0; - user.items.food.CottonCandyPink += 3; + user.items.food = { + ...user.items.food, + CottonCandyPink: user.items.food.CottonCandyPink + 3, + }; if (!user.items.food.Potatoe) user.items.food.Potatoe = 0; - user.items.food.Potatoe += 3; + user.items.food = { + ...user.items.food, + Potatoe: user.items.food.Potatoe + 3, + }; if (!user.items.food.Honey) user.items.food.Honey = 0; - user.items.food.Honey += 3; + user.items.food = { + ...user.items.food, + Honey: user.items.food.Honey + 3, + }; if (!user.items.food.Strawberry) user.items.food.Strawberry = 0; - user.items.food.Strawberry += 3; + user.items.food = { + ...user.items.food, + Strawberry: user.items.food.Strawberry + 3, + }; if (!user.items.food.Chocolate) user.items.food.Chocolate = 0; - user.items.food.Chocolate += 3; + user.items.food = { + ...user.items.food, + Chocolate: user.items.food.Chocolate + 3, + }; if (!user.items.food.Fish) user.items.food.Fish = 0; - user.items.food.Fish += 3; + user.items.food = { + ...user.items.food, + Fish: user.items.food.Fish + 3, + }; if (!user.items.food.Milk) user.items.food.Milk = 0; - user.items.food.Milk += 3; + user.items.food = { + ...user.items.food, + Milk: user.items.food.Milk + 3, + }; if (!user.items.food.RottenMeat) user.items.food.RottenMeat = 0; - user.items.food.RottenMeat += 3; + user.items.food = { + ...user.items.food, + RottenMeat: user.items.food.RottenMeat + 3, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -777,7 +876,10 @@ export default function getLoginIncentives (api) { rewardName: 'twoSaddles', assignReward: function assignReward (user) { if (!user.items.food.Saddle) user.items.food.Saddle = 0; - user.items.food.Saddle += 2; + user.items.food = { + ...user.items.food, + Saddle: user.items.food.Saddle + 2, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -847,25 +949,55 @@ export default function getLoginIncentives (api) { rewardName: 'fourOfEachFood', assignReward: function assignReward (user) { if (!user.items.food.Meat) user.items.food.Meat = 0; - user.items.food.Meat += 4; + user.items.food = { + ...user.items.food, + Meat: user.items.food.Meat + 4, + }; if (!user.items.food.CottonCandyBlue) user.items.food.CottonCandyBlue = 0; - user.items.food.CottonCandyBlue += 4; + user.items.food = { + ...user.items.food, + CottonCandyBlue: user.items.food.CottonCandyBlue + 4, + }; if (!user.items.food.CottonCandyPink) user.items.food.CottonCandyPink = 0; - user.items.food.CottonCandyPink += 4; + user.items.food = { + ...user.items.food, + CottonCandyPink: user.items.food.CottonCandyPink + 4, + }; if (!user.items.food.Potatoe) user.items.food.Potatoe = 0; - user.items.food.Potatoe += 4; + user.items.food = { + ...user.items.food, + Potatoe: user.items.food.Potatoe + 4, + }; if (!user.items.food.Honey) user.items.food.Honey = 0; - user.items.food.Honey += 4; + user.items.food = { + ...user.items.food, + Honey: user.items.food.Honey + 4, + }; if (!user.items.food.Strawberry) user.items.food.Strawberry = 0; - user.items.food.Strawberry += 4; + user.items.food = { + ...user.items.food, + Strawberry: user.items.food.Strawberry + 4, + }; if (!user.items.food.Chocolate) user.items.food.Chocolate = 0; - user.items.food.Chocolate += 4; + user.items.food = { + ...user.items.food, + Chocolate: user.items.food.Chocolate + 4, + }; if (!user.items.food.Fish) user.items.food.Fish = 0; - user.items.food.Fish += 4; + user.items.food = { + ...user.items.food, + Fish: user.items.food.Fish + 4, + }; if (!user.items.food.Milk) user.items.food.Milk = 0; - user.items.food.Milk += 4; + user.items.food = { + ...user.items.food, + Milk: user.items.food.Milk + 4, + }; if (!user.items.food.RottenMeat) user.items.food.RottenMeat = 0; - user.items.food.RottenMeat += 4; + user.items.food = { + ...user.items.food, + RottenMeat: user.items.food.RottenMeat + 4, + }; if (user.markModified) user.markModified('items.food'); }, }, @@ -875,7 +1007,10 @@ export default function getLoginIncentives (api) { rewardName: 'threeSaddles', assignReward: function assignReward (user) { if (!user.items.food.Saddle) user.items.food.Saddle = 0; - user.items.food.Saddle += 3; + user.items.food = { + ...user.items.food, + Saddle: user.items.food.Saddle + 3, + }; if (user.markModified) user.markModified('items.food'); }, }, diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index 5c95bf4505..0719685e31 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -79,8 +79,14 @@ export default function randomDrop (user, options, req = {}, analytics) { canDrop: true, }))); - user.items.food[drop.key] = user.items.food[drop.key] || 0; - user.items.food[drop.key] += 1; + user.items.food = { + ...user.items.food, + [drop.key]: user.items.food[drop.key] || 0, + }; + user.items.food = { + ...user.items.food, + [drop.key]: +1, + }; if (user.markModified) user.markModified('items.food'); drop.type = 'Food'; diff --git a/website/common/script/ops/buy/buyArmoire.js b/website/common/script/ops/buy/buyArmoire.js index ce7a978512..e370c0d1b5 100644 --- a/website/common/script/ops/buy/buyArmoire.js +++ b/website/common/script/ops/buy/buyArmoire.js @@ -129,8 +129,13 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation { // eslint-d canDrop: true, })); - user.items.food[drop.key] = user.items.food[drop.key] || 0; - user.items.food[drop.key] += 1; + user.items.food = { + ...user.items.food, + [drop.key]: user.items.food[drop.key] || 0, + }; + user.items.food = { + [drop.key]: drop.key + 1, + }; if (user.markModified) user.markModified('items.food'); if (this.analytics) { diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index 58a204fe22..4f88b3c0d9 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -95,7 +95,10 @@ export default function feed (user, req = {}) { } } - user.items.food[food.key] -= 1; + user.items.food = { + ...user.items.food, + [food.key]: user.items.food[food.key] - 1, + }; if (user.markModified) user.markModified('items.food'); forEach(content.animalColorAchievements, achievement => { From 2c0da084eaede3b08181cd2bcefc2eb39d68fc55 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 15 Dec 2019 22:18:26 +0300 Subject: [PATCH 08/10] Fix: reassign object for user.items.quest to trigger change in vue view --- website/common/script/content/loginIncentives.js | 15 ++++++++++++--- website/common/script/fns/updateStats.js | 5 ++++- website/common/script/ops/buy/buyQuestGem.js | 5 ++++- website/common/script/ops/buy/buyQuestGold.js | 5 ++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/website/common/script/content/loginIncentives.js b/website/common/script/content/loginIncentives.js index 88cd142ed6..4a53cd22d4 100644 --- a/website/common/script/content/loginIncentives.js +++ b/website/common/script/content/loginIncentives.js @@ -79,7 +79,10 @@ export default function getLoginIncentives (api) { reward: [api.quests.moon1], assignReward: function assignReward (user) { if (!user.items.quests.moon1) user.items.quests.moon1 = 0; - user.items.quests.moon1 += 1; + user.items.quests = { + ...user.items.quests, + moon1: user.items.quests.moon1 + 1, + }; if (user.markModified) user.markModified('items.quests'); }, }, @@ -133,7 +136,10 @@ export default function getLoginIncentives (api) { reward: [api.quests.moon2], assignReward: function assignReward (user) { if (!user.items.quests.moon2) user.items.quests.moon2 = 0; - user.items.quests.moon2 += 1; + user.items.quests = { + ...user.items.quests, + moon2: user.items.quests.moon2 + 1, + }; if (user.markModified) user.markModified('items.quests'); }, }, @@ -193,7 +199,10 @@ export default function getLoginIncentives (api) { reward: [api.quests.moon3], assignReward: function assignReward (user) { if (!user.items.quests.moon3) user.items.quests.moon3 = 0; - user.items.quests.moon3 += 1; + user.items.quests = { + ...user.items.quests, + moon3: user.items.quests.moon3 + 1, + }; if (user.markModified) user.markModified('items.quests'); }, }, diff --git a/website/common/script/fns/updateStats.js b/website/common/script/fns/updateStats.js index 7eb672eb24..79b4f660c7 100644 --- a/website/common/script/fns/updateStats.js +++ b/website/common/script/fns/updateStats.js @@ -95,7 +95,10 @@ export default function updateStats (user, stats, req = {}, analytics) { if (user.markModified) user.markModified('flags.levelDrops'); if (!user.items.quests[k]) user.items.quests[k] = 0; - user.items.quests[k] += 1; + user.items.quests = { + ...user.items.quests, + [k]: user.items.quests[k] + 1, + }; if (user.markModified) user.markModified('items.quests'); if (analytics) { diff --git a/website/common/script/ops/buy/buyQuestGem.js b/website/common/script/ops/buy/buyQuestGem.js index 3f099d2a3a..91f60ad6df 100644 --- a/website/common/script/ops/buy/buyQuestGem.js +++ b/website/common/script/ops/buy/buyQuestGem.js @@ -47,7 +47,10 @@ export class BuyQuestWithGemOperation extends AbstractGemItemOperation { // esli !user.items.quests[item.key] || user.items.quests[item.key] < 0 ) user.items.quests[item.key] = 0; - user.items.quests[item.key] += this.quantity; + user.items.quests = { + ...user.items.quests, + [item.key]: user.items.quests[item.key] + this.quantity, + }; if (user.markModified) user.markModified('items.quests'); this.subtractCurrency(user, item, this.quantity); diff --git a/website/common/script/ops/buy/buyQuestGold.js b/website/common/script/ops/buy/buyQuestGold.js index ead059829c..a4f16d4bfd 100644 --- a/website/common/script/ops/buy/buyQuestGold.js +++ b/website/common/script/ops/buy/buyQuestGold.js @@ -67,7 +67,10 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation { // es !user.items.quests[item.key] || user.items.quests[item.key] < 0 ) user.items.quests[item.key] = 0; - user.items.quests[item.key] += this.quantity; + user.items.quests = { + ...user.items.quests, + [item.key]: user.items.quests[item.key] + this.quantity, + }; if (user.markModified) user.markModified('items.quests'); this.subtractCurrency(user, item, this.quantity); From 4b4cc61031b130e619bfc113aee14f5d8fb2f0c2 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Thu, 26 Dec 2019 22:47:14 +0300 Subject: [PATCH 09/10] Fix: remove unnecessary reassignments --- website/common/script/fns/randomDrop.js | 10 ++-------- website/common/script/fns/resetGear.js | 5 +---- website/common/script/ops/buy/buyArmoire.js | 4 +--- website/common/script/ops/buy/buyMysterySet.js | 10 ++++++---- website/common/script/ops/feed.js | 10 ++-------- website/common/script/ops/hatch.js | 11 ++--------- website/common/script/ops/releaseBoth.js | 10 ++-------- website/common/script/ops/releaseMounts.js | 5 +---- website/common/script/ops/releasePets.js | 5 +---- website/common/script/ops/revive.js | 6 ++---- 10 files changed, 20 insertions(+), 56 deletions(-) diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index 0719685e31..8067aea474 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -83,10 +83,7 @@ export default function randomDrop (user, options, req = {}, analytics) { ...user.items.food, [drop.key]: user.items.food[drop.key] || 0, }; - user.items.food = { - ...user.items.food, - [drop.key]: +1, - }; + user.items.food[drop.key] += 1; if (user.markModified) user.markModified('items.food'); drop.type = 'Food'; @@ -101,10 +98,7 @@ export default function randomDrop (user, options, req = {}, analytics) { ...user.items.eggs, [drop.key]: user.items.eggs[drop.key] || 0, }; - user.items.eggs = { - ...user.items.eggs, - [drop.key]: drop.key += 1, - }; + user.items.eggs[drop.key] += 1; if (user.markModified) user.markModified('items.eggs'); drop.type = 'Egg'; diff --git a/website/common/script/fns/resetGear.js b/website/common/script/fns/resetGear.js index 9ad23b727e..008b1a13b9 100644 --- a/website/common/script/fns/resetGear.js +++ b/website/common/script/fns/resetGear.js @@ -16,10 +16,7 @@ export default function resetGear (user) { // The content.gear.flat[k] check should prevent this causing an error each(gear.owned, (v, k) => { if (gear.owned[k] && content.gear.flat[k] && content.gear.flat[k].value) { - gear.owned = { - ...gear.owned, - [k]: false, - }; + gear.owned[k] = false; } }); diff --git a/website/common/script/ops/buy/buyArmoire.js b/website/common/script/ops/buy/buyArmoire.js index e370c0d1b5..fab02460d7 100644 --- a/website/common/script/ops/buy/buyArmoire.js +++ b/website/common/script/ops/buy/buyArmoire.js @@ -133,9 +133,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation { // eslint-d ...user.items.food, [drop.key]: user.items.food[drop.key] || 0, }; - user.items.food = { - [drop.key]: drop.key + 1, - }; + user.items.food[drop.key] += 1; if (user.markModified) user.markModified('items.food'); if (this.analytics) { diff --git a/website/common/script/ops/buy/buyMysterySet.js b/website/common/script/ops/buy/buyMysterySet.js index 4e1765c013..06ef1f9275 100644 --- a/website/common/script/ops/buy/buyMysterySet.js +++ b/website/common/script/ops/buy/buyMysterySet.js @@ -25,10 +25,7 @@ export default function buyMysterySet (user, req = {}, analytics) { } each(mysterySet.items, item => { - user.items.gear.owned = { - ...user.items.gear.owned, - [item.key]: true, - }; + user.items.gear.owned[item.key] = true; if (analytics) { analytics.track('acquire item', { uuid: user._id, @@ -41,6 +38,11 @@ export default function buyMysterySet (user, req = {}, analytics) { } }); + // Here we need to trigger vue reactivity through reassign object + user.items.gear.owned = { + ...user.items.gear.owned, + }; + if (user.markModified) user.markModified('items.gear.owned'); user.purchased.plan.consecutive.trinkets -= 1; diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index 4f88b3c0d9..be859f72c6 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -13,10 +13,7 @@ import { import errorMessage from '../libs/errorMessage'; function evolve (user, pet, req) { - user.items.pets = { - ...user.items.pets, - [pet.key]: -1, - }; + user.items.pets[pet.key] = -1; user.items.mounts = { ...user.items.mounts, @@ -95,10 +92,7 @@ export default function feed (user, req = {}) { } } - user.items.food = { - ...user.items.food, - [food.key]: user.items.food[food.key] - 1, - }; + user.items.food[food.key] -= 1; if (user.markModified) user.markModified('items.food'); forEach(content.animalColorAchievements, achievement => { diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index 4ecb1f308d..b0c6d6ea40 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -44,15 +44,8 @@ export default function hatch (user, req = {}) { ...user.items.pets, [pet]: 5, }; - user.items.eggs = { - ...user.items.eggs, - [egg]: Number.isInteger(user.items.eggs) ? user.items.eggs - 1 : 0, - }; - user.items.hatchingPotions = { - ...user.items.hatchingPotions, - [hatchingPotion]: - Number.isInteger(user.items.hatchingPotion) ? user.items.hatchingPotion - 1 : 0, - }; + user.items.eggs[egg] -= 1; + user.items.hatchingPotions[hatchingPotion] -= 1; if (user.markModified) { user.markModified('items.pets'); user.markModified('items.eggs'); diff --git a/website/common/script/ops/releaseBoth.js b/website/common/script/ops/releaseBoth.js index c97d352e9e..80a7c81241 100644 --- a/website/common/script/ops/releaseBoth.js +++ b/website/common/script/ops/releaseBoth.js @@ -60,14 +60,8 @@ export default function releaseBoth (user, req = {}) { giveMountMasterAchievement = false; } - user.items.pets = { - ...user.items.pets, - [animal]: 0, - }; - user.items.mounts = { - ...user.items.mounts, - [animal]: null, - }; + user.items.pets[animal] = 0; + user.items.mounts[animal] = null; } if (user.markModified) { diff --git a/website/common/script/ops/releaseMounts.js b/website/common/script/ops/releaseMounts.js index e63a1ec4c5..b41e50d861 100644 --- a/website/common/script/ops/releaseMounts.js +++ b/website/common/script/ops/releaseMounts.js @@ -28,10 +28,7 @@ export default function releaseMounts (user, req = {}, analytics) { if (user.items.mounts[mount] === null || user.items.mounts[mount] === undefined) { giveMountMasterAchievement = false; } - user.items.mounts = { - ...user.items.mounts, - [mount]: null, - }; + user.items.mounts[mount] = null; } if (user.markModified) user.markModified('items.mounts'); diff --git a/website/common/script/ops/releasePets.js b/website/common/script/ops/releasePets.js index 6dc1fbd7e6..df7596a1a3 100644 --- a/website/common/script/ops/releasePets.js +++ b/website/common/script/ops/releasePets.js @@ -28,10 +28,7 @@ export default function releasePets (user, req = {}, analytics) { if (!user.items.pets[pet]) { giveBeastMasterAchievement = false; } - user.items.pets = { - ...user.items.pets, - [pet]: 0, - }; + user.items.pets[pet] = 0; } if (user.markModified) user.markModified('items.pets'); diff --git a/website/common/script/ops/revive.js b/website/common/script/ops/revive.js index b50c1ca7e5..8718030005 100644 --- a/website/common/script/ops/revive.js +++ b/website/common/script/ops/revive.js @@ -89,10 +89,8 @@ export default function revive (user, req = {}, analytics) { if (item) { removePinnedGearByClass(user); - user.items.gear.owned = { - ...user.items.gear.owned, - [lostItem]: false, - }; + user.items.gear.owned[lostItem] = false; + if (user.markModified) user.markModified('items.gear.owned'); addPinnedGearByClass(user); From 2c65b3a6a3aeeb302e7842c78f7d7641e7f889b1 Mon Sep 17 00:00:00 2001 From: Xaz16 Date: Sun, 29 Dec 2019 20:58:10 +0300 Subject: [PATCH 10/10] Fix: remove unnecessary reassigment --- website/common/script/fns/randomDrop.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index 8067aea474..beec977469 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -124,10 +124,8 @@ export default function randomDrop (user, options, req = {}, analytics) { ...user.items.hatchingPotions, [drop.key]: user.items.hatchingPotions[drop.key] || 0, }; - user.items.hatchingPotions = { - ...user.items.hatchingPotions, - [drop.key]: drop.key + 1, - }; + user.items.hatchingPotions[drop.key] += 1; + if (user.markModified) user.markModified('items.hatchingPotions'); drop.type = 'HatchingPotion';