// ═══ shop.js ═══ // ============================================================ // SHOP.JS — Armory / Command overlay state management // ============================================================ function openArmory() { if (G.gameOver) return; G.armoryOpen = true; G.commandOpen = false; G.threatOpen = false; G.prestigeOpen = false; _radialSlot = -1; _shopScrollY = 0; setPaused(true, false); } function closeArmory() { G.armoryOpen = false; _shopScrollY = 0; setPaused(false); } function openCommand() { if (G.gameOver) return; G.commandOpen = true; G.armoryOpen = false; G.threatOpen = false; G.prestigeOpen = false; _radialSlot = -1; _shopScrollY = 0; setPaused(true, false); } function closeCommand() { G.commandOpen = false; _shopScrollY = 0; setPaused(false); } function openWeaponDetail(slotIndex) { if (!G.weapons[slotIndex]) return; G.weaponDetailSlot = slotIndex; _radialSlot = -1; G.armoryOpen = false; G.commandOpen = false; G.threatOpen = false; G.prestigeOpen = false; _weaponDetailScrollY = 0; setPaused(true, false); } function closeWeaponDetail() { G.weaponDetailSlot = -1; _weaponDetailScrollY = 0; if (!G.armoryOpen && !G.commandOpen) setPaused(false); } function calcSellPrice(weapon) { const def = WEAPON_DEFS.find(d => d.id === weapon.defId); const baseSell = Math.floor((def?.cost ?? 0) * 0.5); const upgTree = WEAPON_UPGRADE_TREES[weapon.defId] || []; const upgSell = (G.weaponUpgradesBought[weapon.instanceId] || []).reduce((sum, id) => { const u = upgTree.find(u => u.id === id); return sum + Math.floor((u?.cost ?? 0) * 0.5); }, 0); return baseSell + upgSell; } function renderShop() { /* no-op — render loop redraws every frame */ } function sellWeapon(slotIndex) { const w = G.weapons[slotIndex]; if (!w) return; const activeCount = (G.weapons || []).slice(0, G.tower.weaponSlots).filter(x => x != null).length; if (activeCount <= 1) { addLog('Cannot sell last weapon!', 'lose'); return; } const price = calcSellPrice(w); removeWeaponFromSlot(slotIndex); const invIdx = (G.weaponInventory || []).findIndex(x => x.instanceId === w.instanceId); if (invIdx >= 0) G.weaponInventory.splice(invIdx, 1); G.credits += price; _radialSlot = -1; _sellHoldSlot = -1; closeWeaponDetail(); addLog('Sold ' + getWeaponDef(w).name + ' for ' + price + '¢.', 'win'); updateHUD(); }