Browse Source

andy vs. clippy round 4 and some cleanup

pull/60/head
andy 3 years ago
parent
commit
3faca14883
  1. 7
      src/ship/map/enemy.rs
  2. 24
      src/ship/map/maps.rs
  3. 6
      src/ship/packet/builder/room.rs
  4. 10
      src/ship/packet/handler/room.rs

7
src/ship/map/enemy.rs

@ -324,14 +324,13 @@ impl MapEnemy {
} }
pub fn has_rare_appearance(self) -> bool { pub fn has_rare_appearance(self) -> bool {
match self.monster {
matches!(self.monster,
MonsterType::RagRappy | MonsterType::Hildebear | MonsterType::RagRappy | MonsterType::Hildebear |
MonsterType::PoisonLily | MonsterType::PofuillySlime | MonsterType::PoisonLily | MonsterType::PofuillySlime |
MonsterType::SandRappyCrater | MonsterType::ZuCrater | MonsterType::Dorphon | MonsterType::SandRappyCrater | MonsterType::ZuCrater | MonsterType::Dorphon |
MonsterType::SandRappyDesert | MonsterType::ZuDesert | MonsterType::MerissaA | MonsterType::SandRappyDesert | MonsterType::ZuDesert | MonsterType::MerissaA |
MonsterType::SaintMillion | MonsterType::Shambertin => true,
_ => false
}
MonsterType::SaintMillion | MonsterType::Shambertin
)
} }
/* /*

24
src/ship/map/maps.rs

@ -33,8 +33,7 @@ fn parse_enemy(episode: &Episode, map_area: &MapArea, raw_enemy: RawMapEnemy) ->
enemy enemy
.map_or(vec![None], |monster| { .map_or(vec![None], |monster| {
let mut monsters = Vec::new();
monsters.push(Some(monster));
let mut monsters = vec![Some(monster)];
match monster.monster { match monster.monster {
MonsterType::Monest => { MonsterType::Monest => {
@ -333,9 +332,9 @@ impl Maps {
} }
}) })
.collect(); .collect();
for i in 0..shiny.len() {
for monster in &shiny {
if let Some(j) = rare_monsters.iter().position(|&x| x == 0xFFFF) { 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 { } else {
break break
} }
@ -346,11 +345,18 @@ impl Maps {
pub fn roll_monster_appearance(&mut self, rare_monster_table: &RareMonsterAppearTable) { pub fn roll_monster_appearance(&mut self, rare_monster_table: &RareMonsterAppearTable) {
self.enemy_data = self.enemy_data self.enemy_data = self.enemy_data
.iter() .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(); .collect();
} }
} }

6
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<u16>) -> Result<RareMonsterList, ShipError> {
Ok(RareMonsterList {
pub fn build_rare_monster_list(rare_monster_vec: Vec<u16>) -> RareMonsterList {
RareMonsterList {
ids: rare_monster_vec.try_into().unwrap_or([0xFFFFu16; 16]), ids: rare_monster_vec.try_into().unwrap_or([0xFFFFu16; 16]),
})
}
} }

10
src/ship/packet/handler/room.rs

@ -130,9 +130,15 @@ pub fn done_bursting(id: ClientId,
.flatten() .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 // 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 result = Box::new(result.chain(vec![(id, rare_monster_packet)])); // TODO: make sure we arent clobbering `result` here
} }

Loading…
Cancel
Save