|
|
@ -1,5 +1,6 @@ |
|
|
|
// TOOD: `pub(super) for most of these?`
|
|
|
|
use std::io::{Read};
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use byteorder::{LittleEndian, ReadBytesExt};
|
|
|
|
use thiserror::Error;
|
|
|
@ -9,6 +10,10 @@ use crate::ship::room::Episode; |
|
|
|
|
|
|
|
use crate::ship::map::*;
|
|
|
|
|
|
|
|
use rand::{Rng, SeedableRng};
|
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use crate::ship::drops::{load_rare_monster_file};
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct RawMapEnemy {
|
|
|
|
id: u32,
|
|
|
@ -70,6 +75,46 @@ pub enum MapEnemyError { |
|
|
|
MapAreaError(#[from] MapAreaError),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct RareMonsterAppearRate(pub f32);
|
|
|
|
|
|
|
|
// making this `pub type` doesn't allow `impl`s to be defined?
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct RareMonsterAppearTable {
|
|
|
|
appear_rate: HashMap<MonsterType, RareMonsterAppearRate>,
|
|
|
|
seed: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RareMonsterAppearTable {
|
|
|
|
pub fn new(episode: Episode, room_seed: u32) -> RareMonsterAppearTable {
|
|
|
|
let cfg: HashMap<String, f32> = load_rare_monster_file(episode);
|
|
|
|
|
|
|
|
let appear_rates: HashMap<MonsterType, RareMonsterAppearRate> = cfg
|
|
|
|
.into_iter()
|
|
|
|
.map(|(monster, appear_rate)| {
|
|
|
|
let monster: MonsterType = monster.parse().unwrap();
|
|
|
|
let appear_rate = RareMonsterAppearRate(appear_rate);
|
|
|
|
(monster, appear_rate)
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
RareMonsterAppearTable {
|
|
|
|
appear_rate: appear_rates,
|
|
|
|
seed: room_seed,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn roll_appearance(&self, monster: &MonsterType) -> bool {
|
|
|
|
let mut rng = rand_chacha::ChaChaRng::seed_from_u64(self.seed as u64);
|
|
|
|
if rng.gen::<f32>() < self.appear_rate.get(monster).unwrap_or(&RareMonsterAppearRate(0.0f32)).0 {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct MapEnemy {
|
|
|
|