diff --git a/src/ship/map/enemy.rs b/src/ship/map/enemy.rs index 2555024..6aed225 100644 --- a/src/ship/map/enemy.rs +++ b/src/ship/map/enemy.rs @@ -324,14 +324,13 @@ impl MapEnemy { } pub fn has_rare_appearance(self) -> bool { - match self.monster { + matches!(self.monster, MonsterType::RagRappy | MonsterType::Hildebear | MonsterType::PoisonLily | MonsterType::PofuillySlime | MonsterType::SandRappyCrater | MonsterType::ZuCrater | MonsterType::Dorphon | MonsterType::SandRappyDesert | MonsterType::ZuDesert | MonsterType::MerissaA | - MonsterType::SaintMillion | MonsterType::Shambertin => true, - _ => false - } + MonsterType::SaintMillion | MonsterType::Shambertin + ) } /* diff --git a/src/ship/map/maps.rs b/src/ship/map/maps.rs index 8c11d21..1f85124 100644 --- a/src/ship/map/maps.rs +++ b/src/ship/map/maps.rs @@ -33,8 +33,7 @@ fn parse_enemy(episode: &Episode, map_area: &MapArea, raw_enemy: RawMapEnemy) -> enemy .map_or(vec![None], |monster| { - let mut monsters = Vec::new(); - monsters.push(Some(monster)); + let mut monsters = vec![Some(monster)]; match monster.monster { MonsterType::Monest => { @@ -333,9 +332,9 @@ impl Maps { } }) .collect(); - for i in 0..shiny.len() { + for monster in &shiny { if let Some(j) = rare_monsters.iter().position(|&x| x == 0xFFFF) { - rare_monsters[j] = shiny[i].0 as u16; + rare_monsters[j] = monster.0 as u16; } else { break } @@ -346,11 +345,18 @@ impl Maps { pub fn roll_monster_appearance(&mut self, rare_monster_table: &RareMonsterAppearTable) { self.enemy_data = self.enemy_data .iter() - .map(|&x| if x.is_some() && x.unwrap().has_rare_appearance() { - Some(x.unwrap().roll_appearance_for_mission(&rare_monster_table)) - } else { - x - }) + // .map(|&x| if x.is_some() && x.unwrap().has_rare_appearance() { + .map(|&x| + if let Some(monster) = x { + if monster.has_rare_appearance() { + Some(monster.roll_appearance_for_mission(rare_monster_table)) + } else { + Some(monster) + } + } else { + x + } + ) .collect(); } } diff --git a/src/ship/packet/builder/room.rs b/src/ship/packet/builder/room.rs index 3fe196a..c5bd11c 100644 --- a/src/ship/packet/builder/room.rs +++ b/src/ship/packet/builder/room.rs @@ -72,8 +72,8 @@ pub fn add_to_room(_id: ClientId, }) } -pub fn build_rare_monster_list(rare_monster_vec: Vec) -> Result { - Ok(RareMonsterList { +pub fn build_rare_monster_list(rare_monster_vec: Vec) -> RareMonsterList { + RareMonsterList { ids: rare_monster_vec.try_into().unwrap_or([0xFFFFu16; 16]), - }) + } } \ No newline at end of file diff --git a/src/ship/packet/handler/room.rs b/src/ship/packet/handler/room.rs index 8c2ba8c..854d24f 100644 --- a/src/ship/packet/handler/room.rs +++ b/src/ship/packet/handler/room.rs @@ -130,9 +130,15 @@ pub fn done_bursting(id: ClientId, .flatten() ); + // // TODO: check how often `done_bursting` is called. ie: make sure it's only used when joining a room and not each time a player warps in a pipe + // if rare_monster_list.is_some() { + // let rare_monster_packet = SendShipPacket::RareMonsterList(builder::room::build_rare_monster_list(rare_monster_list.unwrap()).unwrap()); // TODO: don't double unwrap + // result = Box::new(result.chain(vec![(id, rare_monster_packet)])); // TODO: make sure we arent clobbering `result` here + // } + // TODO: check how often `done_bursting` is called. ie: make sure it's only used when joining a room and not each time a player warps in a pipe - if rare_monster_list.is_some() { - let rare_monster_packet = SendShipPacket::RareMonsterList(builder::room::build_rare_monster_list(rare_monster_list.unwrap()).unwrap()); // TODO: don't double unwrap + if let Some(rare_list) = rare_monster_list { + let rare_monster_packet = SendShipPacket::RareMonsterList(builder::room::build_rare_monster_list(rare_list)); result = Box::new(result.chain(vec![(id, rare_monster_packet)])); // TODO: make sure we arent clobbering `result` here }