mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Separate out backer gear into own module
This commit is contained in:
93
common/script/content/gear/sets/special-backer.js
Normal file
93
common/script/content/gear/sets/special-backer.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import { ownsItem } from '../gear-helper';
|
||||||
|
import t from '../../translation';
|
||||||
|
|
||||||
|
let isBackerOfLevel = (tierRequirement, ownedItem) => {
|
||||||
|
return (user) => {
|
||||||
|
let backer = user.backer;
|
||||||
|
let tier = Number(backer && backer.tier);
|
||||||
|
|
||||||
|
return tier >= tierRequirement || ownsItem(ownedItem)(user);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
let armorSpecial0 = {
|
||||||
|
text: t('armorSpecial0Text'),
|
||||||
|
notes: t('armorSpecial0Notes', { con: 20 }),
|
||||||
|
con: 20,
|
||||||
|
value: 150,
|
||||||
|
canOwn: isBackerOfLevel(45, 'armor_special_0'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let armorSpecial2 = {
|
||||||
|
text: t('armorSpecial2Text'),
|
||||||
|
notes: t('armorSpecial2Notes', { attrs: 25 }),
|
||||||
|
int: 25,
|
||||||
|
con: 25,
|
||||||
|
value: 200,
|
||||||
|
canOwn: isBackerOfLevel(300, 'armor_special_2'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let headSpecial0 = {
|
||||||
|
text: t('headSpecial0Text'),
|
||||||
|
notes: t('headSpecial0Notes', { int: 20 }),
|
||||||
|
int: 20,
|
||||||
|
value: 150,
|
||||||
|
canOwn: isBackerOfLevel(45, 'head_special_0'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let headSpecial2 = {
|
||||||
|
text: t('headSpecial2Text'),
|
||||||
|
notes: t('headSpecial2Notes', { attrs: 25 }),
|
||||||
|
int: 25,
|
||||||
|
str: 25,
|
||||||
|
value: 200,
|
||||||
|
canOwn: isBackerOfLevel(300, 'head_special_2'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let shieldSpecial0 = {
|
||||||
|
text: t('shieldSpecial0Text'),
|
||||||
|
notes: t('shieldSpecial0Notes', { per: 20 }),
|
||||||
|
per: 20,
|
||||||
|
value: 150,
|
||||||
|
canOwn: isBackerOfLevel(45, 'shield_special_0'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let weaponSpecial0 = {
|
||||||
|
text: t('weaponSpecial0Text'),
|
||||||
|
notes: t('weaponSpecial0Notes', { str: 20 }),
|
||||||
|
str: 20,
|
||||||
|
value: 150,
|
||||||
|
canOwn: isBackerOfLevel(70, 'weapon_special_0'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let weaponSpecial2 = {
|
||||||
|
text: t('weaponSpecial2Text'),
|
||||||
|
notes: t('weaponSpecial2Notes', { attrs: 25 }),
|
||||||
|
str: 25,
|
||||||
|
per: 25,
|
||||||
|
value: 200,
|
||||||
|
canOwn: isBackerOfLevel(300, 'weapon_special_2'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let weaponSpecial3 = {
|
||||||
|
text: t('weaponSpecial3Text'),
|
||||||
|
notes: t('weaponSpecial3Notes', { attrs: 17 }),
|
||||||
|
str: 17,
|
||||||
|
int: 17,
|
||||||
|
con: 17,
|
||||||
|
value: 200,
|
||||||
|
canOwn: isBackerOfLevel(300, 'weapon_special_3'),
|
||||||
|
};
|
||||||
|
|
||||||
|
let backerSet = {
|
||||||
|
armorSpecial0,
|
||||||
|
armorSpecial2,
|
||||||
|
headSpecial0,
|
||||||
|
headSpecial2,
|
||||||
|
shieldSpecial0,
|
||||||
|
weaponSpecial0,
|
||||||
|
weaponSpecial2,
|
||||||
|
weaponSpecial3,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default backerSet;
|
||||||
@@ -1,19 +1,10 @@
|
|||||||
/* eslint-disable camelcase */
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
EVENTS,
|
EVENTS,
|
||||||
} from '../../constants';
|
} from '../../constants';
|
||||||
import { ownsItem } from '../gear-helper';
|
import { ownsItem } from '../gear-helper';
|
||||||
|
import backerGear from './special-backer';
|
||||||
import t from '../../translation';
|
import t from '../../translation';
|
||||||
|
|
||||||
let isBackerOfLevel = (tierRequirement, ownedItem) => {
|
|
||||||
return (user) => {
|
|
||||||
let backer = user.backer;
|
|
||||||
let tier = backer && backer.tier;
|
|
||||||
return Number(tier) >= tierRequirement || ownsItem(ownedItem)(user);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
let isContributorOfLevel = (tierRequirement, ownedItem) => {
|
let isContributorOfLevel = (tierRequirement, ownedItem) => {
|
||||||
return (user) => {
|
return (user) => {
|
||||||
let contributor = user.contributor;
|
let contributor = user.contributor;
|
||||||
@@ -24,13 +15,7 @@ let isContributorOfLevel = (tierRequirement, ownedItem) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let armor = {
|
let armor = {
|
||||||
0: {
|
0: backerGear.armorSpecial0,
|
||||||
text: t('armorSpecial0Text'),
|
|
||||||
notes: t('armorSpecial0Notes', { con: 20 }),
|
|
||||||
con: 20,
|
|
||||||
value: 150,
|
|
||||||
canOwn: isBackerOfLevel(45),
|
|
||||||
},
|
|
||||||
1: {
|
1: {
|
||||||
text: t('armorSpecial1Text'),
|
text: t('armorSpecial1Text'),
|
||||||
notes: t('armorSpecial1Notes', { attrs: 6 }),
|
notes: t('armorSpecial1Notes', { attrs: 6 }),
|
||||||
@@ -41,14 +26,7 @@ let armor = {
|
|||||||
value: 170,
|
value: 170,
|
||||||
canOwn: isContributorOfLevel(2),
|
canOwn: isContributorOfLevel(2),
|
||||||
},
|
},
|
||||||
2: {
|
2: backerGear.armorSpecial2,
|
||||||
text: t('armorSpecial2Text'),
|
|
||||||
notes: t('armorSpecial2Notes', { attrs: 25 }),
|
|
||||||
int: 25,
|
|
||||||
con: 25,
|
|
||||||
value: 200,
|
|
||||||
canOwn: isBackerOfLevel(300, 'armor_special_2'),
|
|
||||||
},
|
|
||||||
finnedOceanicArmor: {
|
finnedOceanicArmor: {
|
||||||
text: t('armorSpecialFinnedOceanicArmorText'),
|
text: t('armorSpecialFinnedOceanicArmorText'),
|
||||||
notes: t('armorSpecialFinnedOceanicArmorNotes', { str: 15 }),
|
notes: t('armorSpecialFinnedOceanicArmorNotes', { str: 15 }),
|
||||||
@@ -343,13 +321,13 @@ let armor = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let back = {
|
let back = {
|
||||||
wondercon_red: {
|
wondercon_red: { // eslint-disable-line camelcase
|
||||||
text: t('backSpecialWonderconRedText'),
|
text: t('backSpecialWonderconRedText'),
|
||||||
notes: t('backSpecialWonderconRedNotes'),
|
notes: t('backSpecialWonderconRedNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
mystery: 'wondercon',
|
mystery: 'wondercon',
|
||||||
},
|
},
|
||||||
wondercon_black: {
|
wondercon_black: { // eslint-disable-line camelcase
|
||||||
text: t('backSpecialWonderconBlackText'),
|
text: t('backSpecialWonderconBlackText'),
|
||||||
notes: t('backSpecialWonderconBlackNotes'),
|
notes: t('backSpecialWonderconBlackNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
@@ -358,19 +336,19 @@ let back = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = {
|
let body = {
|
||||||
wondercon_red: {
|
wondercon_red: { // eslint-disable-line camelcase
|
||||||
text: t('bodySpecialWonderconRedText'),
|
text: t('bodySpecialWonderconRedText'),
|
||||||
notes: t('bodySpecialWonderconRedNotes'),
|
notes: t('bodySpecialWonderconRedNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
mystery: 'wondercon',
|
mystery: 'wondercon',
|
||||||
},
|
},
|
||||||
wondercon_gold: {
|
wondercon_gold: { // eslint-disable-line camelcase
|
||||||
text: t('bodySpecialWonderconGoldText'),
|
text: t('bodySpecialWonderconGoldText'),
|
||||||
notes: t('bodySpecialWonderconGoldNotes'),
|
notes: t('bodySpecialWonderconGoldNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
mystery: 'wondercon',
|
mystery: 'wondercon',
|
||||||
},
|
},
|
||||||
wondercon_black: {
|
wondercon_black: { // eslint-disable-line camelcase
|
||||||
text: t('bodySpecialWonderconBlackText'),
|
text: t('bodySpecialWonderconBlackText'),
|
||||||
notes: t('bodySpecialWonderconBlackNotes'),
|
notes: t('bodySpecialWonderconBlackNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
@@ -421,13 +399,13 @@ let body = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let eyewear = {
|
let eyewear = {
|
||||||
wondercon_red: {
|
wondercon_red: { // eslint-disable-line camelcase
|
||||||
text: t('eyewearSpecialWonderconRedText'),
|
text: t('eyewearSpecialWonderconRedText'),
|
||||||
notes: t('eyewearSpecialWonderconRedNotes'),
|
notes: t('eyewearSpecialWonderconRedNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
mystery: 'wondercon',
|
mystery: 'wondercon',
|
||||||
},
|
},
|
||||||
wondercon_black: {
|
wondercon_black: { // eslint-disable-line camelcase
|
||||||
text: t('eyewearSpecialWonderconBlackText'),
|
text: t('eyewearSpecialWonderconBlackText'),
|
||||||
notes: t('eyewearSpecialWonderconBlackNotes'),
|
notes: t('eyewearSpecialWonderconBlackNotes'),
|
||||||
value: 0,
|
value: 0,
|
||||||
@@ -450,13 +428,7 @@ let eyewear = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let head = {
|
let head = {
|
||||||
0: {
|
0: backerGear.headSpecial0,
|
||||||
text: t('headSpecial0Text'),
|
|
||||||
notes: t('headSpecial0Notes', { int: 20 }),
|
|
||||||
int: 20,
|
|
||||||
value: 150,
|
|
||||||
canOwn: isBackerOfLevel(45),
|
|
||||||
},
|
|
||||||
1: {
|
1: {
|
||||||
text: t('headSpecial1Text'),
|
text: t('headSpecial1Text'),
|
||||||
notes: t('headSpecial1Notes', { attrs: 6 }),
|
notes: t('headSpecial1Notes', { attrs: 6 }),
|
||||||
@@ -467,14 +439,7 @@ let head = {
|
|||||||
value: 170,
|
value: 170,
|
||||||
canOwn: isContributorOfLevel(3),
|
canOwn: isContributorOfLevel(3),
|
||||||
},
|
},
|
||||||
2: {
|
2: backerGear.headSpecial2,
|
||||||
text: t('headSpecial2Text'),
|
|
||||||
notes: t('headSpecial2Notes', { attrs: 25 }),
|
|
||||||
int: 25,
|
|
||||||
str: 25,
|
|
||||||
value: 200,
|
|
||||||
canOwn: isBackerOfLevel(300, 'head_special_2'),
|
|
||||||
},
|
|
||||||
fireCoralCirclet: {
|
fireCoralCirclet: {
|
||||||
text: t('headSpecialFireCoralCircletText'),
|
text: t('headSpecialFireCoralCircletText'),
|
||||||
notes: t('headSpecialFireCoralCircletNotes', { per: 15 }),
|
notes: t('headSpecialFireCoralCircletNotes', { per: 15 }),
|
||||||
@@ -910,13 +875,7 @@ let headAccessory = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let shield = {
|
let shield = {
|
||||||
0: {
|
0: backerGear.shieldSpecial0,
|
||||||
text: t('shieldSpecial0Text'),
|
|
||||||
notes: t('shieldSpecial0Notes', { per: 20 }),
|
|
||||||
per: 20,
|
|
||||||
value: 150,
|
|
||||||
canOwn: isBackerOfLevel(45),
|
|
||||||
},
|
|
||||||
1: {
|
1: {
|
||||||
text: t('shieldSpecial1Text'),
|
text: t('shieldSpecial1Text'),
|
||||||
notes: t('shieldSpecial1Notes', { attrs: 6 }),
|
notes: t('shieldSpecial1Notes', { attrs: 6 }),
|
||||||
@@ -1146,13 +1105,7 @@ let shield = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let weapon = {
|
let weapon = {
|
||||||
0: {
|
0: backerGear.weaponSpecial0,
|
||||||
text: t('weaponSpecial0Text'),
|
|
||||||
notes: t('weaponSpecial0Notes', { str: 20 }),
|
|
||||||
str: 20,
|
|
||||||
value: 150,
|
|
||||||
canOwn: isBackerOfLevel(70),
|
|
||||||
},
|
|
||||||
1: {
|
1: {
|
||||||
text: t('weaponSpecial1Text'),
|
text: t('weaponSpecial1Text'),
|
||||||
notes: t('weaponSpecial1Notes', { attrs: 6 }),
|
notes: t('weaponSpecial1Notes', { attrs: 6 }),
|
||||||
@@ -1163,23 +1116,8 @@ let weapon = {
|
|||||||
value: 170,
|
value: 170,
|
||||||
canOwn: isContributorOfLevel(4),
|
canOwn: isContributorOfLevel(4),
|
||||||
},
|
},
|
||||||
2: {
|
2: backerGear.weaponSpecial2,
|
||||||
text: t('weaponSpecial2Text'),
|
3: backerGear.weaponSpecial3,
|
||||||
notes: t('weaponSpecial2Notes', { attrs: 25 }),
|
|
||||||
str: 25,
|
|
||||||
per: 25,
|
|
||||||
value: 200,
|
|
||||||
canOwn: isBackerOfLevel(300, 'weapon_special_2'),
|
|
||||||
},
|
|
||||||
3: {
|
|
||||||
text: t('weaponSpecial3Text'),
|
|
||||||
notes: t('weaponSpecial3Notes', { attrs: 17 }),
|
|
||||||
str: 17,
|
|
||||||
int: 17,
|
|
||||||
con: 17,
|
|
||||||
value: 200,
|
|
||||||
canOwn: isBackerOfLevel(300, 'weapon_special_3'),
|
|
||||||
},
|
|
||||||
critical: {
|
critical: {
|
||||||
text: t('weaponSpecialCriticalText'),
|
text: t('weaponSpecialCriticalText'),
|
||||||
notes: t('weaponSpecialCriticalNotes', { attrs: 40 }),
|
notes: t('weaponSpecialCriticalNotes', { attrs: 40 }),
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import {
|
|||||||
expectValidTranslationString,
|
expectValidTranslationString,
|
||||||
} from '../helpers/content.helper';
|
} from '../helpers/content.helper';
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
|
import camelCase from 'lodash.camelcase';
|
||||||
|
|
||||||
import { tree as allGear } from '../../common/script/content/gear';
|
import { tree as allGear } from '../../common/script/content/gear';
|
||||||
|
import backerGear from '../../common/script/content/gear/sets/special-backer';
|
||||||
|
|
||||||
describe('Gear', () => {
|
describe('Gear', () => {
|
||||||
each(allGear, (piece, gearType) => {
|
each(allGear, (piece, gearType) => {
|
||||||
@@ -41,4 +43,53 @@ describe('Gear', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('backer gear', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
user = {
|
||||||
|
backer: {},
|
||||||
|
items: { gear: { owned: {} } },
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
let cases = {
|
||||||
|
armor_special_0: 45,
|
||||||
|
armor_special_2: 300,
|
||||||
|
head_special_0: 45,
|
||||||
|
head_special_2: 300,
|
||||||
|
weapon_special_0: 70,
|
||||||
|
weapon_special_2: 300,
|
||||||
|
weapon_special_3: 300,
|
||||||
|
}
|
||||||
|
|
||||||
|
each(cases, (tierRequirement, key) => {
|
||||||
|
context(key, () => {
|
||||||
|
let camelCaseKey = camelCase(key);
|
||||||
|
|
||||||
|
it(`canOwn returns true if user has a backer tier of ${tierRequirement} or higher`, () => {
|
||||||
|
user.backer.tier = tierRequirement;
|
||||||
|
expect(backerGear[camelCaseKey].canOwn(user)).to.eql(true);
|
||||||
|
|
||||||
|
user.backer.tier = tierRequirement + 1;
|
||||||
|
expect(backerGear[camelCaseKey].canOwn(user)).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('canOwn returns true if user already owns the item', () => {
|
||||||
|
user.items.gear.owned[key] = true;
|
||||||
|
expect(backerGear[camelCaseKey].canOwn(user)).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('canOwn returns true if user has previously owned the item', () => {
|
||||||
|
user.items.gear.owned[key] = false;
|
||||||
|
expect(backerGear[camelCaseKey].canOwn(user)).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('canOwn returns false if user does not have tier requirement and did not previously own the item', () => {
|
||||||
|
expect(backerGear[camelCaseKey].canOwn(user)).to.eql(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user