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
106
107
108
109
110
111
112
113
114
115
116
117
118
#[cfg(not(any(
feature = "bloodborne", feature = "demons",
feature = "ds1", feature = "ds2", feature = "ds3",
feature = "sekiro",
)))]
compile_error!("Cannot compile without any Message Sets enabled.");
#[cfg(feature = "ds2")]
#[macro_use]
extern crate lazy_static;
extern crate rand;
#[cfg(feature = "bloodborne")]
mod bb;
#[cfg(feature = "demons")]
mod des;
#[cfg(feature = "ds1")]
mod ds1;
#[cfg(feature = "ds2")]
mod ds2;
#[cfg(feature = "ds3")]
mod ds3;
#[cfg(feature = "sekiro")]
mod sek;
#[cfg(feature = "bloodborne")]
pub use bb::MessageBB;
#[cfg(feature = "demons")]
pub use des::MessageDeS;
#[cfg(feature = "ds1")]
pub use ds1::MessageDkS1;
#[cfg(feature = "ds2")]
pub use ds2::MessageDkS2;
#[cfg(feature = "ds3")]
pub use ds3::MessageDkS3;
#[cfg(feature = "sekiro")]
pub use sek::MessageSek;
use rand::prelude::{Rng, SliceRandom, thread_rng, ThreadRng};
use std::fmt::Display;
const COMPOUND_CHANCE: f64 = 0.5;
pub type Generator = fn(&mut ThreadRng) -> Box<dyn DsMsg>;
pub trait DsMsg: Display {
fn random(rng: &mut ThreadRng) -> Self
where Self: Sized;
}
pub trait DsMulti: Display {
fn double(rng: &mut ThreadRng) -> Self
where Self: Sized;
fn single(rng: &mut ThreadRng) -> Self
where Self: Sized;
}
impl<M> DsMsg for M
where M: DsMulti,
{
fn random(rng: &mut ThreadRng) -> Self {
if rng.gen_bool(COMPOUND_CHANCE) {
Self::double(rng)
} else {
Self::single(rng)
}
}
}
pub const GENERATORS: &[Generator] = &[
#[cfg(feature = "bloodborne")]
|r| Box::new(MessageBB::random(r)),
#[cfg(feature = "demons")]
|r| Box::new(MessageDeS::random(r)),
#[cfg(feature = "ds1")]
|r| Box::new(MessageDkS1::random(r)),
#[cfg(feature = "ds2")]
|r| Box::new(MessageDkS2::random(r)),
#[cfg(feature = "ds3")]
|r| Box::new(MessageDkS3::random(r)),
#[cfg(feature = "sekiro")]
|r| Box::new(MessageSek::random(r)),
];
pub fn random_message() -> Box<dyn DsMsg> {
let mut rng: ThreadRng = thread_rng();
GENERATORS.choose(&mut rng)
.expect("DsMsg was not compiled with any Generators!")
(&mut rng)
}