refactor: use subclasses for different item types
This commit is contained in:
parent
be616e3be8
commit
8d2cff77d7
47 changed files with 766 additions and 456 deletions
32
src/item/spell/calculate-spell-price.ts
Normal file
32
src/item/spell/calculate-spell-price.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { CooldownDuration, DS4SpellDataSourceData } from "./spell-data-source";
|
||||
|
||||
export function calculateSpellPrice(data: DS4SpellDataSourceData): number | null {
|
||||
const spellPriceFactor = calculateSpellPriceFactor(data.cooldownDuration);
|
||||
const baseSpellPrices = [
|
||||
data.minimumLevels.healer !== null ? 10 + (data.minimumLevels.healer - 1) * 35 : null,
|
||||
data.minimumLevels.wizard !== null ? 10 + (data.minimumLevels.wizard - 1) * 50 : null,
|
||||
data.minimumLevels.sorcerer !== null ? 10 + (data.minimumLevels.sorcerer - 1) * 65 : null,
|
||||
].filter((baseSpellPrice: number | null): baseSpellPrice is number => baseSpellPrice !== null);
|
||||
const baseSpellPrice = Math.min(...baseSpellPrices);
|
||||
return baseSpellPrice === Infinity ? null : baseSpellPrice * spellPriceFactor;
|
||||
}
|
||||
|
||||
function calculateSpellPriceFactor(cooldownDuration: CooldownDuration): number {
|
||||
switch (cooldownDuration) {
|
||||
case "0r":
|
||||
case "1r":
|
||||
case "2r":
|
||||
case "5r":
|
||||
case "10r":
|
||||
case "100r":
|
||||
return 1;
|
||||
case "1d":
|
||||
return 2;
|
||||
case "d20d":
|
||||
return 3;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue