Implemented conjured items

This commit is contained in:
Benjamin Barreto 2020-10-22 08:26:54 +02:00
parent 0abd370fd1
commit 4520c75f4c
2 changed files with 23 additions and 4 deletions

View File

@ -3,8 +3,8 @@
"version": "1.0.0", "version": "1.0.0",
"description": "Gilded Rose kata in JavaScript with Jest", "description": "Gilded Rose kata in JavaScript with Jest",
"engines": { "engines": {
"node": ">=12.18.0", "node": ">=10.16.0",
"npm": ">=6.14.8" "npm": ">=6.14.5"
}, },
"scripts": { "scripts": {
"start": "babel-node ./test/texttest_fixture.js", "start": "babel-node ./test/texttest_fixture.js",

View File

@ -1,6 +1,7 @@
const AGED_CHEESE = ['Aged Brie'] const AGED_CHEESE = ['Aged Brie']
const CONCERT_PASS = ['Backstage passes to a TAFKAL80ETC concert'] const CONCERT_PASS = ['Backstage passes to a TAFKAL80ETC concert']
const LEGENDARY_ITEMS = ['Sulfuras, Hand of Ragnaros'] const LEGENDARY_ITEMS = ['Sulfuras, Hand of Ragnaros']
const CONJURED_ITEMS = ['Conjured Mana Cake']
/** /**
* "(...) do not alter the Item class or Items property as those belong to the goblin in the corner * "(...) do not alter the Item class or Items property as those belong to the goblin in the corner
@ -142,6 +143,15 @@ export class LegendaryItem extends RegularItem {
updateQuality () {} updateQuality () {}
} }
export class ConjuredItem extends RegularItem {
constructor (itemProps) {
super(itemProps)
// "Conjured" items degrade in Quality twice as fast as normal items
this.depreciationRate = 2
}
}
export class Shop { export class Shop {
constructor (items = []) { constructor (items = []) {
/* /*
@ -225,11 +235,20 @@ export class ShopV2 extends Shop {
// Special Items // Special Items
if (LEGENDARY_ITEMS.indexOf(name) !== -1) { if (LEGENDARY_ITEMS.indexOf(name) !== -1) {
ItemClass = LegendaryItem ItemClass = LegendaryItem
} else if (AGED_CHEESE.indexOf(name) !== -1) { }
if (AGED_CHEESE.indexOf(name) !== -1) {
ItemClass = AgedCheese ItemClass = AgedCheese
} else if (CONCERT_PASS.indexOf(name) !== -1) { }
if (CONCERT_PASS.indexOf(name) !== -1) {
ItemClass = ConcertPass ItemClass = ConcertPass
} }
if (CONJURED_ITEMS.indexOf(name) !== -1) {
ItemClass = ConjuredItem
}
return new ItemClass({ name, sellIn, quality }) return new ItemClass({ name, sellIn, quality })
}) })