feat(event): 10th Birthday Bash

with @CuriousMagpie and @phillipthelen
This commit is contained in:
SabreCat
2023-01-20 16:14:33 -06:00
parent a8cb303f46
commit e5bbde7e97
64 changed files with 2185 additions and 235 deletions

View File

@@ -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);

View 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),
}),
];
}
}

View File

@@ -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