|
|
@ -20,65 +20,67 @@ struct TechniqueRateStat { |
|
|
|
max: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
struct TechniqueRate {
|
|
|
|
#[serde(rename = "Foie")]
|
|
|
|
foie: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Gifoie")]
|
|
|
|
gifoie: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Rafoie")]
|
|
|
|
rafoie: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Zonde")]
|
|
|
|
zonde: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Gizonde")]
|
|
|
|
gizonde: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Razonde")]
|
|
|
|
razonde: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Barta")]
|
|
|
|
barta: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Gibarta")]
|
|
|
|
gibarta: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Rabarta")]
|
|
|
|
rabarta: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Grants")]
|
|
|
|
grants: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Deband")]
|
|
|
|
deband: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Jellen")]
|
|
|
|
jellen: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Zalure")]
|
|
|
|
zalure: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Shifta")]
|
|
|
|
shifta: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Ryuker")]
|
|
|
|
ryuker: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Resta")]
|
|
|
|
resta: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Anti")]
|
|
|
|
anti: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Reverser")]
|
|
|
|
reverser: TechniqueRateStat,
|
|
|
|
#[serde(rename = "Megid")]
|
|
|
|
megid: TechniqueRateStat,
|
|
|
|
struct TechniqueRatesRaw {
|
|
|
|
area1: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area2: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area3: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area4: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area5: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area6: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area7: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area8: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area9: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
area10: BTreeMap<String, TechniqueRateStat>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
struct TechniqueRates {
|
|
|
|
area1: TechniqueRate,
|
|
|
|
area2: TechniqueRate,
|
|
|
|
area3: TechniqueRate,
|
|
|
|
area4: TechniqueRate,
|
|
|
|
area5: TechniqueRate,
|
|
|
|
area6: TechniqueRate,
|
|
|
|
area7: TechniqueRate,
|
|
|
|
area8: TechniqueRate,
|
|
|
|
area9: TechniqueRate,
|
|
|
|
area10: TechniqueRate,
|
|
|
|
area1: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area2: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area3: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area4: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area5: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area6: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area7: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area8: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area9: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
area10: BTreeMap<Technique, TechniqueRateStat>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TechniqueRates {
|
|
|
|
fn new(rates: TechniqueRatesRaw) -> TechniqueRates {
|
|
|
|
TechniqueRates {
|
|
|
|
area1: rates.area1.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area2: rates.area2.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area3: rates.area3.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area4: rates.area4.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area5: rates.area5.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area6: rates.area6.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area7: rates.area7.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area8: rates.area8.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area9: rates.area9.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
area10: rates.area10.into_iter().map(|(tech, rate)| (tech.parse().unwrap(), rate)).collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TechniqueRates {
|
|
|
|
fn get_by_area<'a>(&'a self, map_area: &MapVariantType) -> &'a BTreeMap<Technique, TechniqueRateStat> {
|
|
|
|
match map_area.area_value().unwrap() {
|
|
|
|
0 => &self.area1,
|
|
|
|
1 => &self.area2,
|
|
|
|
2 => &self.area3,
|
|
|
|
3 => &self.area4,
|
|
|
|
4 => &self.area5,
|
|
|
|
5 => &self.area6,
|
|
|
|
6 => &self.area7,
|
|
|
|
7 => &self.area8,
|
|
|
|
8 => &self.area9,
|
|
|
|
_ => &self.area10,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TechniqueTable {
|
|
|
|
rates: TechniqueRates
|
|
|
@ -86,12 +88,48 @@ pub struct TechniqueTable { |
|
|
|
|
|
|
|
impl TechniqueTable {
|
|
|
|
pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> TechniqueTable {
|
|
|
|
let rates: TechniqueRatesRaw = load_data_file(episode, difficulty, section_id, "tech_rate.toml");
|
|
|
|
|
|
|
|
TechniqueTable {
|
|
|
|
rates: load_data_file(episode, difficulty, section_id, "tech_rate.toml")
|
|
|
|
rates: TechniqueRates::new(rates),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_drop<R: Rng>(&self, map_area: &MapVariantType, rng: &mut R) -> Option<ItemDetail> {
|
|
|
|
None
|
|
|
|
let mut tech_rates = self.rates.get_by_area(map_area).iter();
|
|
|
|
let tech_weights = WeightedIndex::new(tech_rates.clone().map(|(_, stat)| stat.rate)).unwrap();
|
|
|
|
|
|
|
|
let (tech, stat) = tech_rates.nth(tech_weights.sample(rng)).unwrap();
|
|
|
|
let level = rng.gen_range(stat.min, stat.max+1);
|
|
|
|
|
|
|
|
Some(ItemDetail::TechniqueDisk(TechniqueDisk {
|
|
|
|
tech: *tech,
|
|
|
|
level: level as u32
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
|
|
fn test_tech_drops() {
|
|
|
|
let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]);
|
|
|
|
let tt = TechniqueTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly);
|
|
|
|
|
|
|
|
let tech_tests = vec![(MapVariantType::Forest1, Technique::Resta, 13),
|
|
|
|
(MapVariantType::Caves3, Technique::Foie, 24),
|
|
|
|
(MapVariantType::Mines2, Technique::Gibarta, 20),
|
|
|
|
(MapVariantType::DarkFalz, Technique::Razonde, 22)];
|
|
|
|
|
|
|
|
for (area, tech, level) in tech_tests {
|
|
|
|
assert!(tt.get_drop(&area, &mut rng) == Some(ItemDetail::TechniqueDisk(
|
|
|
|
TechniqueDisk {
|
|
|
|
tech: tech,
|
|
|
|
level: level
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|