From 1279fedfeeeeb2ee7328c683a7d62a27a362e2d5 Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 3 Apr 2020 22:51:55 -0700 Subject: [PATCH] MapVariantType -> MapArea --- src/ship/drops/box_drop_table.rs | 20 ++-- src/ship/drops/generic_armor.rs | 18 +-- src/ship/drops/generic_shield.rs | 16 +-- src/ship/drops/generic_unit.rs | 20 ++-- src/ship/drops/generic_weapon.rs | 46 ++++---- src/ship/drops/mod.rs | 12 +- src/ship/drops/rare_drop_table.rs | 6 +- src/ship/drops/tech_table.rs | 16 +-- src/ship/drops/tool_table.rs | 8 +- src/ship/map.rs | 180 +++++++++++++++++------------- 10 files changed, 183 insertions(+), 159 deletions(-) diff --git a/src/ship/drops/box_drop_table.rs b/src/ship/drops/box_drop_table.rs index d6101d8..f78acdb 100644 --- a/src/ship/drops/box_drop_table.rs +++ b/src/ship/drops/box_drop_table.rs @@ -10,7 +10,7 @@ use crate::entity::item::tool::{Tool, ToolType}; use crate::entity::character::SectionID; use crate::ship::monster::MonsterType; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::map::{MapObject, MapObjectType, FixedBoxDropType}; use crate::ship::drops::rare_drop_table::{RareDropTable, RareDropItem}; @@ -49,8 +49,8 @@ struct BoxDropRates { } impl BoxDropRates { - fn rates_by_area(&self, map_area: &MapVariantType) -> &BoxDropRate { - match map_area.area_value().unwrap() { + fn rates_by_area(&self, map_area: &MapArea) -> &BoxDropRate { + match map_area.drop_area_value().unwrap() { 0 => &self.area1, 1 => &self.area2, 2 => &self.area3, @@ -122,8 +122,8 @@ impl BoxRareRates { } } - fn rates_by_area(&self, map_area: &MapVariantType) -> &Vec { - match map_area.area_value().unwrap() { + fn rates_by_area(&self, map_area: &MapArea) -> &Vec { + match map_area.drop_area_value().unwrap() { 0 => &self.area1, 1 => &self.area2, 2 => &self.area3, @@ -171,7 +171,7 @@ impl BoxDropTable { } - fn rare_drop(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + fn rare_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { self.rare_rates.rates_by_area(map_area).iter() .filter_map(|rate| { let rand: f32 = rng.gen(); @@ -184,7 +184,7 @@ impl BoxDropTable { }).nth(0) } - fn random_box_drop(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + fn random_box_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { self.rare_drop(map_area, rng).or_else(|| { let rate = self.box_rates.rates_by_area(map_area); let type_weights = WeightedIndex::new(&[rate.weapon_rate, rate.armor_rate, rate.shield_rate, rate.unit_rate, @@ -202,7 +202,7 @@ impl BoxDropTable { }) } - fn fixed_box_drop(&self, fixed_drop: FixedBoxDropType, map_area: &MapVariantType, rng: &mut R) -> Option { + fn fixed_box_drop(&self, fixed_drop: FixedBoxDropType, map_area: &MapArea, rng: &mut R) -> Option { match fixed_drop { FixedBoxDropType::Weapon => self.weapon_table.get_drop(map_area, rng), FixedBoxDropType::Armor => self.armor_table.get_drop(map_area, rng), // TODO: should this drop shield? @@ -216,7 +216,7 @@ impl BoxDropTable { } } - pub fn get_drop(&self, map_area: &MapVariantType, object: &MapObject, rng: &mut R) -> Option { + pub fn get_drop(&self, map_area: &MapArea, object: &MapObject, rng: &mut R) -> Option { match object.object { MapObjectType::Box | MapObjectType::EnemyBox | MapObjectType::RuinsBox| MapObjectType::RuinsEnemyBox | MapObjectType::CcaBox => { @@ -243,6 +243,6 @@ mod test { let bdt = BoxDropTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); - println!("{:?}", bdt.get_drop(&MapVariantType::Forest1, &MapObject {object: MapObjectType::Box}, &mut rng)); + println!("{:?}", bdt.get_drop(&MapArea::Forest1, &MapObject {object: MapObjectType::Box}, &mut rng)); } } diff --git a/src/ship/drops/generic_armor.rs b/src/ship/drops/generic_armor.rs index ec1b174..c9f6468 100644 --- a/src/ship/drops/generic_armor.rs +++ b/src/ship/drops/generic_armor.rs @@ -5,7 +5,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use crate::entity::item::armor::{ArmorType, Armor}; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{armor_stats, ArmorStats}; @@ -45,11 +45,11 @@ impl GenericArmorTable { gat } - fn armor_type(&self, area_map: &MapVariantType, rng: &mut R) -> ArmorType { + fn armor_type(&self, area_map: &MapArea, rng: &mut R) -> ArmorType { 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 armor_level = std::cmp::max(0i32, self.armor_set as i32 - 3i32 + rank + area_map.area_value().unwrap_or(0) as i32); + let armor_level = std::cmp::max(0i32, self.armor_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32); match armor_level { 0x00 => ArmorType::Frame, 0x01 => ArmorType::Armor, @@ -79,7 +79,7 @@ impl GenericArmorTable { } } - pub fn slots(&self, area_map: &MapVariantType, rng: &mut R) -> usize { + pub fn slots(&self, area_map: &MapArea, rng: &mut R) -> usize { let slot_weights = WeightedIndex::new(&[self.slot_rates.slot0, self.slot_rates.slot1, self.slot_rates.slot2, self.slot_rates.slot3, self.slot_rates.slot4]).unwrap(); slot_weights.sample(rng) @@ -95,7 +95,7 @@ impl GenericArmorTable { rng.gen_range(0, stats.evp_modifier) } - pub fn get_drop(&self, area_map: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, area_map: &MapArea, rng: &mut R) -> Option { let armor_type = self.armor_type(area_map, rng); let slots = self.slots(area_map, rng); let dfp_modifier = self.dfp_modifier(&armor_type, rng); @@ -120,25 +120,25 @@ mod test { let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]); let gat = GenericArmorTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); - assert!(gat.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDropType::Armor(Armor { + assert!(gat.get_drop(&MapArea::Mines1, &mut rng) == Some(ItemDropType::Armor(Armor { armor: ArmorType::GeneralArmor, dfp: 0, evp: 0, slots: 1, }))); - assert!(gat.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDropType::Armor(Armor { + assert!(gat.get_drop(&MapArea::Caves3, &mut rng) == Some(ItemDropType::Armor(Armor { armor: ArmorType::AbsorbArmor, dfp: 1, evp: 1, slots: 1, }))); - assert!(gat.get_drop(&MapVariantType::Forest2, &mut rng) == Some(ItemDropType::Armor(Armor { + assert!(gat.get_drop(&MapArea::Forest2, &mut rng) == Some(ItemDropType::Armor(Armor { armor: ArmorType::HyperFrame, dfp: 0, evp: 0, slots: 0, }))); - assert!(gat.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDropType::Armor(Armor { + assert!(gat.get_drop(&MapArea::DarkFalz, &mut rng) == Some(ItemDropType::Armor(Armor { armor: ArmorType::ImperialArmor, dfp: 2, evp: 1, diff --git a/src/ship/drops/generic_shield.rs b/src/ship/drops/generic_shield.rs index 725ff66..d0edfd9 100644 --- a/src/ship/drops/generic_shield.rs +++ b/src/ship/drops/generic_shield.rs @@ -5,7 +5,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use crate::entity::item::shield::{ShieldType, Shield}; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{shield_stats, ShieldStats}; @@ -35,11 +35,11 @@ impl GenericShieldTable { gst } - fn shield_type(&self, area_map: &MapVariantType, rng: &mut R) -> ShieldType { + fn shield_type(&self, area_map: &MapArea, 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); + let shield_level = std::cmp::max(0i32, self.shield_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32); match shield_level { 0x00 => ShieldType::Barrier, 0x01 => ShieldType::Shield, @@ -76,7 +76,7 @@ impl GenericShieldTable { rng.gen_range(0, stats.evp_modifier) } - pub fn get_drop(&self, area_map: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, area_map: &MapArea, rng: &mut R) -> Option { 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); @@ -100,22 +100,22 @@ mod test { let gst = GenericShieldTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); - assert!(gst.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDropType::Shield(Shield { + assert!(gst.get_drop(&MapArea::Forest1, &mut rng) == Some(ItemDropType::Shield(Shield { shield: ShieldType::FreezeBarrier, dfp: 4, evp: 1, }))); - assert!(gst.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDropType::Shield(Shield { + assert!(gst.get_drop(&MapArea::Caves3, &mut rng) == Some(ItemDropType::Shield(Shield { shield: ShieldType::PsychicBarrier, dfp: 3, evp: 2, }))); - assert!(gst.get_drop(&MapVariantType::Mines2, &mut rng) == Some(ItemDropType::Shield(Shield { + assert!(gst.get_drop(&MapArea::Mines2, &mut rng) == Some(ItemDropType::Shield(Shield { shield: ShieldType::ImperialBarrier, dfp: 0, evp: 4, }))); - assert!(gst.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDropType::Shield(Shield { + assert!(gst.get_drop(&MapArea::DarkFalz, &mut rng) == Some(ItemDropType::Shield(Shield { shield: ShieldType::DivinityBarrier, dfp: 1, evp: 0, diff --git a/src/ship/drops/generic_unit.rs b/src/ship/drops/generic_unit.rs index 7e2224e..1f432f8 100644 --- a/src/ship/drops/generic_unit.rs +++ b/src/ship/drops/generic_unit.rs @@ -6,7 +6,7 @@ use rand::seq::IteratorRandom; use crate::entity::item::unit::{UnitType, Unit, UnitModifier}; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{unit_stats, UnitStats}; @@ -28,8 +28,8 @@ struct UnitLevels { } impl UnitLevels { - fn level_by_area(&self, map_area: &MapVariantType) -> u32 { - match map_area.area_value().unwrap() { + fn level_by_area(&self, map_area: &MapArea) -> u32 { + match map_area.drop_area_value().unwrap() { 0 => self.area1, 1 => self.area2, 2 => self.area3, @@ -60,7 +60,7 @@ impl GenericUnitTable { } } - fn unit_type_and_modifier(&self, area_map: &MapVariantType, rng: &mut R) -> Option<(UnitType, Option)> { + fn unit_type_and_modifier(&self, area_map: &MapArea, rng: &mut R) -> Option<(UnitType, Option)> { let level = self.unit_levels.level_by_area(area_map) as i32; if level == 0 { return None; @@ -83,7 +83,7 @@ impl GenericUnitTable { Some(units.choose(rng).unwrap()) } - pub fn get_drop(&self, area_map: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, area_map: &MapArea, rng: &mut R) -> Option { let unit_type_modifier = self.unit_type_and_modifier(area_map, rng); unit_type_modifier.map(|(unit_type, unit_modifier)| { @@ -104,14 +104,14 @@ mod test { let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]); let gut = GenericUnitTable::new(Episode::One, Difficulty::Normal, SectionID::Skyly); - assert!(gut.get_drop(&MapVariantType::Forest1, &mut rng) == None); + assert!(gut.get_drop(&MapArea::Forest1, &mut rng) == None); let gut = GenericUnitTable::new(Episode::One, Difficulty::Hard, SectionID::Skyly); - let unit_tests = vec![(MapVariantType::Forest1, UnitType::ResistFreeze, Some(UnitModifier::PlusPlus)), - (MapVariantType::Caves3, UnitType::GeneralTp, None), - (MapVariantType::Mines2, UnitType::ResistEvil, Some(UnitModifier::PlusPlus)), - (MapVariantType::DarkFalz, UnitType::DragonHp, Some(UnitModifier::Minus))]; + let unit_tests = vec![(MapArea::Forest1, UnitType::ResistFreeze, Some(UnitModifier::PlusPlus)), + (MapArea::Caves3, UnitType::GeneralTp, None), + (MapArea::Mines2, UnitType::ResistEvil, Some(UnitModifier::PlusPlus)), + (MapArea::DarkFalz, UnitType::DragonHp, Some(UnitModifier::Minus))]; for (area, unit, umod) in unit_tests { assert!(gut.get_drop(&area, &mut rng) == Some(ItemDropType::Unit(Unit { unit: unit, diff --git a/src/ship/drops/generic_weapon.rs b/src/ship/drops/generic_weapon.rs index d34f484..761d329 100644 --- a/src/ship/drops/generic_weapon.rs +++ b/src/ship/drops/generic_weapon.rs @@ -8,7 +8,7 @@ use rand::seq::SliceRandom; use crate::entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial}; use crate::ship::monster::MonsterType; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; @@ -95,8 +95,8 @@ struct AttributeRates { } impl AttributeRates { - fn get_by_area(&self, map_area: &MapVariantType) -> AttributeRate { - match map_area.area_value().unwrap() { + fn get_by_area(&self, map_area: &MapArea) -> AttributeRate { + match map_area.drop_area_value().unwrap() { 0 => self.area1, 1 => self.area2, 2 => self.area3, @@ -179,8 +179,8 @@ struct AreaPercentPatterns { } impl AreaPercentPatterns { - fn get_by_area(&self, map_area: &MapVariantType) -> AttributePercentPattern { - match map_area.area_value().unwrap() { + fn get_by_area(&self, map_area: &MapArea) -> AttributePercentPattern { + match map_area.drop_area_value().unwrap() { 0 => self.area1, 1 => self.area2, 2 => self.area3, @@ -301,13 +301,13 @@ impl AttributeTable { }).0 } - fn generate_attributes(&self, map_area: &MapVariantType, rng: &mut R) -> [Option; 3] { + fn generate_attributes(&self, map_area: &MapArea, rng: &mut R) -> [Option; 3] { let percent_pattern = self.area_percent_patterns.get_by_area(map_area); let attribute_rate = self.attribute_rates.get_by_area(map_area); self.attributes(&percent_pattern, &attribute_rate, rng) } - pub fn generate_rare_attributes(&self, map_area: &MapVariantType, rng: &mut R) -> [Option; 3] { + pub fn generate_rare_attributes(&self, map_area: &MapArea, rng: &mut R) -> [Option; 3] { let percent_pattern = AttributePercentPattern { attribute1: Some(PercentPatternType::Pattern6), attribute2: Some(PercentPatternType::Pattern6), @@ -345,8 +345,8 @@ impl SpecialRates { load_data_file(episode, difficulty, section_id, "weapon_special_rate.toml") } - fn rate_by_area(&self, map_area: &MapVariantType) -> SpecialRate { - match map_area.area_value().unwrap() { + fn rate_by_area(&self, map_area: &MapArea) -> SpecialRate { + match map_area.drop_area_value().unwrap() { 0 => self.area1, 1 => self.area2, 2 => self.area3, @@ -376,7 +376,7 @@ impl SpecialRates { *specials.choose(rng).unwrap() } - fn get_special(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + fn get_special(&self, map_area: &MapArea, rng: &mut R) -> Option { let rate = self.rate_by_area(map_area); if rng.gen_range(0, 100) < rate.rate { Some(self.random_special_by_rank(rate.rank, rng)) @@ -422,16 +422,16 @@ impl GenericWeaponTable { } } - fn area_rank(&self, ratio: &WeaponRatio, map_area: &MapVariantType) -> (u32, u32) { + fn area_rank(&self, ratio: &WeaponRatio, map_area: &MapArea) -> (u32, u32) { if ratio.rank >= 0 { - (map_area.area_value().unwrap_or(0), ratio.rank as u32) + (map_area.drop_area_value().unwrap_or(0), ratio.rank as u32) } else { - ((map_area.area_value().unwrap_or(0) as i32 + ratio.rank) as u32, 0) + ((map_area.drop_area_value().unwrap_or(0) as i32 + ratio.rank) as u32, 0) } } - fn get_possible_weapon_types(&self, map_area: &MapVariantType) -> BTreeMap { + fn get_possible_weapon_types(&self, map_area: &MapArea) -> BTreeMap { let mut valid_weapons = BTreeMap::new(); let item_rate_pairs = vec![ @@ -450,7 +450,7 @@ impl GenericWeaponTable { ]; for (item_type, ratio) in item_rate_pairs.into_iter() { - if ratio.rate > 0 && map_area.area_value().map(|k| k as i32 + ratio.rank).unwrap_or(-1) >= 0 { + if ratio.rate > 0 && map_area.drop_area_value().map(|k| k as i32 + ratio.rank).unwrap_or(-1) >= 0 { valid_weapons.insert(item_type, ratio); } } @@ -458,7 +458,7 @@ impl GenericWeaponTable { valid_weapons } - fn weapon_type(&self, possible_weapon_types: &BTreeMap, map_area: &MapVariantType, rng: &mut R) -> WeaponDropType { + fn weapon_type(&self, possible_weapon_types: &BTreeMap, map_area: &MapArea, rng: &mut R) -> WeaponDropType { let mut weapon_rates = possible_weapon_types.iter() .map(|(weapon, stat)| { (weapon, stat.rate) @@ -468,7 +468,7 @@ impl GenericWeaponTable { } - fn weapon_rank(&self, ratio: &WeaponRatio, map_area: &MapVariantType) -> u32 { + fn weapon_rank(&self, ratio: &WeaponRatio, map_area: &MapArea) -> u32 { let (area, rank) = self.area_rank(ratio, map_area); let weapon_rank = (rank + area / ratio.inc); @@ -480,7 +480,7 @@ impl GenericWeaponTable { weapons[std::cmp::min(weapons.len() - 1, weapon_rank as usize)] } - fn get_grind(&self, ratio: &WeaponRatio, map_area: &MapVariantType, rng: &mut R) -> usize { + fn get_grind(&self, ratio: &WeaponRatio, map_area: &MapArea, rng: &mut R) -> usize { let (area, _) = self.area_rank(ratio, map_area); let pattern = std::cmp::min(area % ratio.inc, 3); @@ -489,7 +489,7 @@ impl GenericWeaponTable { grind_choice.sample(rng) } - pub fn get_drop(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { let possible_weapon_types = self.get_possible_weapon_types(map_area); let weapon_type = self.weapon_type(&possible_weapon_types, map_area, rng); let ratio = possible_weapon_types.get(&weapon_type).unwrap(); @@ -519,7 +519,7 @@ mod test { let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]); let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Normal, SectionID::Skyly); - assert!(gwt.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDropType::Weapon(Weapon { + assert!(gwt.get_drop(&MapArea::Forest1, &mut rng) == Some(ItemDropType::Weapon(Weapon { weapon: WeaponType::Cane, special: None, grind: 0, @@ -528,7 +528,7 @@ mod test { }))); let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Hard, SectionID::Skyly); - assert!(gwt.get_drop(&MapVariantType::Caves2, &mut rng) == Some(ItemDropType::Weapon(Weapon { + assert!(gwt.get_drop(&MapArea::Caves2, &mut rng) == Some(ItemDropType::Weapon(Weapon { weapon: WeaponType::Sniper, special: None, grind: 2, @@ -537,7 +537,7 @@ mod test { }))); let gwt = GenericWeaponTable::new(Episode::One, Difficulty::VeryHard, SectionID::Skyly); - assert!(gwt.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDropType::Weapon(Weapon { + assert!(gwt.get_drop(&MapArea::Mines1, &mut rng) == Some(ItemDropType::Weapon(Weapon { weapon: WeaponType::Club, special: Some(WeaponSpecial::Berserk), grind: 0, @@ -546,7 +546,7 @@ mod test { }))); let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); - assert!(gwt.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDropType::Weapon(Weapon { + assert!(gwt.get_drop(&MapArea::DarkFalz, &mut rng) == Some(ItemDropType::Weapon(Weapon { weapon: WeaponType::Vulcan, special: None, grind: 0, diff --git a/src/ship/drops/mod.rs b/src/ship/drops/mod.rs index 32a98b7..9887e7e 100644 --- a/src/ship/drops/mod.rs +++ b/src/ship/drops/mod.rs @@ -17,7 +17,7 @@ use rand::{Rng, SeedableRng}; use crate::ship::monster::MonsterType; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::generic_weapon::GenericWeaponTable; use crate::ship::drops::generic_armor::GenericArmorTable; @@ -98,7 +98,7 @@ impl ItemDrop { -struct DropTable { +pub struct DropTable { monster_stats: HashMap, rare_table: RareDropTable, weapon_table: GenericWeaponTable, @@ -112,7 +112,7 @@ struct DropTable { impl DropTable { - fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> DropTable { + pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> DropTable { let mut path = PathBuf::from("data/drops/"); path.push(episode.to_string()); path.push(difficulty.to_string().to_lowercase()); @@ -140,7 +140,7 @@ impl DropTable { Some(ItemDropType::Meseta(self.rng.gen_range(monster.min_meseta, monster.max_meseta))) } - fn generate_typed_drop(&mut self, map_area: &MapVariantType, monster: &MonsterDropStats) -> Option { + fn generate_typed_drop(&mut self, map_area: &MapArea, monster: &MonsterDropStats) -> Option { match monster.drop_type { MonsterDropType::Weapon => self.weapon_table.get_drop(map_area, &mut self.rng), MonsterDropType::Armor => self.armor_table.get_drop(map_area, &mut self.rng), @@ -150,7 +150,7 @@ impl DropTable { } } - fn get_drop(&mut self, map_area: &MapVariantType, monster: &MonsterType) -> Option { + pub fn get_drop(&mut self, map_area: &MapArea, monster: &MonsterType) -> Option { let monster_stat = *self.monster_stats.get(monster)?; let drop_anything = self.rng.gen_range(0, 100); @@ -178,7 +178,7 @@ impl DropTable { } } - pub fn get_box_drop(&mut self, map_area: &MapVariantType, object: &MapObject) -> Option { + pub fn get_box_drop(&mut self, map_area: &MapArea, object: &MapObject) -> Option { self.box_table.get_drop(map_area, object, &mut self.rng) } } diff --git a/src/ship/drops/rare_drop_table.rs b/src/ship/drops/rare_drop_table.rs index 286e197..04fa477 100644 --- a/src/ship/drops/rare_drop_table.rs +++ b/src/ship/drops/rare_drop_table.rs @@ -10,7 +10,7 @@ use crate::entity::item::mag::{Mag, MagType}; use crate::entity::character::SectionID; use crate::ship::monster::MonsterType; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::drops::generic_weapon::AttributeTable; use crate::ship::drops::generic_armor::GenericArmorTable; @@ -95,7 +95,7 @@ impl RareDropTable { } } - pub fn apply_item_stats(&self, map_area: &MapVariantType, item: RareDropItem, rng: &mut R) -> ItemDropType { + pub fn apply_item_stats(&self, map_area: &MapArea, item: RareDropItem, rng: &mut R) -> ItemDropType { match item { RareDropItem::Weapon(weapon) => { ItemDropType::Weapon(Weapon { @@ -148,7 +148,7 @@ impl RareDropTable { } } - pub fn get_drop(&self, map_area: &MapVariantType, monster: &MonsterType, rng: &mut R) -> Option { + pub fn get_drop(&self, map_area: &MapArea, monster: &MonsterType, rng: &mut R) -> Option { self.rates.get(monster) .and_then(|drop_rates| { drop_rates.iter() diff --git a/src/ship/drops/tech_table.rs b/src/ship/drops/tech_table.rs index 5a9efd5..370f9c5 100644 --- a/src/ship/drops/tech_table.rs +++ b/src/ship/drops/tech_table.rs @@ -6,7 +6,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use crate::entity::item::tech::{Technique, TechniqueDisk}; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; @@ -65,8 +65,8 @@ impl TechniqueRates { } impl TechniqueRates { - fn get_by_area<'a>(&'a self, map_area: &MapVariantType) -> &'a BTreeMap { - match map_area.area_value().unwrap() { + fn get_by_area<'a>(&'a self, map_area: &MapArea) -> &'a BTreeMap { + match map_area.drop_area_value().unwrap() { 0 => &self.area1, 1 => &self.area2, 2 => &self.area3, @@ -95,7 +95,7 @@ impl TechniqueTable { } - pub fn get_drop(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { let mut tech_rates = self.rates.get_by_area(map_area).iter(); let tech_weights = WeightedIndex::new(tech_rates.clone().map(|(_, stat)| stat.rate)).unwrap(); @@ -118,10 +118,10 @@ mod test { let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]); let tt = TechniqueTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); - let tech_tests = vec![(MapVariantType::Forest1, Technique::Resta, 13), - (MapVariantType::Caves3, Technique::Foie, 24), - (MapVariantType::Mines2, Technique::Gibarta, 20), - (MapVariantType::DarkFalz, Technique::Razonde, 22)]; + let tech_tests = vec![(MapArea::Forest1, Technique::Resta, 13), + (MapArea::Caves3, Technique::Foie, 24), + (MapArea::Mines2, Technique::Gibarta, 20), + (MapArea::DarkFalz, Technique::Razonde, 22)]; for (area, tech, level) in tech_tests { assert!(tt.get_drop(&area, &mut rng) == Some(ItemDropType::TechniqueDisk( diff --git a/src/ship/drops/tool_table.rs b/src/ship/drops/tool_table.rs index 04c73ea..d20d9da 100644 --- a/src/ship/drops/tool_table.rs +++ b/src/ship/drops/tool_table.rs @@ -6,7 +6,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use crate::entity::item::tool::{Tool, ToolType}; use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapVariantType; +use crate::ship::map::MapArea; use crate::entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::drops::tech_table::TechniqueTable; @@ -93,8 +93,8 @@ impl ToolRates { } impl ToolRates { - fn get_by_area<'a>(&'a self, map_area: &MapVariantType) -> &'a BTreeMap { - match map_area.area_value().unwrap() { + fn get_by_area<'a>(&'a self, map_area: &MapArea) -> &'a BTreeMap { + match map_area.drop_area_value().unwrap() { 0 => &self.area1, 1 => &self.area2, 2 => &self.area3, @@ -124,7 +124,7 @@ impl ToolTable { } } - pub fn get_drop(&self, map_area: &MapVariantType, rng: &mut R) -> Option { + pub fn get_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { let tool_rates = self.rates.get_by_area(map_area).iter(); let tool_weights = WeightedIndex::new(tool_rates.clone().map(|(_, weights)| weights)).unwrap(); diff --git a/src/ship/map.rs b/src/ship/map.rs index 7133aa7..afd4802 100644 --- a/src/ship/map.rs +++ b/src/ship/map.rs @@ -340,9 +340,8 @@ enum MapVariantMode { Offline, } -// TODO: rename this since apparently I'm going to be using it a lot #[derive(Debug)] -pub enum MapVariantType { +pub enum MapArea { Pioneer2Ep1, Forest1, Forest2, @@ -360,23 +359,48 @@ pub enum MapVariantType { DarkFalz, } -impl MapVariantType { - pub fn area_value(&self) -> Option { +pub enum MapAreaError { + UnknownMapArea(u32), +} + +impl MapArea { + pub fn from_value(episode: Episode, area: u32) -> Result { + match (episode, area) { + (Episode::One, 0) => Ok(MapArea::Pioneer2Ep1), + (Episode::One, 1) => Ok(MapArea::Forest1), + (Episode::One, 2) => Ok(MapArea::Forest2), + (Episode::One, 3) => Ok(MapArea::Caves1), + (Episode::One, 4) => Ok(MapArea::Caves2), + (Episode::One, 5) => Ok(MapArea::Caves3), + (Episode::One, 6) => Ok(MapArea::Mines1), + (Episode::One, 7) => Ok(MapArea::Mines2), + (Episode::One, 8) => Ok(MapArea::Ruins1), + (Episode::One, 9) => Ok(MapArea::Ruins2), + (Episode::One, 10) => Ok(MapArea::Ruins3), + (Episode::One, 11) => Ok(MapArea::Dragon), + (Episode::One, 12) => Ok(MapArea::DeRolLe), + (Episode::One, 13) => Ok(MapArea::VolOpt), + (Episode::One, 14) => Ok(MapArea::DarkFalz), + _ => Err(MapAreaError::UnknownMapArea(area)) + } + } + + pub fn drop_area_value(&self) -> Option { match self { - MapVariantType::Forest1 => Some(0), - MapVariantType::Forest2 => Some(1), - MapVariantType::Caves1 => Some(2), - MapVariantType::Caves2 => Some(3), - MapVariantType::Caves3 => Some(4), - MapVariantType::Mines1 => Some(5), - MapVariantType::Mines2 => Some(6), - MapVariantType::Ruins1 => Some(7), - MapVariantType::Ruins2 => Some(8), - MapVariantType::Ruins3 => Some(9), - MapVariantType::Dragon => Some(2), - MapVariantType::DeRolLe => Some(5), - MapVariantType::VolOpt => Some(7), - MapVariantType::DarkFalz => Some(9), + MapArea::Forest1 => Some(0), + MapArea::Forest2 => Some(1), + MapArea::Caves1 => Some(2), + MapArea::Caves2 => Some(3), + MapArea::Caves3 => Some(4), + MapArea::Mines1 => Some(5), + MapArea::Mines2 => Some(6), + MapArea::Ruins1 => Some(7), + MapArea::Ruins2 => Some(8), + MapArea::Ruins3 => Some(9), + MapArea::Dragon => Some(2), + MapArea::DeRolLe => Some(5), + MapArea::VolOpt => Some(7), + MapArea::DarkFalz => Some(9), _ => None } } @@ -385,31 +409,31 @@ impl MapVariantType { #[derive(Debug)] struct MapVariant { - map: MapVariantType, + map: MapArea, mode: MapVariantMode, major: u8, minor: u8, } impl MapVariant { - fn new(map: MapVariantType, mode: MapVariantMode) -> MapVariant { + fn new(map: MapArea, mode: MapVariantMode) -> MapVariant { let major = match map { - MapVariantType::Pioneer2Ep1 => 0, - MapVariantType::Forest1 | MapVariantType::Forest2 => 0, - MapVariantType::Caves1 | MapVariantType::Caves2 | MapVariantType::Caves3 => rand::thread_rng().gen_range(0, 3), - MapVariantType::Mines1 | MapVariantType::Mines2 => rand::thread_rng().gen_range(0, 3), - MapVariantType::Ruins1 | MapVariantType::Ruins2 | MapVariantType::Ruins3 => rand::thread_rng().gen_range(0, 3), - MapVariantType::Dragon | MapVariantType::DeRolLe | MapVariantType::VolOpt | MapVariantType::DarkFalz => 0, + MapArea::Pioneer2Ep1 => 0, + MapArea::Forest1 | MapArea::Forest2 => 0, + MapArea::Caves1 | MapArea::Caves2 | MapArea::Caves3 => rand::thread_rng().gen_range(0, 3), + MapArea::Mines1 | MapArea::Mines2 => rand::thread_rng().gen_range(0, 3), + MapArea::Ruins1 | MapArea::Ruins2 | MapArea::Ruins3 => rand::thread_rng().gen_range(0, 3), + MapArea::Dragon | MapArea::DeRolLe | MapArea::VolOpt | MapArea::DarkFalz => 0, }; let minor = match map { - MapVariantType::Pioneer2Ep1 => 0, - MapVariantType::Forest1 => rand::thread_rng().gen_range(0, 5), - MapVariantType::Forest2 => rand::thread_rng().gen_range(0, 5), - MapVariantType::Caves1 | MapVariantType::Caves2 | MapVariantType::Caves3 => rand::thread_rng().gen_range(0, 2), - MapVariantType::Mines1 | MapVariantType::Mines2 => rand::thread_rng().gen_range(0, 2), - MapVariantType::Ruins1 | MapVariantType::Ruins2 | MapVariantType::Ruins3 => rand::thread_rng().gen_range(0, 2), - MapVariantType::Dragon | MapVariantType::DeRolLe | MapVariantType::VolOpt | MapVariantType::DarkFalz => 0, + MapArea::Pioneer2Ep1 => 0, + MapArea::Forest1 => rand::thread_rng().gen_range(0, 5), + MapArea::Forest2 => rand::thread_rng().gen_range(0, 5), + MapArea::Caves1 | MapArea::Caves2 | MapArea::Caves3 => rand::thread_rng().gen_range(0, 2), + MapArea::Mines1 | MapArea::Mines2 => rand::thread_rng().gen_range(0, 2), + MapArea::Ruins1 | MapArea::Ruins2 | MapArea::Ruins3 => rand::thread_rng().gen_range(0, 2), + MapArea::Dragon | MapArea::DeRolLe | MapArea::VolOpt | MapArea::DarkFalz => 0, }; MapVariant { @@ -422,41 +446,41 @@ impl MapVariant { // TODO: rename to npc_file fn dat_file(&self) -> String { match self.map { - MapVariantType::Pioneer2Ep1 => "data/maps/map_city00_00e.dat".into(), - MapVariantType::Forest1 => format!("data/maps/map_forest01_0{}e.dat", self.minor), - MapVariantType::Forest2 => format!("data/maps/map_forest02_0{}e.dat", self.minor), - MapVariantType::Caves1 => format!("data/maps/map_cave01_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Caves2 => format!("data/maps/map_cave02_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Caves3 => format!("data/maps/map_cave03_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Mines1 => format!("data/maps/map_machine01_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Mines2 => format!("data/maps/map_machine02_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Ruins1 => format!("data/maps/map_ancient01_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Ruins2 => format!("data/maps/map_ancient02_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Ruins3 => format!("data/maps/map_ancient03_0{}_0{}e.dat", self.major, self.minor), - MapVariantType::Dragon => "data/maps/map_boss01e.dat".into(), - MapVariantType::DeRolLe => "data/maps/map_boss02e.dat".into(), - MapVariantType::VolOpt => "data/maps/map_boss03e.dat".into(), - MapVariantType::DarkFalz => "data/maps/map_boss04e.dat".into(), + MapArea::Pioneer2Ep1 => "data/maps/map_city00_00e.dat".into(), + MapArea::Forest1 => format!("data/maps/map_forest01_0{}e.dat", self.minor), + MapArea::Forest2 => format!("data/maps/map_forest02_0{}e.dat", self.minor), + MapArea::Caves1 => format!("data/maps/map_cave01_0{}_0{}e.dat", self.major, self.minor), + MapArea::Caves2 => format!("data/maps/map_cave02_0{}_0{}e.dat", self.major, self.minor), + MapArea::Caves3 => format!("data/maps/map_cave03_0{}_0{}e.dat", self.major, self.minor), + MapArea::Mines1 => format!("data/maps/map_machine01_0{}_0{}e.dat", self.major, self.minor), + MapArea::Mines2 => format!("data/maps/map_machine02_0{}_0{}e.dat", self.major, self.minor), + MapArea::Ruins1 => format!("data/maps/map_ancient01_0{}_0{}e.dat", self.major, self.minor), + MapArea::Ruins2 => format!("data/maps/map_ancient02_0{}_0{}e.dat", self.major, self.minor), + MapArea::Ruins3 => format!("data/maps/map_ancient03_0{}_0{}e.dat", self.major, self.minor), + MapArea::Dragon => "data/maps/map_boss01e.dat".into(), + MapArea::DeRolLe => "data/maps/map_boss02e.dat".into(), + MapArea::VolOpt => "data/maps/map_boss03e.dat".into(), + MapArea::DarkFalz => "data/maps/map_boss04e.dat".into(), } } fn obj_file(&self) -> String { match self.map { - MapVariantType::Pioneer2Ep1 => "data/maps/map_city00_00e.dat".into(), - MapVariantType::Forest1 => format!("data/maps/map_forest01_0{}o.dat", self.minor), - MapVariantType::Forest2 => format!("data/maps/map_forest02_0{}o.dat", self.minor), - MapVariantType::Caves1 => format!("data/maps/map_cave01_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Caves2 => format!("data/maps/map_cave02_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Caves3 => format!("data/maps/map_cave03_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Mines1 => format!("data/maps/map_machine01_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Mines2 => format!("data/maps/map_machine02_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Ruins1 => format!("data/maps/map_ancient01_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Ruins2 => format!("data/maps/map_ancient02_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Ruins3 => format!("data/maps/map_ancient03_0{}_0{}o.dat", self.major, self.minor), - MapVariantType::Dragon => "data/maps/map_boss01o.dat".into(), - MapVariantType::DeRolLe => "data/maps/map_boss02o.dat".into(), - MapVariantType::VolOpt => "data/maps/map_boss03o.dat".into(), - MapVariantType::DarkFalz => "data/maps/map_boss04o.dat".into(), + MapArea::Pioneer2Ep1 => "data/maps/map_city00_00e.dat".into(), + MapArea::Forest1 => format!("data/maps/map_forest01_0{}o.dat", self.minor), + MapArea::Forest2 => format!("data/maps/map_forest02_0{}o.dat", self.minor), + MapArea::Caves1 => format!("data/maps/map_cave01_0{}_0{}o.dat", self.major, self.minor), + MapArea::Caves2 => format!("data/maps/map_cave02_0{}_0{}o.dat", self.major, self.minor), + MapArea::Caves3 => format!("data/maps/map_cave03_0{}_0{}o.dat", self.major, self.minor), + MapArea::Mines1 => format!("data/maps/map_machine01_0{}_0{}o.dat", self.major, self.minor), + MapArea::Mines2 => format!("data/maps/map_machine02_0{}_0{}o.dat", self.major, self.minor), + MapArea::Ruins1 => format!("data/maps/map_ancient01_0{}_0{}o.dat", self.major, self.minor), + MapArea::Ruins2 => format!("data/maps/map_ancient02_0{}_0{}o.dat", self.major, self.minor), + MapArea::Ruins3 => format!("data/maps/map_ancient03_0{}_0{}o.dat", self.major, self.minor), + MapArea::Dragon => "data/maps/map_boss01o.dat".into(), + MapArea::DeRolLe => "data/maps/map_boss02o.dat".into(), + MapArea::VolOpt => "data/maps/map_boss03o.dat".into(), + MapArea::DarkFalz => "data/maps/map_boss04o.dat".into(), } } @@ -583,21 +607,21 @@ impl Maps { pub fn new(episode: Episode) -> Maps { let map_variants = match episode { Episode::One => { - [MapVariant::new(MapVariantType::Pioneer2Ep1, MapVariantMode::Online), - MapVariant::new(MapVariantType::Forest1, MapVariantMode::Online), - MapVariant::new(MapVariantType::Forest2, MapVariantMode::Online), - MapVariant::new(MapVariantType::Caves1, MapVariantMode::Online), - MapVariant::new(MapVariantType::Caves2, MapVariantMode::Online), - MapVariant::new(MapVariantType::Caves3, MapVariantMode::Online), - MapVariant::new(MapVariantType::Mines1, MapVariantMode::Online), - MapVariant::new(MapVariantType::Mines2, MapVariantMode::Online), - MapVariant::new(MapVariantType::Ruins1, MapVariantMode::Online), - MapVariant::new(MapVariantType::Ruins2, MapVariantMode::Online), - MapVariant::new(MapVariantType::Ruins3, MapVariantMode::Online), - MapVariant::new(MapVariantType::Dragon, MapVariantMode::Online), - MapVariant::new(MapVariantType::DeRolLe, MapVariantMode::Online), - MapVariant::new(MapVariantType::VolOpt, MapVariantMode::Online), - MapVariant::new(MapVariantType::DarkFalz, MapVariantMode::Online), + [MapVariant::new(MapArea::Pioneer2Ep1, MapVariantMode::Online), + MapVariant::new(MapArea::Forest1, MapVariantMode::Online), + MapVariant::new(MapArea::Forest2, MapVariantMode::Online), + MapVariant::new(MapArea::Caves1, MapVariantMode::Online), + MapVariant::new(MapArea::Caves2, MapVariantMode::Online), + MapVariant::new(MapArea::Caves3, MapVariantMode::Online), + MapVariant::new(MapArea::Mines1, MapVariantMode::Online), + MapVariant::new(MapArea::Mines2, MapVariantMode::Online), + MapVariant::new(MapArea::Ruins1, MapVariantMode::Online), + MapVariant::new(MapArea::Ruins2, MapVariantMode::Online), + MapVariant::new(MapArea::Ruins3, MapVariantMode::Online), + MapVariant::new(MapArea::Dragon, MapVariantMode::Online), + MapVariant::new(MapArea::DeRolLe, MapVariantMode::Online), + MapVariant::new(MapArea::VolOpt, MapVariantMode::Online), + MapVariant::new(MapArea::DarkFalz, MapVariantMode::Online), ] }, _ => panic!()