diff --git a/index.ts b/index.ts index cd7615c7..aab54a1b 100644 --- a/index.ts +++ b/index.ts @@ -1,11 +1,12 @@ import { Drug, Pharmacy } from "./pharmacy"; +import { Linear, DoubleAfterExpires, Reverse, ChangeAcrossExpires, ZeroAfterExpires, Double } from "./revaluations"; import fs from "fs"; const drugs = [ - new Drug("Doliprane", 20, 30), - new Drug("Herbal Tea", 10, 5), - new Drug("Fervex", 5, 40), + new Drug("Doliprane", 20, 30, [new Linear(), new DoubleAfterExpires()]), + new Drug("Herbal Tea", 10, 5, [new Linear(), new DoubleAfterExpires(), new Reverse()]), + new Drug("Fervex", 5, 40, [new Linear(), new ChangeAcrossExpires(), new Reverse(), new ZeroAfterExpires()]), new Drug("Magic Pill", 15, 40) ]; const trial = new Pharmacy(drugs); diff --git a/pharmacy.ts b/pharmacy.ts index 6a527b65..f9102001 100644 --- a/pharmacy.ts +++ b/pharmacy.ts @@ -81,60 +81,17 @@ export class Drug implements DrugData { } } export class Pharmacy { - constructor(public drugs = []) { - this.drugs = drugs; + constructor(private _drugs: Drug[] = []) {} + + public get drugs(): Drug[] { + return [...this._drugs]; } - updateBenefitValue() { - for (var i = 0; i < this.drugs.length; i++) { - if ( - this.drugs[i].name != "Herbal Tea" && - this.drugs[i].name != "Fervex" - ) { - if (this.drugs[i].benefit > 0) { - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].benefit = this.drugs[i].benefit - 1; - } - } - } else { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - if (this.drugs[i].name == "Fervex") { - if (this.drugs[i].expiresIn < 11) { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } - if (this.drugs[i].expiresIn < 6) { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } - } - } - } - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].expiresIn = this.drugs[i].expiresIn - 1; - } - if (this.drugs[i].expiresIn < 0) { - if (this.drugs[i].name != "Herbal Tea") { - if (this.drugs[i].name != "Fervex") { - if (this.drugs[i].benefit > 0) { - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].benefit = this.drugs[i].benefit - 1; - } - } - } else { - this.drugs[i].benefit = - this.drugs[i].benefit - this.drugs[i].benefit; - } - } else { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } - } + + updateBenefitValue(): Drug[] { + for (const drug of this._drugs) { + drug.benefitRevaluate(); } - return this.drugs; + return [...this._drugs]; } }