particle effect on items/traps

This commit is contained in:
Llywelwyn 2023-08-21 20:20:46 +01:00
parent 397aa07d60
commit f325d39f4c
7 changed files with 144 additions and 7 deletions

View file

@ -1,4 +1,5 @@
use crate::{Map, Position};
use crate::{Equipped, InBackpack, Map, Position};
use rltk::prelude::*;
use specs::prelude::*;
pub fn entity_position(ecs: &World, target: Entity) -> Option<usize> {
@ -18,3 +19,27 @@ pub fn aoe_tiles(map: &Map, target: rltk::Point, radius: i32) -> Vec<usize> {
}
result
}
pub fn find_item_position(ecs: &World, target: Entity) -> Option<i32> {
let positions = ecs.read_storage::<Position>();
let map = ecs.fetch::<Map>();
// Does it have a position?
if let Some(pos) = positions.get(target) {
return Some(map.xy_idx(pos.x, pos.y) as i32);
}
// If not, is it carried?
if let Some(carried) = ecs.read_storage::<InBackpack>().get(target) {
if let Some(pos) = positions.get(carried.owner) {
return Some(map.xy_idx(pos.x, pos.y) as i32);
}
}
// Is it equipped?
if let Some(carried) = ecs.read_storage::<Equipped>().get(target) {
if let Some(pos) = positions.get(carried.owner) {
return Some(map.xy_idx(pos.x, pos.y) as i32);
}
}
// Out of luck: give up
console::log("DEBUGINFO: Failed to find item position");
None
}