rare monster appear config files. init rare monster appear table stuff
This commit is contained in:
parent
7c7cf95942
commit
f5946013a1
@ -3,13 +3,13 @@
|
|||||||
# 1/512 = 0.001953125
|
# 1/512 = 0.001953125
|
||||||
|
|
||||||
[[Hildebear]]
|
[[Hildebear]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[RagRappy]]
|
[[RagRappy]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[PoisonLily]]
|
[[PoisonLily]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[PofuillySlime]]
|
[[PofuillySlime]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
@ -3,11 +3,11 @@
|
|||||||
# 1/512 = 0.001953125
|
# 1/512 = 0.001953125
|
||||||
|
|
||||||
[[Hildebear]]
|
[[Hildebear]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[RagRappy]]
|
[[RagRappy]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[PoisonLily]]
|
[[PoisonLily]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
|
@ -3,25 +3,25 @@
|
|||||||
# 1/512 = 0.001953125
|
# 1/512 = 0.001953125
|
||||||
|
|
||||||
[[SandRappyCrater]]
|
[[SandRappyCrater]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[ZuCrater]]
|
[[ZuCrater]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[Dorphon]]
|
[[Dorphon]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[SandRappyDesert]]
|
[[SandRappyDesert]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[ZuDesert]]
|
[[ZuDesert]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[MerissaA]]
|
[[MerissaA]]
|
||||||
rate = 0.01
|
appear_rate = 0.01
|
||||||
|
|
||||||
[[Shambertin]]
|
[[Shambertin]]
|
||||||
rate = 0.1
|
appear_rate = 0.1
|
||||||
|
|
||||||
[[SaintMillion]]
|
[[SaintMillion]]
|
||||||
rate = 0.1
|
appear_rate = 0.1
|
@ -55,6 +55,17 @@ pub fn load_data_file<T: serde::de::DeserializeOwned>(episode: Episode, difficul
|
|||||||
toml::from_str::<T>(s.as_str()).unwrap()
|
toml::from_str::<T>(s.as_str()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is just copypaste
|
||||||
|
pub fn load_rare_monster_file<T: serde::de::DeserializeOwned>(episode: Episode) -> T {
|
||||||
|
let mut path = PathBuf::from("data/battle_param/");
|
||||||
|
path.push(episode.to_string().to_lowercase());
|
||||||
|
path.push("_rare_monster.toml");
|
||||||
|
|
||||||
|
let mut f = File::open(path).unwrap();
|
||||||
|
let mut s = String::new();
|
||||||
|
f.read_to_string(&mut s);
|
||||||
|
toml::from_str::<T>(s.as_str()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||||
pub enum MonsterDropType {
|
pub enum MonsterDropType {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// TOOD: `pub(super) for most of these?`
|
// TOOD: `pub(super) for most of these?`
|
||||||
use std::io::{Read};
|
use std::io::{Read};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@ -9,6 +10,10 @@ use crate::ship::room::Episode;
|
|||||||
|
|
||||||
use crate::ship::map::*;
|
use crate::ship::map::*;
|
||||||
|
|
||||||
|
use rand::{Rng, SeedableRng};
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use crate::ship::drops::{load_rare_monster_file};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct RawMapEnemy {
|
pub struct RawMapEnemy {
|
||||||
id: u32,
|
id: u32,
|
||||||
@ -70,6 +75,46 @@ pub enum MapEnemyError {
|
|||||||
MapAreaError(#[from] MapAreaError),
|
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)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct MapEnemy {
|
pub struct MapEnemy {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user