mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
start fixing commong
This commit is contained in:
@@ -14,10 +14,10 @@ import statsComputed from '../libs/statsComputed';
|
||||
// TODO This is only used on the server
|
||||
// move to user model as an instance method?
|
||||
|
||||
// Clone a drop object maintaining its functions so that we can change it without affecting the original item
|
||||
// Clone a drop object maintaining its functions
|
||||
// so that we can change it without affecting the original item
|
||||
function cloneDropItem (drop) {
|
||||
return cloneDeepWith(drop, val => (isFunction(val) ? val : undefined), // undefined will be handled by lodash
|
||||
);
|
||||
return cloneDeepWith(drop, val => (isFunction(val) ? val : undefined));
|
||||
}
|
||||
|
||||
function trueRandom () {
|
||||
@@ -40,14 +40,17 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
* (1 + (user.contributor.level / 40 || 0)) // Contrib levels: +2.5% per level
|
||||
* (1 + (user.achievements.rebirths / 20 || 0)) // Rebirths: +5% per achievement
|
||||
* (1 + (user.achievements.streak / 200 || 0)) // Streak achievements: +0.5% per achievement
|
||||
* (user._tmp.crit || 1) * (1 + 0.5 * (reduce(task.checklist, (m, i) => // +50% per checklist item complete. TODO: make this into X individual drop chances instead
|
||||
m + (i.completed ? 1 : 0), // eslint-disable-line indent
|
||||
0) || 0)); // eslint-disable-line indent
|
||||
// +50% per checklist item complete. TODO: make this into X individual drop chances instead
|
||||
* (user._tmp.crit || 1)
|
||||
* (1 + 0.5 * (reduce(
|
||||
task.checklist, (m, i) => m + (i.completed ? 1 : 0), // eslint-disable-line indent
|
||||
0,
|
||||
) || 0)); // eslint-disable-line indent
|
||||
chance = diminishingReturns(chance, 0.75);
|
||||
|
||||
if (predictableRandom() < chance) {
|
||||
user.party.quest.progress.collectedItems = user.party.quest.progress.collectedItems || 0;
|
||||
user.party.quest.progress.collectedItems++;
|
||||
user.party.quest.progress.collectedItems += 1;
|
||||
user._tmp.quest = user._tmp.quest || {};
|
||||
user._tmp.quest.collection = 1;
|
||||
if (user.markModified) user.markModified('party.quest.progress');
|
||||
@@ -59,8 +62,10 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
dropMultiplier = 1;
|
||||
}
|
||||
|
||||
if (daysSince(user.items.lastDrop.date, user.preferences) === 0
|
||||
&& user.items.lastDrop.count >= dropMultiplier * (5 + Math.floor(statsComputed(user).per / 25) + (user.contributor.level || 0))) {
|
||||
if (
|
||||
daysSince(user.items.lastDrop.date, user.preferences) === 0
|
||||
&& user.items.lastDrop.count >= dropMultiplier * (5 + Math.floor(statsComputed(user).per / 25) + (user.contributor.level || 0))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,7 +90,7 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
drop = cloneDropItem(randomVal(content.dropEggs));
|
||||
|
||||
user.items.eggs[drop.key] = user.items.eggs[drop.key] || 0;
|
||||
user.items.eggs[drop.key]++;
|
||||
user.items.eggs[drop.key] += 1;
|
||||
if (user.markModified) user.markModified('items.eggs');
|
||||
|
||||
drop.type = 'Egg';
|
||||
@@ -103,10 +108,12 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
} else { // common, 40% of 30%
|
||||
acceptableDrops = ['Base', 'White', 'Desert'];
|
||||
}
|
||||
drop = cloneDropItem(randomVal(pickBy(content.hatchingPotions, (v, k) => acceptableDrops.indexOf(k) >= 0)));
|
||||
drop = cloneDropItem(
|
||||
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]++;
|
||||
user.items.hatchingPotions[drop.key] += 1;
|
||||
if (user.markModified) user.markModified('items.hatchingPotions');
|
||||
|
||||
drop.type = 'HatchingPotion';
|
||||
@@ -128,6 +135,6 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
|
||||
user._tmp.drop = drop;
|
||||
user.items.lastDrop.date = Number(new Date());
|
||||
user.items.lastDrop.count++;
|
||||
user.items.lastDrop.count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user