İçeriğe geç
Tüm kodlar

Hipodrom

Yorumla oynanan TikTok LIVE at yarışı

55 satır · 1,8 KBHamİndir
// Sahte izleyici üretici: canlı yayın açmadan oyunu test etmek için.
const NAMES = [
  'aysu', 'mert', 'zeynep', 'emre', 'elif', 'burak', 'selin', 'can', 'deniz', 'ece',
  'kaan', 'irem', 'onur', 'melis', 'baris', 'naz', 'umut', 'derya', 'tolga', 'gizem',
  'sinan', 'pelin', 'yigit', 'busra', 'efe', 'damla', 'arda', 'ceren', 'kerem', 'ipek',
];
const SUFFIX = ['', '_', '.', '34', '06', '35', 'x', '_tr', '99', '07'];
const CHAT = [
  'koş', 'hadi', 'koş koş koş', 'hayda', 'bas', 'gaz', 'hadi oğlum', 'yetiş', 'son düzlük',
  'selam', 'ben de varım', 'kim kazanır', 'atım uçuyor', 'yaaa', 'az kaldı',
];

const pick = (a) => a[Math.floor(Math.random() * a.length)];

export function randomUser() {
  const id = pick(NAMES) + pick(SUFFIX) + (Math.random() < 0.5 ? Math.floor(Math.random() * 100) : '');
  return { id, name: id };
}

export function createSimulator(onEvent) {
  let timer = null;
  let rate = 4; // saniyedeki olay sayısı
  const pool = [];
  const fans = new Map(); // bazı kişiler daha çok yazar

  function poolUser() {
    if (pool.length < 40 && (pool.length < 8 || Math.random() < 0.15)) {
      const u = randomUser();
      pool.push(u);
      fans.set(u.id, 0.3 + Math.random() * 2);
      return u;
    }
    // ağırlıklı seçim
    const total = pool.reduce((s, u) => s + fans.get(u.id), 0);
    let r = Math.random() * total;
    for (const u of pool) if ((r -= fans.get(u.id)) <= 0) return u;
    return pick(pool);
  }

  function tick() {
    onEvent({ type: 'chat', user: poolUser(), text: pick(CHAT) });
  }

  function start(newRate) {
    if (newRate) rate = Math.max(0.2, Math.min(30, Number(newRate)));
    stop();
    timer = setInterval(tick, 1000 / rate);
  }
  function stop() {
    clearInterval(timer);
    timer = null;
  }

  return { start, stop, isRunning: () => !!timer, getRate: () => rate };
}

Lisans bilgisi projenin LICENSE dosyasında.