mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Adventure Guide Prep (#11883)
* WIP(adventure): prereqs * WIP(drops): new modal * WIP(adventure): analytics fixes etc * feat(adventure): random egg+potion on 2nd task * fix(lint): noworkies * fix(modal): correctly construct classes * fix(tests): expectations and escape * fix(first-drops): address comments * fix(first-drops): don't give random drops until first drops * fix(drops): remove more Level 3 references * refactor(drops): no need for cloning * refactor(drops): unnecessary export * fix(first-drops): force sync * fix(first-drops): move to server * fix(first-drops): escape in case we get here with >0 items * fix(lint): line length * fix(pet-food): remove unused string
This commit is contained in:
@@ -4,12 +4,15 @@ import min from 'lodash/min';
|
||||
import reduce from 'lodash/reduce';
|
||||
import filter from 'lodash/filter';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import size from 'lodash/size';
|
||||
import moment from 'moment';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import { daysSince } from '../cron';
|
||||
import { diminishingReturns } from '../statHelpers';
|
||||
import randomVal from '../libs/randomVal';
|
||||
import statsComputed from '../libs/statsComputed';
|
||||
import firstDrops from './firstDrops';
|
||||
|
||||
// TODO This is only used on the server
|
||||
// move to user model as an instance method?
|
||||
@@ -30,6 +33,14 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
let dropMultiplier;
|
||||
let rarity;
|
||||
|
||||
if (
|
||||
size(user.items.eggs) < 1
|
||||
&& size(user.items.hatchingPotions) < 1
|
||||
) {
|
||||
user._tmp.firstDrops = firstDrops(user);
|
||||
return;
|
||||
}
|
||||
|
||||
const predictableRandom = options.predictableRandom || trueRandom;
|
||||
const { task } = options;
|
||||
|
||||
@@ -71,7 +82,7 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.flags && user.flags.dropsEnabled && predictableRandom() < chance) {
|
||||
if (predictableRandom() < chance) {
|
||||
rarity = predictableRandom();
|
||||
|
||||
if (rarity > 0.6) { // food 40% chance
|
||||
@@ -135,7 +146,7 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
}, req.language);
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
if (analytics && moment().diff(user.auth.timestamps.created, 'days') < 7) {
|
||||
analytics.track('dropped item', {
|
||||
uuid: user._id,
|
||||
itemKey: drop.key,
|
||||
|
||||
Reference in New Issue
Block a user