66 lines
3.1 KiB
JavaScript
66 lines
3.1 KiB
JavaScript
export const TOOLS = {
|
|
wood_pickaxe: { n:'Деревянная кирка', icon:'⛏️', damage:1, durability:60, toolType:'pickaxe', toolTier:'wood', speed:2 },
|
|
stone_pickaxe: { n:'Каменная кирка', icon:'⛏️', damage:2, durability:132, toolType:'pickaxe', toolTier:'stone', speed:4 },
|
|
iron_pickaxe: { n:'Железная кирка', icon:'⛏️', damage:3, durability:250, toolType:'pickaxe', toolTier:'iron', speed:6 },
|
|
wood_sword: { n:'Деревянный меч', icon:'🗡️', damage:4, durability:60 },
|
|
stone_sword: { n:'Каменный меч', icon:'🗡️', damage:5, durability:132 },
|
|
iron_sword: { n:'Железный меч', icon:'🗡️', damage:7, durability:250 },
|
|
wood_axe: { n:'Деревянный топор', icon:'🪓', damage:3, durability:60, toolType:'axe', toolTier:'wood', speed:2 },
|
|
stone_axe: { n:'Каменный топор', icon:'🪓', damage:4, durability:132, toolType:'axe', toolTier:'stone', speed:4 },
|
|
iron_axe: { n:'Железный топор', icon:'🪓', damage:5, durability:250, toolType:'axe', toolTier:'iron', speed:6 },
|
|
wood_shovel: { n:'Деревянная лопата', icon:'🔱', damage:1, durability:60, toolType:'shovel', toolTier:'wood', speed:2 },
|
|
stone_shovel: { n:'Каменная лопата', icon:'🔱', damage:2, durability:132, toolType:'shovel', toolTier:'stone', speed:4 },
|
|
iron_shovel: { n:'Железная лопата', icon:'🔱', damage:3, durability:250, toolType:'shovel', toolTier:'iron', speed:6 },
|
|
bow: { n:'Лук', icon:'🏹', damage:10, durability:200 },
|
|
};
|
|
|
|
import { state } from '../core/state.js';
|
|
import { BLOCKS } from './blocks.js';
|
|
|
|
export function addTool(type) {
|
|
const maxDur = TOOLS[type]?.durability || 60;
|
|
const key = `${type}_${Date.now()}_${Math.random().toString(36).slice(2,6)}`;
|
|
state.toolDurability.set(key, { type, current: maxDur, max: maxDur });
|
|
}
|
|
|
|
export function useTool(type) {
|
|
for (const [tid, dur] of state.toolDurability) {
|
|
if (dur.type === type && dur.current > 0) {
|
|
dur.current--;
|
|
if (dur.current <= 0) {
|
|
state.toolDurability.delete(tid);
|
|
state.inv[type] = Math.max(0, (state.inv[type] || 0) - 1);
|
|
return true; // broke
|
|
}
|
|
return false; // used but not broke
|
|
}
|
|
}
|
|
return false; // no durability entry found
|
|
}
|
|
|
|
export function getBestTool(blockType) {
|
|
const block = BLOCKS[blockType];
|
|
if (!block || !block.toolType) return null;
|
|
const toolType = block.toolType;
|
|
for (const tier of ['iron', 'stone', 'wood']) {
|
|
const toolId = `${tier}_${toolType}`;
|
|
if (TOOLS[toolId] && state.inv[toolId] > 0) return toolId;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function toolTierLessThan(toolTier, minTier) {
|
|
const tiers = { wood: 1, stone: 2, iron: 3 };
|
|
return (tiers[toolTier] || 0) < (tiers[minTier] || 0);
|
|
}
|
|
|
|
export function getMiningSpeed(blockType) {
|
|
const block = BLOCKS[blockType];
|
|
if (!block) return 1;
|
|
const toolId = getBestTool(blockType);
|
|
if (toolId) {
|
|
const tool = TOOLS[toolId];
|
|
if (tool.toolType === block.toolType) return tool.speed;
|
|
}
|
|
return 1; // Bare hands = 1 click per hit
|
|
} |