60
src/data/economy.ts
Normal file
60
src/data/economy.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { InventoryItem, WorldType } from '../types';
|
||||
|
||||
const RARITY_BASE_VALUES: Record<InventoryItem['rarity'], number> = {
|
||||
common: 12,
|
||||
uncommon: 24,
|
||||
rare: 48,
|
||||
epic: 92,
|
||||
legendary: 168,
|
||||
};
|
||||
|
||||
export function getCurrencyName(worldType: WorldType | null) {
|
||||
if (worldType === WorldType.XIANXIA) return '灵石';
|
||||
if (worldType === WorldType.WUXIA) return '铜钱';
|
||||
return '钱币';
|
||||
}
|
||||
|
||||
export function getInitialPlayerCurrency(worldType: WorldType | null) {
|
||||
return worldType === WorldType.XIANXIA ? 140 : 160;
|
||||
}
|
||||
|
||||
export function getDiscountTierForAffinity(affinity: number) {
|
||||
if (affinity >= 90) return 3;
|
||||
if (affinity >= 60) return 2;
|
||||
if (affinity >= 30) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function getInventoryItemValue(item: InventoryItem) {
|
||||
if (typeof item.value === 'number' && Number.isFinite(item.value)) {
|
||||
return Math.max(8, Math.round(item.value));
|
||||
}
|
||||
|
||||
let value = RARITY_BASE_VALUES[item.rarity];
|
||||
|
||||
if (item.tags.includes('weapon')) value += 14;
|
||||
if (item.tags.includes('armor')) value += 12;
|
||||
if (item.tags.includes('relic')) value += 16;
|
||||
if (item.tags.includes('mana')) value += 8;
|
||||
if (item.tags.includes('healing')) value += 8;
|
||||
if (item.tags.includes('material')) value += 4;
|
||||
if (item.category.includes('专属')) value += 10;
|
||||
|
||||
return Math.max(8, value);
|
||||
}
|
||||
|
||||
export function getNpcPurchasePrice(item: InventoryItem, affinity: number) {
|
||||
const discountTier = getDiscountTierForAffinity(affinity);
|
||||
const discountMultiplier = 1 - (discountTier * 0.08);
|
||||
return Math.max(6, Math.round(getInventoryItemValue(item) * discountMultiplier));
|
||||
}
|
||||
|
||||
export function getNpcBuybackPrice(item: InventoryItem, affinity: number) {
|
||||
const discountTier = getDiscountTierForAffinity(affinity);
|
||||
const buybackMultiplier = 0.4 + (discountTier * 0.06);
|
||||
return Math.max(4, Math.round(getInventoryItemValue(item) * buybackMultiplier));
|
||||
}
|
||||
|
||||
export function formatCurrency(value: number, worldType: WorldType | null) {
|
||||
return `${value} ${getCurrencyName(worldType)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user