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",
"description": "Gilded Rose kata in JavaScript with Jest",
"engines": {
"node": ">=12.18.0",
"npm": ">=6.14.8"
"node": ">=10.16.0",
"npm": ">=6.14.5"
},
"scripts": {
"start": "babel-node ./test/texttest_fixture.js",

View File

@ -1,6 +1,7 @@
const AGED_CHEESE = ['Aged Brie']
const CONCERT_PASS = ['Backstage passes to a TAFKAL80ETC concert']
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
@ -142,6 +143,15 @@ export class LegendaryItem extends RegularItem {
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 {
constructor (items = []) {
/*
@ -225,11 +235,20 @@ export class ShopV2 extends Shop {
// Special Items
if (LEGENDARY_ITEMS.indexOf(name) !== -1) {
ItemClass = LegendaryItem
} else if (AGED_CHEESE.indexOf(name) !== -1) {
}
if (AGED_CHEESE.indexOf(name) !== -1) {
ItemClass = AgedCheese
} else if (CONCERT_PASS.indexOf(name) !== -1) {
}
if (CONCERT_PASS.indexOf(name) !== -1) {
ItemClass = ConcertPass
}
if (CONJURED_ITEMS.indexOf(name) !== -1) {
ItemClass = ConjuredItem
}
return new ItemClass({ name, sellIn, quality })
})