Browse Source

shield drop table

pbs
jake 5 years ago
parent
commit
663eaf7f25
  1. 14
      src/ship/drops/generic_armor.rs
  2. 90
      src/ship/drops/generic_shield.rs
  3. 8
      src/ship/drops/mod.rs

14
src/ship/drops/generic_armor.rs

@ -10,17 +10,6 @@ use crate::entity::character::SectionID;
use crate::ship::drops::load_data_file; use crate::ship::drops::load_data_file;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct ArmorRankRates { struct ArmorRankRates {
rank0: u32, rank0: u32,
@ -39,8 +28,6 @@ struct ArmorSlotRanks {
slot4: u32, slot4: u32,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct GenericArmorTable { pub struct GenericArmorTable {
rank_rates: ArmorRankRates, rank_rates: ArmorRankRates,
@ -48,7 +35,6 @@ pub struct GenericArmorTable {
armor_set: u32, armor_set: u32,
} }
impl GenericArmorTable { impl GenericArmorTable {
pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> GenericArmorTable { pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> GenericArmorTable {
load_data_file(episode, difficulty, section_id, "armor_rate.toml") load_data_file(episode, difficulty, section_id, "armor_rate.toml")

90
src/ship/drops/generic_shield.rs

@ -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,
}
}))
}
}

8
src/ship/drops/mod.rs

@ -25,6 +25,7 @@ use crate::ship::map::MapVariantType;
use crate::entity::character::SectionID; use crate::entity::character::SectionID;
use crate::ship::drops::generic_weapon::GenericWeaponTable; use crate::ship::drops::generic_weapon::GenericWeaponTable;
use crate::ship::drops::generic_armor::GenericArmorTable; use crate::ship::drops::generic_armor::GenericArmorTable;
use crate::ship::drops::generic_shield::GenericShieldTable;
fn data_file_path(episode: Episode, difficulty: Difficulty, section_id: SectionID, filename: &str) -> PathBuf { fn data_file_path(episode: Episode, difficulty: Difficulty, section_id: SectionID, filename: &str) -> PathBuf {
@ -124,6 +125,7 @@ struct DropTable<R: Rng + SeedableRng> {
monster_stats: HashMap<MonsterType, MonsterDropStats>, monster_stats: HashMap<MonsterType, MonsterDropStats>,
weapon_table: GenericWeaponTable, weapon_table: GenericWeaponTable,
armor_table: GenericArmorTable, armor_table: GenericArmorTable,
shield_table: GenericShieldTable,
rng: R, rng: R,
} }
@ -145,6 +147,7 @@ impl<R: Rng + SeedableRng> DropTable<R> {
monster_stats: monster_stats, monster_stats: monster_stats,
weapon_table: GenericWeaponTable::new(episode, difficulty, section_id), weapon_table: GenericWeaponTable::new(episode, difficulty, section_id),
armor_table: GenericArmorTable::new(episode, difficulty, section_id), armor_table: GenericArmorTable::new(episode, difficulty, section_id),
shield_table: GenericShieldTable::new(episode, difficulty, section_id),
rng: R::from_entropy(), rng: R::from_entropy(),
} }
} }
@ -172,14 +175,13 @@ impl<R: Rng + SeedableRng> DropTable<R> {
fn generate_typed_drop(&mut self, map_area: &MapVariantType, monster: &MonsterDropStats) -> Option<ItemDetail> { fn generate_typed_drop(&mut self, map_area: &MapVariantType, monster: &MonsterDropStats) -> Option<ItemDetail> {
match monster.drop_type { match monster.drop_type {
MonsterDropType::Weapon => self.weapon_table.get_drop(map_area, &mut self.rng), MonsterDropType::Weapon => self.weapon_table.get_drop(map_area, &mut self.rng),
MonsterDropType::Armor => self.generate_armor(),
MonsterDropType::Shield => self.generate_shield(),
MonsterDropType::Armor => self.armor_table.get_drop(map_area, &mut self.rng),
MonsterDropType::Shield => self.shield_table.get_drop(map_area, &mut self.rng),
MonsterDropType::Unit => self.generate_unit(), MonsterDropType::Unit => self.generate_unit(),
MonsterDropType::None => None, MonsterDropType::None => None,
} }
} }
fn get_drop(&mut self, map_area: &MapVariantType, monster: &MonsterType) -> Option<ItemDetail> { fn get_drop(&mut self, map_area: &MapVariantType, monster: &MonsterType) -> Option<ItemDetail> {
//let mut rng = rand::thread_rng(); //let mut rng = rand::thread_rng();
let monster_stat = *self.monster_stats.get(monster)?; let monster_stat = *self.monster_stats.get(monster)?;

Loading…
Cancel
Save