diff --git a/src/map/map.rs b/src/map/map.rs index c8a300bb..8a24560d 100644 --- a/src/map/map.rs +++ b/src/map/map.rs @@ -46,6 +46,7 @@ mod enter; mod equip; mod face; mod forget_skill; +mod get_adjacent_tiles; mod get_character; mod get_dimensions; mod get_item; diff --git a/src/map/map/act_npcs.rs b/src/map/map/act_npcs.rs index 1fbbec8e..beb46bfd 100644 --- a/src/map/map/act_npcs.rs +++ b/src/map/map/act_npcs.rs @@ -349,6 +349,7 @@ impl Map { (0, -1) => Direction::Down, (1, 0) => Direction::Left, (-1, 0) => Direction::Right, + (0, 0) => npc.direction, _ => return None, }; @@ -547,29 +548,6 @@ impl Map { } } } - - fn get_adjacent_tiles(&self, coords: &Coords) -> Vec { - let mut adjacent_tiles = Vec::with_capacity(4); - adjacent_tiles.push(Coords { - x: coords.x, - y: cmp::max(coords.y as i32 - 1, 0) as EOChar, - }); - adjacent_tiles.push(Coords { - x: coords.x, - y: cmp::min(coords.y as i32 + 1, self.file.height as i32) as EOChar, - }); - adjacent_tiles.push(Coords { - x: cmp::max(coords.x as i32 - 1, 0) as EOChar, - y: coords.y, - }); - adjacent_tiles.push(Coords { - x: cmp::min(coords.x as i32 + 1, self.file.width as i32) as EOChar, - y: coords.y, - }); - - adjacent_tiles.dedup(); - adjacent_tiles - } } fn get_damage_amount(npc: &Npc, npc_data: &EnfNpc, character: &Character) -> EOInt { diff --git a/src/map/map/get_adjacent_tiles.rs b/src/map/map/get_adjacent_tiles.rs new file mode 100644 index 00000000..795a860a --- /dev/null +++ b/src/map/map/get_adjacent_tiles.rs @@ -0,0 +1,31 @@ +use std::cmp; + +use eo::{data::EOChar, protocol::Coords}; + +use super::Map; + +impl Map { + pub fn get_adjacent_tiles(&self, coords: &Coords) -> Vec { + let mut adjacent_tiles = Vec::with_capacity(5); + adjacent_tiles.push(*coords); + adjacent_tiles.push(Coords { + x: coords.x, + y: cmp::max(coords.y as i32 - 1, 0) as EOChar, + }); + adjacent_tiles.push(Coords { + x: coords.x, + y: cmp::min(coords.y as i32 + 1, self.file.height as i32) as EOChar, + }); + adjacent_tiles.push(Coords { + x: cmp::max(coords.x as i32 - 1, 0) as EOChar, + y: coords.y, + }); + adjacent_tiles.push(Coords { + x: cmp::min(coords.x as i32 + 1, self.file.width as i32) as EOChar, + y: coords.y, + }); + + adjacent_tiles.dedup(); + adjacent_tiles + } +} diff --git a/src/map/map/timed_warp_suck.rs b/src/map/map/timed_warp_suck.rs index 0423bad7..8a471844 100644 --- a/src/map/map/timed_warp_suck.rs +++ b/src/map/map/timed_warp_suck.rs @@ -1,30 +1,9 @@ -use eo::protocol::Coords; - use super::Map; impl Map { pub fn timed_warp_suck(&mut self) { for character in self.characters.values() { - let coords = [ - character.coords, - Coords { - x: character.coords.x + 1, - y: character.coords.y, - }, - Coords { - x: character.coords.x - 1, - y: character.coords.y, - }, - Coords { - x: character.coords.x, - y: character.coords.y + 1, - }, - Coords { - x: character.coords.x, - y: character.coords.y - 1, - }, - ]; - + let coords = self.get_adjacent_tiles(&character.coords); let warp = match coords .iter() .map(|coords| self.get_warp(coords))