Skip to content

Commit

Permalink
Fix warp suck on edge of map
Browse files Browse the repository at this point in the history
Let npcs attack player on same tile
  • Loading branch information
sorokya committed Nov 11, 2023
1 parent e1c7d44 commit 4f7bd14
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/map/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 1 addition & 23 deletions src/map/map/act_npcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl Map {
(0, -1) => Direction::Down,
(1, 0) => Direction::Left,
(-1, 0) => Direction::Right,
(0, 0) => npc.direction,
_ => return None,
};

Expand Down Expand Up @@ -547,29 +548,6 @@ impl Map {
}
}
}

fn get_adjacent_tiles(&self, coords: &Coords) -> Vec<Coords> {
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 {
Expand Down
31 changes: 31 additions & 0 deletions src/map/map/get_adjacent_tiles.rs
Original file line number Diff line number Diff line change
@@ -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<Coords> {
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
}
}
23 changes: 1 addition & 22 deletions src/map/map/timed_warp_suck.rs
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit 4f7bd14

Please sign in to comment.