103 lines
2.6 KiB
TypeScript
103 lines
2.6 KiB
TypeScript
import { Character, InventoryItem, TimedBuildBuff } from "../types";
|
||
|
||
export type InventoryUseEffect = {
|
||
hpRestore: number;
|
||
manaRestore: number;
|
||
cooldownReduction: number;
|
||
buildBuffs: TimedBuildBuff[];
|
||
};
|
||
|
||
function getRarityMultiplier(rarity: InventoryItem["rarity"]) {
|
||
switch (rarity) {
|
||
case "legendary":
|
||
return 2.4;
|
||
case "epic":
|
||
return 1.9;
|
||
case "rare":
|
||
return 1.55;
|
||
case "uncommon":
|
||
return 1.2;
|
||
default:
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
export function isInventoryItemUsable(item: InventoryItem) {
|
||
return (
|
||
Boolean(item.useProfile) ||
|
||
item.tags.includes("healing") ||
|
||
item.tags.includes("mana")
|
||
);
|
||
}
|
||
|
||
export function resolveInventoryItemUseEffect(
|
||
item: InventoryItem,
|
||
character: Character,
|
||
): InventoryUseEffect | null {
|
||
if (!isInventoryItemUsable(item)) return null;
|
||
|
||
if (item.useProfile) {
|
||
return {
|
||
hpRestore: item.useProfile.hpRestore ?? 0,
|
||
manaRestore: item.useProfile.manaRestore ?? 0,
|
||
cooldownReduction: item.useProfile.cooldownReduction ?? 0,
|
||
buildBuffs: item.useProfile.buildBuffs ?? [],
|
||
};
|
||
}
|
||
|
||
const rarityMultiplier = getRarityMultiplier(item.rarity);
|
||
const hasHealing =
|
||
item.tags.includes("healing") ||
|
||
/药|包|补给|恢复|疗伤|meat|apple|mushroom|water/i.test(item.name);
|
||
const hasMana =
|
||
item.tags.includes("mana") ||
|
||
/灵液|法力|mana|crystal|essence|spirit/i.test(item.name);
|
||
|
||
const hpRestore = hasHealing
|
||
? Math.max(
|
||
10,
|
||
Math.round((14 + character.attributes.spirit * 1.4) * rarityMultiplier),
|
||
)
|
||
: 0;
|
||
const manaRestore = hasMana
|
||
? Math.max(
|
||
8,
|
||
Math.round(
|
||
(12 + character.attributes.intelligence * 1.4) * rarityMultiplier,
|
||
),
|
||
)
|
||
: 0;
|
||
const cooldownReduction = /凝神|回气|醒神|booster|essence/i.test(item.name)
|
||
? 1
|
||
: 0;
|
||
|
||
if (hpRestore <= 0 && manaRestore <= 0 && cooldownReduction <= 0) {
|
||
return null;
|
||
}
|
||
|
||
return {
|
||
hpRestore,
|
||
manaRestore,
|
||
cooldownReduction,
|
||
buildBuffs: [],
|
||
};
|
||
}
|
||
|
||
export function buildInventoryUseResultText(
|
||
item: InventoryItem,
|
||
effect: InventoryUseEffect,
|
||
) {
|
||
const parts = [
|
||
effect.hpRestore > 0 ? `恢复 ${effect.hpRestore} 点气血` : null,
|
||
effect.manaRestore > 0 ? `恢复 ${effect.manaRestore} 点灵力` : null,
|
||
effect.cooldownReduction > 0
|
||
? `额外推进 ${effect.cooldownReduction} 回合冷却`
|
||
: null,
|
||
effect.buildBuffs.length > 0
|
||
? `获得 ${effect.buildBuffs.map(buff => buff.name).join("、")}`
|
||
: null,
|
||
].filter(Boolean);
|
||
|
||
return `你取出${item.name}立刻使用,${parts.join(",")}。`;
|
||
}
|