2022-01-20 09:23:13 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
|
2022-01-21 11:18:53 -05:00
|
|
|
use crate::components::{CursedItem, Equipped, InBackpack, Name, WantsToRemoveItem};
|
2022-02-01 10:39:46 -05:00
|
|
|
use crate::{colors, gamelog};
|
2022-01-20 09:23:13 -05:00
|
|
|
|
|
|
|
pub struct ItemRemoveSystem {}
|
|
|
|
|
|
|
|
impl<'a> System<'a> for ItemRemoveSystem {
|
|
|
|
#[allow(clippy::type_complexity)]
|
|
|
|
type SystemData = (
|
|
|
|
Entities<'a>,
|
|
|
|
WriteStorage<'a, WantsToRemoveItem>,
|
|
|
|
WriteStorage<'a, Equipped>,
|
|
|
|
WriteStorage<'a, InBackpack>,
|
2022-01-21 11:18:53 -05:00
|
|
|
ReadStorage<'a, CursedItem>,
|
|
|
|
ReadStorage<'a, Name>,
|
2022-01-20 09:23:13 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
fn run(&mut self, data: Self::SystemData) {
|
2022-02-01 10:39:46 -05:00
|
|
|
let (entities, mut wants_remove, mut equipped, mut backpack, cursed, names) = data;
|
2022-01-20 09:23:13 -05:00
|
|
|
|
|
|
|
for (entity, to_remove) in (&entities, &wants_remove).join() {
|
2022-01-21 11:18:53 -05:00
|
|
|
if cursed.get(to_remove.item).is_some() {
|
2022-02-01 10:39:46 -05:00
|
|
|
gamelog::line("You cannot remove")
|
|
|
|
.append_color(colors::CYAN, &names.get(to_remove.item).unwrap().name)
|
|
|
|
.append_white(" - it is cursed.")
|
|
|
|
.log();
|
2022-01-21 11:18:53 -05:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-20 09:23:13 -05:00
|
|
|
equipped.remove(to_remove.item);
|
|
|
|
backpack
|
|
|
|
.insert(to_remove.item, InBackpack { owner: entity })
|
|
|
|
.expect("Unable to remove item and put in backpack");
|
|
|
|
}
|
|
|
|
|
|
|
|
wants_remove.clear();
|
|
|
|
}
|
|
|
|
}
|