Skip to main content

cuqueclicker_lib/game/
golden.rs

1use rand::RngExt;
2use ratatui::layout::Rect;
3
4/// A Golden Cuque variant. The on-screen marker color + label differ per
5/// variant, but all are caught through the same path (mouse click on the
6/// marker, or the `g` hotkey). See `GameState::catch_golden` for effects.
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum GoldenVariant {
9    /// Instant flat reward: `max(10, fps * 60s)` cuques. No buff, no duration.
10    Lucky,
11    /// 13-second `ClickFrenzy` buff: manual clicks produce x777 cuques.
12    Frenzy,
13    /// 60-second per-fingerer modifier on a random owned fingerer: that
14    /// fingerer's passive FPS is multiplied x7. Implemented as a
15    /// `ModifierSource::PurpleCoin` `MulFactor(7.0)` with `Ticks(1200)`.
16    Buff,
17}
18
19impl GoldenVariant {
20    pub fn random() -> Self {
21        let r: f64 = rand::rng().random();
22        if r < 0.6 {
23            Self::Lucky
24        } else if r < 0.8 {
25            Self::Frenzy
26        } else {
27            Self::Buff
28        }
29    }
30}
31
32/// Position is stored as a fraction of the biscuit rect ([0.0, 1.0] on each
33/// axis) so the marker stays anchored to its spot on the biscuit when the
34/// terminal resizes or the user zooms (`+`/`-`). The renderer resolves these
35/// fractions against the *current* biscuit rect every frame.
36#[derive(Clone)]
37pub struct GoldenCuque {
38    pub frac_x: f32,
39    pub frac_y: f32,
40    pub life_ticks: u32,
41    pub variant: GoldenVariant,
42}
43
44pub const GOLDEN_LIFE_TICKS: u32 = 220; // ~11s at 20Hz
45pub const GOLDEN_COOLDOWN_MIN: u32 = 400; // 20s
46pub const GOLDEN_COOLDOWN_MAX: u32 = 1600; // 80s
47// Inset (in fractional units) the spawn lottery away from the biscuit edges
48// so the 5x3 marker has room to render without bumping into the border.
49const SPAWN_INSET_X: f32 = 0.08;
50const SPAWN_INSET_Y: f32 = 0.10;
51
52pub fn next_cooldown() -> u32 {
53    rand::rng().random_range(GOLDEN_COOLDOWN_MIN..=GOLDEN_COOLDOWN_MAX)
54}
55
56/// Pick a random fractional position inside the biscuit, away from the edges.
57/// `_biscuit` is taken so the signature documents intent (the spawn area is
58/// "inside this rect"); the actual fractions are rect-independent.
59pub fn spawn_in(_biscuit: Rect) -> GoldenCuque {
60    let mut r = rand::rng();
61    let frac_x = r.random_range(SPAWN_INSET_X..=(1.0 - SPAWN_INSET_X));
62    let frac_y = r.random_range(SPAWN_INSET_Y..=(1.0 - SPAWN_INSET_Y));
63    GoldenCuque {
64        frac_x,
65        frac_y,
66        life_ticks: GOLDEN_LIFE_TICKS,
67        variant: GoldenVariant::random(),
68    }
69}