From 354c068f33269edbb711668b84d11cdc005b51b8 Mon Sep 17 00:00:00 2001 From: Daniel F Date: Tue, 11 Jul 2023 22:26:10 +0100 Subject: [PATCH] Updated NormalItemUpdateService --- go/services/normal_item_update_service.go | 52 ++++------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/go/services/normal_item_update_service.go b/go/services/normal_item_update_service.go index b10430fc..d43712a6 100644 --- a/go/services/normal_item_update_service.go +++ b/go/services/normal_item_update_service.go @@ -16,56 +16,22 @@ func NewNormalItemUpdateService(logger lib.Logger) NormalItemUpdateService { } func (this NormalItemUpdateService) UpdateQuality(item *models.Item) error { + decrement := 1 + item.Mutex.Lock() defer item.Mutex.Unlock() itemModel := item.Model - if itemModel.Name != "Aged Brie" && itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } + if itemModel.SellIn <= 0 { + decrement *= 2 + } + if (itemModel.Quality - decrement) < 0 { + itemModel.Quality = 0 } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - if itemModel.Name == "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.SellIn < 11 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - if itemModel.SellIn < 6 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - } - } - } - - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.SellIn = itemModel.SellIn - 1 - } - - if itemModel.SellIn < 0 { - if itemModel.Name != "Aged Brie" { - if itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } - } else { - itemModel.Quality = itemModel.Quality - itemModel.Quality - } - } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } + itemModel.Quality -= decrement } + itemModel.SellIn-- return nil }