Compare commits
	
		
			4 Commits
		
	
	
		
			master
			...
			andy/add-p
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 178143a3bf | |||
| a6be644ebf | |||
| 226577f91a | |||
| 23a3d1212e | 
| @ -15,6 +15,17 @@ use elseware::entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity}; | ||||
| use elseware::entity::item; | ||||
| 
 | ||||
| fn setup_logger() { | ||||
|     match std::fs::create_dir("log") { | ||||
|         Ok(()) => {}, | ||||
|         Err(e) => { | ||||
|             match e.kind() { | ||||
|                 std::io::ErrorKind::AlreadyExists => {}, // false error
 | ||||
|                 _ => { // real error
 | ||||
|                     panic!("Failed to create \"log\" directory.\n{e:?}"); | ||||
|                 }, | ||||
|             } | ||||
|         }, | ||||
|     }; | ||||
|     let colors = fern::colors::ColoredLevelConfig::new() | ||||
|         .error(fern::colors::Color::Red) | ||||
|         .warn(fern::colors::Color::Yellow) | ||||
|  | ||||
| @ -1029,10 +1029,30 @@ impl Mag { | ||||
|         MAG_STATS.get(&self.mag).map(|stats| { | ||||
|             MAG_FEEDING_TABLES.get(stats.feed_table).map(|feeding_table| { | ||||
|                 feeding_table.get(&tool).map(|feed_stats| { | ||||
|                     self.def = std::cmp::max(std::cmp::max((self.def as i16) + feed_stats.def, 0) as u16, self.def()*100); | ||||
|                     self.pow = std::cmp::max(std::cmp::max((self.pow as i16) + feed_stats.pow, 0) as u16, self.pow()*100); | ||||
|                     self.dex = std::cmp::max(std::cmp::max((self.dex as i16) + feed_stats.dex, 0) as u16, self.dex()*100); | ||||
|                     self.mnd = std::cmp::max(std::cmp::max((self.mnd as i16) + feed_stats.mnd, 0) as u16, self.mind()*100); | ||||
|                     self.def = { | ||||
|                         if (self.def as i16 + feed_stats.def) < ((self.def()*100) as i16) { | ||||
|                             self.def | ||||
|                         } else { | ||||
|                             std::cmp::max(std::cmp::max((self.def as i16) + feed_stats.def, 0) as u16, self.def()*100) | ||||
|                         }}; | ||||
|                     self.pow = { | ||||
|                         if (self.pow as i16 + feed_stats.pow) < ((self.pow()*100) as i16) { | ||||
|                             self.pow | ||||
|                         } else { | ||||
|                             std::cmp::max(std::cmp::max((self.pow as i16) + feed_stats.pow, 0) as u16, self.pow()*100) | ||||
|                         }}; | ||||
|                     self.dex = { | ||||
|                         if (self.dex as i16 + feed_stats.dex) < ((self.dex()*100) as i16) { | ||||
|                             self.dex | ||||
|                         } else { | ||||
|                             std::cmp::max(std::cmp::max((self.dex as i16) + feed_stats.dex, 0) as u16, self.dex()*100) | ||||
|                         }}; | ||||
|                     self.mnd = { | ||||
|                         if (self.mnd as i16 + feed_stats.mnd) < ((self.mind()*100) as i16) { | ||||
|                             self.mnd | ||||
|                         } else { | ||||
|                             std::cmp::max(std::cmp::max((self.mnd as i16) + feed_stats.mnd, 0) as u16, self.mind()*100) | ||||
|                         }}; | ||||
|                     self.iq = std::cmp::min(((self.iq as i16) + feed_stats.iq as i16) as u8, 200); | ||||
|                     self.synchro = std::cmp::min(((self.synchro as i8) + feed_stats.syn) as u8, 120); | ||||
|                 }) | ||||
| @ -1188,7 +1208,7 @@ mod test { | ||||
|         f.read_to_string(&mut s).unwrap(); | ||||
| 
 | ||||
|         let mut feed: HashMap<String, Vec<HashMap<String, MagFeedTable>>> = toml::from_str(&s).unwrap(); | ||||
|         let feed = feed.remove("feedtable".into()).unwrap(); | ||||
|         let feed = feed.remove("feedtable").unwrap(); | ||||
|         let _feed = feed.into_iter() | ||||
|             .map(|table| { | ||||
|                 table.into_iter() | ||||
| @ -1219,7 +1239,7 @@ mod test { | ||||
|         } | ||||
|         assert!(mag == Mag { | ||||
|             mag: MagType::Sato, | ||||
|             def: 507, | ||||
|             def: 509, | ||||
|             pow: 5019, | ||||
|             dex: 4505, | ||||
|             mnd: 0, | ||||
|  | ||||
| @ -217,7 +217,22 @@ impl ServerState for PatchServerState { | ||||
| } | ||||
| 
 | ||||
| fn load_patch_dir(basedir: &str, patchbase: &str, file_ids: &mut HashMap<u32, PatchFile>) -> PatchFileTree { | ||||
|     let paths = fs::read_dir(basedir).expect("could not read directory"); | ||||
|     let paths = { | ||||
|         match fs::read_dir(basedir) { | ||||
|             Ok(p) => p, | ||||
|             Err(e) => { | ||||
|                 match e.kind() { | ||||
|                     std::io::ErrorKind::NotFound => { // attempt to create the missing directory
 | ||||
|                         match std::fs::create_dir(basedir) { | ||||
|                             Ok(_) => fs::read_dir(basedir).expect("could not read newly created directory"), // created patch directory successfully. return it to paths
 | ||||
|                             Err(ee) => panic!("Failed to create directory \"{basedir}\".\n{ee:?}"), // we already know the path doesnt exist so no need to check for AlreadyExists error. panic
 | ||||
|                         } | ||||
|                     }, | ||||
|                     _ => panic!("Unable to read directory \"{basedir}\".\n{e:?}"), | ||||
|                 } | ||||
|             }, | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     let mut files = Vec::new(); | ||||
|     let mut dirs = Vec::new(); | ||||
|  | ||||
| @ -176,7 +176,7 @@ impl BoxDropTable { | ||||
|     fn random_box_drop<R: Rng>(&self, map_area: &MapArea, rng: &mut R) -> Option<ItemDropType> { | ||||
|         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, | ||||
|             let type_weights = WeightedIndex::new([rate.weapon_rate, rate.armor_rate, rate.shield_rate, rate.unit_rate, | ||||
|                                                     rate.tool_rate, rate.meseta_rate, rate.nothing_rate]).unwrap(); | ||||
|             let btype = type_weights.sample(rng); | ||||
|             match btype { | ||||
|  | ||||
| @ -46,7 +46,7 @@ impl GenericArmorTable { | ||||
|     } | ||||
| 
 | ||||
|     fn armor_type<R: Rng>(&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, | ||||
|         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.drop_area_value().unwrap_or(0) as i32); | ||||
| @ -80,7 +80,7 @@ impl GenericArmorTable { | ||||
|     } | ||||
| 
 | ||||
|     pub fn slots<R: Rng>(&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, | ||||
|         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) | ||||
|     } | ||||
|  | ||||
| @ -36,7 +36,7 @@ impl GenericShieldTable { | ||||
|     } | ||||
| 
 | ||||
|     fn shield_type<R: Rng>(&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, | ||||
|         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.drop_area_value().unwrap_or(0) as i32); | ||||
|  | ||||
| @ -240,7 +240,7 @@ impl AttributeTable { | ||||
| 
 | ||||
| 
 | ||||
|     fn generate_attribute<R: Rng>(&self, pattern: &PercentPatternType, rates: &AttributeRate, rng: &mut R) -> Option<WeaponAttribute> { | ||||
|         let attribute_weights = WeightedIndex::new(&[rates.none, rates.native, rates.abeast, rates.machine, rates.dark, rates.hit]).unwrap(); | ||||
|         let attribute_weights = WeightedIndex::new([rates.none, rates.native, rates.abeast, rates.machine, rates.dark, rates.hit]).unwrap(); | ||||
|         let attr = match attribute_weights.sample(rng) { | ||||
|             0 => return None, | ||||
|             1 => Attribute::Native, | ||||
| @ -253,7 +253,7 @@ impl AttributeTable { | ||||
| 
 | ||||
|         let percents = self.percent_rates.get_by_pattern(pattern); | ||||
| 
 | ||||
|         let value_weights = WeightedIndex::new(&percents.as_array()).unwrap(); | ||||
|         let value_weights = WeightedIndex::new(percents.as_array()).unwrap(); | ||||
|         let value = value_weights.sample(rng); | ||||
|         let percent = ((value + 1) * 5) as i8; | ||||
| 
 | ||||
| @ -477,7 +477,7 @@ impl GenericWeaponTable { | ||||
|         let pattern = std::cmp::min(area % ratio.inc, 3); | ||||
| 
 | ||||
|         let weights = self.grind_rates.grind_rate[pattern as usize]; | ||||
|         let grind_choice = WeightedIndex::new(&weights).unwrap(); | ||||
|         let grind_choice = WeightedIndex::new(weights).unwrap(); | ||||
|         grind_choice.sample(rng) | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -226,7 +226,7 @@ pub async fn liberta_kit<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: | ||||
| 
 | ||||
| fn jack_o_lantern() -> Result<Vec<ApplyItemAction>, anyhow::Error> | ||||
| { | ||||
|     let mag_rate = WeightedIndex::new(&[13, 13, 13, 13, 12, 12, 12, 12]).unwrap(); | ||||
|     let mag_rate = WeightedIndex::new([13, 13, 13, 13, 12, 12, 12, 12]).unwrap(); | ||||
|     let mag_type = match mag_rate.sample(&mut rand_chacha::ChaChaRng::from_entropy()) { | ||||
|         0 => ToolType::CellOfMag502, | ||||
|         1 => ToolType::CellOfMag213, | ||||
|  | ||||
| @ -412,7 +412,7 @@ impl<R: Rng + SeedableRng> WeaponShop<R> { | ||||
|             .last() | ||||
|             .unwrap(); | ||||
| 
 | ||||
|         let attr_choice = WeightedIndex::new(&[tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap(); | ||||
|         let attr_choice = WeightedIndex::new([tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap(); | ||||
|         let attr = match attr_choice.sample(&mut self.rng) { | ||||
|             0 => return None, | ||||
|             1 => Attribute::Native, | ||||
| @ -439,7 +439,7 @@ impl<R: Rng + SeedableRng> WeaponShop<R> { | ||||
|             .last() | ||||
|             .unwrap(); | ||||
| 
 | ||||
|         let attr_choice = WeightedIndex::new(&[tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap(); | ||||
|         let attr_choice = WeightedIndex::new([tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap(); | ||||
|         let attr = match attr_choice.sample(&mut self.rng) { | ||||
|             0 => return None, | ||||
|             1 => Attribute::Native, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user