buckshot_roulette_gameplay_engine/
loadout.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use rand::Rng;

use crate::{multiplayer_count::MultiplayerCount, LOG_RNG};

pub const MAX_SHELLS: u32 = 8;

#[derive(Debug, Clone, Copy)]
struct Sequence {
    num_live: usize,
    num_blank: usize,
}

pub struct Loadout {
    pub initial_blank_rounds: usize,
    pub initial_live_rounds: usize,
    pub new_items: usize,
}

impl Loadout {
    pub fn new<TRng>(multiplayer_count: MultiplayerCount, rng: &mut TRng) -> Self
    where
        TRng: Rng,
    {
        let sequence = get_sequence(multiplayer_count, rng);

        // https://github.com/thecatontheceiling/buckshotroulette_multiplayer/blob/aed4aecb7fd7f6cec14a7bd17239e736039915c0/global%20scripts/MP_RoundManager.gd#L528
        // #4 overridden in mp_main.tscn
        let new_items = match multiplayer_count {
            MultiplayerCount::Two => rng.gen_range(2, 5),
            MultiplayerCount::Three => rng.gen_range(3, 6),
            MultiplayerCount::Four => rng.gen_range(2, 5),
        };

        if LOG_RNG {
            println!("{} new items", new_items);
        }

        Loadout {
            initial_blank_rounds: sequence.num_blank,
            initial_live_rounds: sequence.num_live,
            new_items,
        }
    }
}

fn get_sequence<TRng>(multiplayer_count: MultiplayerCount, rng: &mut TRng) -> Sequence
where
    TRng: Rng,
{
    // found in mp_main.tscn
    let sequences = match multiplayer_count {
        MultiplayerCount::Two => vec![
            s(1, 1),
            s(1, 2),
            s(2, 1),
            s(2, 2),
            s(2, 3),
            s(3, 1),
            s(3, 2),
            s(3, 3),
            s(4, 2),
        ],
        MultiplayerCount::Three => vec![
            s(1, 1),
            s(2, 2),
            s(2, 3),
            s(3, 1),
            s(3, 2),
            s(3, 3),
            s(3, 4),
            s(4, 2),
            s(4, 3),
            s(4, 4),
        ],
        MultiplayerCount::Four => vec![
            s(2, 1),
            s(2, 2),
            s(3, 1),
            s(3, 2),
            s(3, 3),
            s(3, 4),
            s(3, 4),
            s(4, 2),
            s(4, 3),
            s(4, 4),
        ],
    };

    let sequence_index = rng.gen_range(0, sequences.len());
    if LOG_RNG {
        println!(
            "Selecting sequence index {}/{}",
            sequence_index,
            sequences.len()
        );
    }
    sequences[sequence_index]
}

fn s(num_live: usize, num_blank: usize) -> Sequence {
    Sequence {
        num_live,
        num_blank,
    }
}