const generateId = () => Math.random().toString(36).substr(2, 9);

const generateEnemy = (floor) => {
  const hp = Math.floor(50 * Math.pow(1.2, floor - 1));
  const atk = Math.floor(5 * Math.pow(1.15, floor - 1));
  return { name: `セキュリティボット Mk-${floor}`, maxHp: hp, hp, atk, maxGauge: 200, gauge: 0 };
};

const generateDrop = (floor) => {
  const rand = Math.random();
  if (rand < 0.15) {
    // 武器ドロップ
    const availableWeapons = WEAPON_TYPES.filter(w => w.minFloor <= floor);
    const type = availableWeapons[Math.floor(Math.random() * availableWeapons.length)];
    const prefixKeys = Object.keys(PREFIXES);
    
    let prefix = 'rusty';
    if (Math.random() < 0.1 + (floor * 0.01)) prefix = 'legendary';
    else if (Math.random() < 0.2) prefix = 'cursed';
    else if (Math.random() < 0.3) prefix = 'sonic';
    else if (Math.random() < 0.4) prefix = 'heavy';
    else if (Math.random() < 0.6) prefix = 'sharp';
    else if (Math.random() < 0.8) prefix = 'none';

    const sockets = Array(Math.floor(Math.random() * type.maxSockets) + 1).fill(null);

    return {
      type: 'weapon',
      item: { id: `w_${generateId()}`, typeId: type.id, name: type.name, prefix, baseAtk: type.baseAtk, sockets, rarity: type.rarity }
    };
  } else {
    // パーツドロップ
    const availableParts = Object.values(PARTS).filter(p => p.minFloor <= floor);
    const part = availableParts[Math.floor(Math.random() * availableParts.length)].id;
    return { type: 'part', item: part };
  }
};
