mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
* WIP(analytics): add / improve tracking * fix(groups): revert attempt at tracking on group model * fix(analytics): track questing based on user data * each buy-operation now has a getItemType method - typo getItemKey - removed unneeded overrides
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
import content from '../../content/index';
|
|
import {
|
|
NotAuthorized,
|
|
} from '../../libs/errors';
|
|
|
|
import { AbstractGoldItemOperation} from './abstractBuyOperation';
|
|
|
|
export class BuyHealthPotionOperation extends AbstractGoldItemOperation {
|
|
constructor (user, req, analytics) {
|
|
super(user, req, analytics);
|
|
}
|
|
|
|
multiplePurchaseAllowed () {
|
|
return true;
|
|
}
|
|
|
|
extractAndValidateParams (user) {
|
|
let item = content.potion;
|
|
let userHp = user.stats.hp;
|
|
|
|
super.canUserPurchase(user, item);
|
|
|
|
if (userHp >= 50) {
|
|
throw new NotAuthorized(this.i18n('messageHealthAlreadyMax'));
|
|
}
|
|
|
|
if (userHp <= 0) {
|
|
throw new NotAuthorized(this.i18n('messageHealthAlreadyMin'));
|
|
}
|
|
}
|
|
|
|
executeChanges (user, item) {
|
|
user.stats.hp += 15 * this.quantity;
|
|
if (user.stats.hp > 50) {
|
|
user.stats.hp = 50;
|
|
}
|
|
|
|
this.subtractCurrency(user, item, this.quantity);
|
|
|
|
let message = this.i18n('messageBought', {
|
|
itemText: this.item.text(this.req.language),
|
|
});
|
|
|
|
return [
|
|
this.user.stats,
|
|
message,
|
|
];
|
|
}
|
|
}
|