jake
5 years ago
3 changed files with 184 additions and 5 deletions
@ -0,0 +1,39 @@ |
|||||
|
use std::collections::{HashMap, BTreeMap};
|
||||
|
use std::io::Read;
|
||||
|
use serde::{Serialize, Deserialize};
|
||||
|
use rand::{Rng, SeedableRng};
|
||||
|
use rand::distributions::{WeightedIndex, Distribution};
|
||||
|
|
||||
|
use crate::entity::item::{ItemDetail, Tool as ToolDetail};
|
||||
|
use crate::entity::item::tool::{StackedTool, ToolType};
|
||||
|
use crate::ship::room::{Difficulty, Episode};
|
||||
|
use crate::ship::map::MapVariantType;
|
||||
|
use crate::entity::character::SectionID;
|
||||
|
use crate::ship::drops::load_data_file;
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
pub struct TechniqueTable {
|
||||
|
|
||||
|
}
|
||||
|
|
||||
|
impl TechniqueTable {
|
||||
|
pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> TechniqueTable {
|
||||
|
TechniqueTable {
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn get_drop<R: Rng>(&self, map_area: &MapVariantType, rng: &mut R) -> Option<ItemDetail> {
|
||||
|
None
|
||||
|
}
|
||||
|
}
|
@ -0,0 +1,139 @@ |
|||||
|
use std::collections::{HashMap, BTreeMap};
|
||||
|
use std::io::Read;
|
||||
|
use serde::{Serialize, Deserialize};
|
||||
|
use rand::{Rng, SeedableRng};
|
||||
|
use rand::distributions::{WeightedIndex, Distribution};
|
||||
|
|
||||
|
use crate::entity::item::{ItemDetail, Tool as ToolDetail};
|
||||
|
use crate::entity::item::tool::{StackedTool, ToolType};
|
||||
|
use crate::ship::room::{Difficulty, Episode};
|
||||
|
use crate::ship::map::MapVariantType;
|
||||
|
use crate::entity::character::SectionID;
|
||||
|
use crate::ship::drops::load_data_file;
|
||||
|
use crate::ship::drops::tech_table::TechniqueTable;
|
||||
|
|
||||
|
|
||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
|
||||
|
enum ToolRateType {
|
||||
|
Monomate,
|
||||
|
Dimate,
|
||||
|
Trimate,
|
||||
|
Monofluid,
|
||||
|
Difluid,
|
||||
|
Trifluid,
|
||||
|
Antidote,
|
||||
|
Antiparalysis,
|
||||
|
SolAtomizer,
|
||||
|
MoonAtomizer,
|
||||
|
StarAtomizer,
|
||||
|
Telepipe,
|
||||
|
TrapVision,
|
||||
|
Monogrinder,
|
||||
|
Digrinder,
|
||||
|
Trigrinder,
|
||||
|
PowerMaterial,
|
||||
|
MindMaterial,
|
||||
|
EvadeMaterial,
|
||||
|
HpMaterial,
|
||||
|
TpMaterial,
|
||||
|
DefMaterial,
|
||||
|
LuckMaterial,
|
||||
|
ScapeDoll,
|
||||
|
Technique,
|
||||
|
PhotonDrop,
|
||||
|
}
|
||||
|
|
||||
|
/*#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
|
struct ToolRate {
|
||||
|
tool: ToolRateType,
|
||||
|
rate: u32,
|
||||
|
}*/
|
||||
|
|
||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
struct ToolRates {
|
||||
|
area1: BTreeMap<ToolRateType, u32>,
|
||||
|
area2: BTreeMap<ToolRateType, u32>,
|
||||
|
area3: BTreeMap<ToolRateType, u32>,
|
||||
|
area4: BTreeMap<ToolRateType, u32>,
|
||||
|
area5: BTreeMap<ToolRateType, u32>,
|
||||
|
area6: BTreeMap<ToolRateType, u32>,
|
||||
|
area7: BTreeMap<ToolRateType, u32>,
|
||||
|
area8: BTreeMap<ToolRateType, u32>,
|
||||
|
area9: BTreeMap<ToolRateType, u32>,
|
||||
|
area10: BTreeMap<ToolRateType, u32>,
|
||||
|
}
|
||||
|
|
||||
|
impl ToolRates {
|
||||
|
fn get_by_area<'a>(&'a self, map_area: &MapVariantType) -> &'a BTreeMap<ToolRateType, u32> {
|
||||
|
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 ToolTable {
|
||||
|
rates: ToolRates,
|
||||
|
tech_table: TechniqueTable,
|
||||
|
}
|
||||
|
|
||||
|
impl ToolTable {
|
||||
|
pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> ToolTable {
|
||||
|
ToolTable {
|
||||
|
rates: load_data_file(episode, difficulty, section_id, "tool_rate.toml"),
|
||||
|
tech_table: TechniqueTable::new(episode, difficulty, section_id),
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn tool_type<R: Rng>(&self, map_area: &MapVariantType, rng: &mut R) -> ToolType {
|
||||
|
let tool_rates = self.rates.get_by_area(map_area).iter();
|
||||
|
let tool_weights = WeightedIndex::new(tool_rates.clone().map(|(_, weights)| weights)).unwrap();
|
||||
|
|
||||
|
match tool_rates.map(|(ttype, _)| ttype).nth(tool_weights.sample(rng)).unwrap() {
|
||||
|
ToolRateType::Monomate => ToolType::Monomate,
|
||||
|
ToolRateType::Dimate => ToolType::Dimate,
|
||||
|
ToolRateType::Trimate => ToolType::Trimate,
|
||||
|
ToolRateType::Monofluid => ToolType::Monofluid,
|
||||
|
ToolRateType::Difluid => ToolType::Difluid,
|
||||
|
ToolRateType::Trifluid => ToolType::Trifluid,
|
||||
|
ToolRateType::Antidote => ToolType::Antidote,
|
||||
|
ToolRateType::Antiparalysis => ToolType::Antiparalysis,
|
||||
|
ToolRateType::SolAtomizer => ToolType::SolAtomizer,
|
||||
|
ToolRateType::MoonAtomizer => ToolType::MoonAtomizer,
|
||||
|
ToolRateType::StarAtomizer => ToolType::StarAtomizer,
|
||||
|
ToolRateType::Telepipe => ToolType::Telepipe,
|
||||
|
ToolRateType::TrapVision => ToolType::TrapVision,
|
||||
|
ToolRateType::Monogrinder => ToolType::Monogrinder,
|
||||
|
ToolRateType::Digrinder => ToolType::Digrinder,
|
||||
|
ToolRateType::Trigrinder => ToolType::Trigrinder,
|
||||
|
ToolRateType::PowerMaterial => ToolType::PowerMaterial,
|
||||
|
ToolRateType::MindMaterial => ToolType::MindMaterial,
|
||||
|
ToolRateType::EvadeMaterial => ToolType::EvadeMaterial,
|
||||
|
ToolRateType::HpMaterial => ToolType::HpMaterial,
|
||||
|
ToolRateType::TpMaterial => ToolType::TpMaterial,
|
||||
|
ToolRateType::DefMaterial => ToolType::DefMaterial,
|
||||
|
ToolRateType::LuckMaterial => ToolType::LuckMaterial,
|
||||
|
ToolRateType::ScapeDoll => ToolType::ScapeDoll,
|
||||
|
ToolRateType::PhotonDrop => ToolType::PhotonDrop,
|
||||
|
ToolRateType::Technique => todo!(),
|
||||
|
//ToolRateType::Technique => self.tech_table.get_drop(area, rng),
|
||||
|
}
|
||||
|
//let attribute_weights = WeightedIndex::new(&[rates.none, rates.native, rates.abeast, rates.machine, rates.dark, rates.hit]).unwrap();
|
||||
|
}
|
||||
|
|
||||
|
pub fn get_drop<R: Rng>(&self, map_area: &MapVariantType, rng: &mut R) -> Option<ItemDetail> {
|
||||
|
let tool_type = self.tool_type(map_area, rng);
|
||||
|
|
||||
|
Some(ItemDetail::Tool(ToolDetail {
|
||||
|
tool: tool_type
|
||||
|
}))
|
||||
|
}
|
||||
|
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue