jake
5 years ago
3 changed files with 95 additions and 17 deletions
@ -0,0 +1,90 @@ |
|||||
|
|
||||
|
use serde::{Serialize, Deserialize};
|
||||
|
use rand::{Rng, SeedableRng};
|
||||
|
use rand::distributions::{WeightedIndex, Distribution};
|
||||
|
|
||||
|
use crate::entity::item::{ItemDetail, Shield as ShieldDetail};
|
||||
|
use crate::entity::item::shield::{ShieldType, Shield};
|
||||
|
use crate::ship::room::{Difficulty, Episode};
|
||||
|
use crate::ship::map::MapVariantType;
|
||||
|
use crate::entity::character::SectionID;
|
||||
|
use crate::ship::drops::load_data_file;
|
||||
|
|
||||
|
|
||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
struct ShieldRankRates {
|
||||
|
rank0: u32,
|
||||
|
rank1: u32,
|
||||
|
rank2: u32,
|
||||
|
rank3: u32,
|
||||
|
rank4: u32,
|
||||
|
}
|
||||
|
|
||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
pub struct GenericShieldTable {
|
||||
|
rank_rates: ShieldRankRates,
|
||||
|
shield_set: u32,
|
||||
|
}
|
||||
|
|
||||
|
impl GenericShieldTable {
|
||||
|
pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> GenericShieldTable {
|
||||
|
load_data_file(episode, difficulty, section_id, "shield_rate.toml")
|
||||
|
}
|
||||
|
|
||||
|
fn shield_type<R: Rng>(&self, area_map: &MapVariantType, rng: &mut R) -> ShieldType {
|
||||
|
let rank_weights = WeightedIndex::new(&[self.rank_rates.rank0, self.rank_rates.rank1, self.rank_rates.rank2,
|
||||
|
self.rank_rates.rank3, self.rank_rates.rank4]).unwrap();
|
||||
|
let rank = rank_weights.sample(rng) as i32;
|
||||
|
let shield_level = std::cmp::max(0i32, self.shield_set as i32 - 3i32 + rank + area_map.area_value().unwrap_or(0) as i32);
|
||||
|
match shield_level {
|
||||
|
0x00 => ShieldType::Barrier,
|
||||
|
0x01 => ShieldType::Shield,
|
||||
|
0x02 => ShieldType::CoreShield,
|
||||
|
0x03 => ShieldType::GigaShield,
|
||||
|
0x04 => ShieldType::SoulBarrier,
|
||||
|
0x05 => ShieldType::HardShield,
|
||||
|
0x06 => ShieldType::BraveBarrier,
|
||||
|
0x07 => ShieldType::SolidShield,
|
||||
|
0x08 => ShieldType::FlameBarrier,
|
||||
|
0x09 => ShieldType::PlasmaBarrier,
|
||||
|
0x0A => ShieldType::FreezeBarrier,
|
||||
|
0x0B => ShieldType::PsychicBarrier,
|
||||
|
0x0C => ShieldType::GeneralShield,
|
||||
|
0x0D => ShieldType::ProtectBarrier,
|
||||
|
0x0E => ShieldType::GloriousShield,
|
||||
|
0x0F => ShieldType::ImperialBarrier,
|
||||
|
0x10 => ShieldType::GuardianShield,
|
||||
|
0x11 => ShieldType::DivinityBarrier,
|
||||
|
0x12 => ShieldType::UltimateShield,
|
||||
|
0x13 => ShieldType::SpiritualShield,
|
||||
|
0x14 => ShieldType::CelestialShield,
|
||||
|
_ => panic!(),
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
// TODO: this needs the pmt file
|
||||
|
fn dfp_modifier<R: Rng>(&self, shield_type: &ShieldType, rng: &mut R) -> usize {
|
||||
|
0
|
||||
|
}
|
||||
|
|
||||
|
// TODO: this needs the pmt file
|
||||
|
fn evp_modifier<R: Rng>(&self, shield_type: &ShieldType, rng: &mut R) -> usize {
|
||||
|
0
|
||||
|
}
|
||||
|
|
||||
|
pub fn get_drop<R: Rng>(&self, area_map: &MapVariantType, rng: &mut R) -> Option<ItemDetail> {
|
||||
|
let shield_type = self.shield_type(area_map, rng);
|
||||
|
let dfp_modifier = self.dfp_modifier(&shield_type, rng);
|
||||
|
let evp_modifier = self.dfp_modifier(&shield_type, rng);
|
||||
|
|
||||
|
|
||||
|
Some(ItemDetail::Shield(ShieldDetail {
|
||||
|
equipped: false,
|
||||
|
shield: Shield {
|
||||
|
shield: shield_type,
|
||||
|
dfp: dfp_modifier as u8,
|
||||
|
evp: evp_modifier as u8,
|
||||
|
}
|
||||
|
}))
|
||||
|
}
|
||||
|
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue