mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
make sure to clone drop so original properties do not change
This commit is contained in:
@@ -4,6 +4,13 @@ import i18n from '../i18n';
|
|||||||
import { daysSince } from '../cron';
|
import { daysSince } from '../cron';
|
||||||
import { diminishingReturns } from '../statHelpers';
|
import { diminishingReturns } from '../statHelpers';
|
||||||
|
|
||||||
|
// Clone a drop object maintaining its functions so that we can change it without affecting the original item
|
||||||
|
function cloneDropItem (drop) {
|
||||||
|
return _.cloneDeep(drop, function (val) {
|
||||||
|
return _.isFunction(val) ? val : undefined; // undefined will be handled by lodash
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function(user, modifiers, req) {
|
module.exports = function(user, modifiers, req) {
|
||||||
var acceptableDrops, base, base1, base2, chance, drop, dropK, dropMultiplier, name, name1, name2, quest, rarity, ref, ref1, ref2, ref3, task;
|
var acceptableDrops, base, base1, base2, chance, drop, dropK, dropMultiplier, name, name1, name2, quest, rarity, ref, ref1, ref2, ref3, task;
|
||||||
task = modifiers.task;
|
task = modifiers.task;
|
||||||
@@ -29,9 +36,9 @@ module.exports = function(user, modifiers, req) {
|
|||||||
if (((ref3 = user.flags) != null ? ref3.dropsEnabled : void 0) && user.fns.predictableRandom(user.stats.exp) < chance) {
|
if (((ref3 = user.flags) != null ? ref3.dropsEnabled : void 0) && user.fns.predictableRandom(user.stats.exp) < chance) {
|
||||||
rarity = user.fns.predictableRandom(user.stats.gp);
|
rarity = user.fns.predictableRandom(user.stats.gp);
|
||||||
if (rarity > .6) {
|
if (rarity > .6) {
|
||||||
drop = user.fns.randomVal(_.where(content.food, {
|
drop = cloneDropItem(user.fns.randomVal(_.where(content.food, {
|
||||||
canDrop: true
|
canDrop: true
|
||||||
}));
|
})));
|
||||||
if ((base = user.items.food)[name = drop.key] == null) {
|
if ((base = user.items.food)[name = drop.key] == null) {
|
||||||
base[name] = 0;
|
base[name] = 0;
|
||||||
}
|
}
|
||||||
@@ -43,7 +50,7 @@ module.exports = function(user, modifiers, req) {
|
|||||||
dropNotes: drop.notes(req.language)
|
dropNotes: drop.notes(req.language)
|
||||||
}, req.language);
|
}, req.language);
|
||||||
} else if (rarity > .3) {
|
} else if (rarity > .3) {
|
||||||
drop = user.fns.randomVal(content.dropEggs);
|
drop = cloneDropItem(user.fns.randomVal(content.dropEggs));
|
||||||
if ((base1 = user.items.eggs)[name1 = drop.key] == null) {
|
if ((base1 = user.items.eggs)[name1 = drop.key] == null) {
|
||||||
base1[name1] = 0;
|
base1[name1] = 0;
|
||||||
}
|
}
|
||||||
@@ -55,9 +62,9 @@ module.exports = function(user, modifiers, req) {
|
|||||||
}, req.language);
|
}, req.language);
|
||||||
} else {
|
} else {
|
||||||
acceptableDrops = rarity < .02 ? ['Golden'] : rarity < .09 ? ['Zombie', 'CottonCandyPink', 'CottonCandyBlue'] : rarity < .18 ? ['Red', 'Shade', 'Skeleton'] : ['Base', 'White', 'Desert'];
|
acceptableDrops = rarity < .02 ? ['Golden'] : rarity < .09 ? ['Zombie', 'CottonCandyPink', 'CottonCandyBlue'] : rarity < .18 ? ['Red', 'Shade', 'Skeleton'] : ['Base', 'White', 'Desert'];
|
||||||
drop = user.fns.randomVal(_.pick(content.hatchingPotions, (function(v, k) {
|
drop = cloneDropItem(user.fns.randomVal(_.pick(content.hatchingPotions, (function(v, k) {
|
||||||
return acceptableDrops.indexOf(k) >= 0;
|
return acceptableDrops.indexOf(k) >= 0;
|
||||||
})));
|
}))));
|
||||||
if ((base2 = user.items.hatchingPotions)[name2 = drop.key] == null) {
|
if ((base2 = user.items.hatchingPotions)[name2 = drop.key] == null) {
|
||||||
base2[name2] = 0;
|
base2[name2] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user