2022-02-02 11:52:19 -05:00
|
|
|
use ::rltk::prelude::*;
|
2022-02-02 09:45:19 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
2022-02-02 09:45:19 -05:00
|
|
|
use crate::components::{CursedItem, Equipped, InBackpack, Item, Name};
|
|
|
|
use crate::{MasterDungeonMap, State};
|
|
|
|
|
|
|
|
pub fn remove_curse_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
|
|
|
let player_entity = gs.ecs.fetch::<Entity>();
|
|
|
|
let equipped = gs.ecs.read_storage::<Equipped>();
|
|
|
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
|
|
|
let entities = gs.ecs.entities();
|
2022-02-02 11:52:19 -05:00
|
|
|
let item_components = gs.ecs.read_storage::<Item>();
|
2022-02-02 09:45:19 -05:00
|
|
|
let cursed = gs.ecs.read_storage::<CursedItem>();
|
|
|
|
let names = gs.ecs.read_storage::<Name>();
|
|
|
|
let dm = gs.ecs.fetch::<MasterDungeonMap>();
|
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
let mut draw_batch = DrawBatch::new();
|
|
|
|
|
|
|
|
let mut items = Vec::new();
|
|
|
|
|
|
|
|
(&entities, &item_components, &cursed)
|
|
|
|
.join()
|
|
|
|
.filter(|(item_entity, _item, _cursed)| {
|
|
|
|
let mut keep = false;
|
|
|
|
if let Some(bp) = backpack.get(*item_entity) {
|
|
|
|
if bp.owner == *player_entity {
|
|
|
|
if let Some(name) = names.get(*item_entity) {
|
|
|
|
if dm.identified_items.contains(&name.name) {
|
|
|
|
keep = true;
|
2022-02-02 09:45:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-02 11:52:19 -05:00
|
|
|
}
|
|
|
|
// It's equipped, so we know it's cursed
|
|
|
|
if let Some(equip) = equipped.get(*item_entity) {
|
|
|
|
if equip.owner == *player_entity {
|
|
|
|
keep = true;
|
2022-02-02 09:45:19 -05:00
|
|
|
}
|
2022-02-02 11:52:19 -05:00
|
|
|
}
|
|
|
|
keep
|
|
|
|
})
|
|
|
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
2022-02-02 09:45:19 -05:00
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
let result = item_result_menu(
|
|
|
|
&mut draw_batch,
|
2022-02-02 09:45:19 -05:00
|
|
|
"Remove Curse From Which Item?",
|
2022-02-02 11:52:19 -05:00
|
|
|
items.len(),
|
|
|
|
&items,
|
|
|
|
ctx.key,
|
2022-02-02 09:45:19 -05:00
|
|
|
);
|
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
draw_batch
|
|
|
|
.submit(6000)
|
|
|
|
.expect("Failed to batch render Remove Curse Menu");
|
2022-02-02 09:45:19 -05:00
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
result
|
2022-02-02 09:45:19 -05:00
|
|
|
}
|