mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
feat(event): 10th Birthday Bash
with @CuriousMagpie and @phillipthelen
This commit is contained in:
@@ -13,6 +13,7 @@ import hourglassPurchase from './hourglassPurchase';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import { BuyGemOperation } from './buyGem';
|
||||
import { BuyQuestWithGemOperation } from './buyQuestGem';
|
||||
import { BuyPetWithGemOperation } from './buyPetGem';
|
||||
import { BuyHourglassMountOperation } from './buyMount';
|
||||
|
||||
// @TODO: remove the req option style. Dependency on express structure is an anti-pattern
|
||||
@@ -86,7 +87,12 @@ export default async function buy (
|
||||
break;
|
||||
}
|
||||
case 'pets':
|
||||
buyRes = hourglassPurchase(user, req, analytics);
|
||||
if (key === 'Gryphatrice-Jubilant') {
|
||||
const buyOp = new BuyPetWithGemOperation(user, req, analytics);
|
||||
buyRes = await buyOp.purchase();
|
||||
} else {
|
||||
buyRes = hourglassPurchase(user, req, analytics);
|
||||
}
|
||||
break;
|
||||
case 'quest': {
|
||||
const buyOp = new BuyQuestWithGoldOperation(user, req, analytics);
|
||||
|
||||
61
website/common/script/ops/buy/buyPetGem.js
Normal file
61
website/common/script/ops/buy/buyPetGem.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
BadRequest,
|
||||
NotFound,
|
||||
} from '../../libs/errors';
|
||||
import content from '../../content/index';
|
||||
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import { AbstractGemItemOperation } from './abstractBuyOperation';
|
||||
|
||||
export class BuyPetWithGemOperation extends AbstractGemItemOperation { // eslint-disable-line import/prefer-default-export, max-len
|
||||
multiplePurchaseAllowed () { // eslint-disable-line class-methods-use-this
|
||||
return false;
|
||||
}
|
||||
|
||||
getItemKey () {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
getItemValue (item) { // eslint-disable-line class-methods-use-this
|
||||
return item.value / 4;
|
||||
}
|
||||
|
||||
getItemType () { // eslint-disable-line class-methods-use-this
|
||||
return 'pet';
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
this.key = get(req, 'params.key');
|
||||
const { key } = this;
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
const item = content.petInfo[key];
|
||||
|
||||
if (!item) throw new NotFound(errorMessage('petNotFound', { key }));
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
}
|
||||
|
||||
canUserPurchase (user, item) {
|
||||
if (item && user.items.pets[item.key]) {
|
||||
throw new BadRequest(this.i18n('petsAlreadyOwned'));
|
||||
}
|
||||
|
||||
super.canUserPurchase(user, item);
|
||||
}
|
||||
|
||||
async executeChanges (user, item, req) {
|
||||
user.items.pets[item.key] = 5;
|
||||
if (user.markModified) user.markModified('items.pets');
|
||||
|
||||
await this.subtractCurrency(user, item);
|
||||
|
||||
return [
|
||||
user.items.pets,
|
||||
this.i18n('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -251,9 +251,10 @@ export default async function unlock (user, req = {}, analytics) {
|
||||
return invalidSet(req);
|
||||
}
|
||||
|
||||
cost = getIndividualItemPrice(setType, item, req);
|
||||
|
||||
unlockedAlready = alreadyUnlocked(user, setType, firstPath);
|
||||
if (!unlockedAlready) {
|
||||
cost = getIndividualItemPrice(setType, item, req);
|
||||
}
|
||||
|
||||
// Since only an item is being unlocked here,
|
||||
// remove all the other items from the set
|
||||
|
||||
Reference in New Issue
Block a user