use ::specs::prelude::*; use super::obfuscate_name; use crate::components::{ EquipmentChanged, InBackpack, MagicItem, Name, ObfuscatedName, Position, WantsToDropItem, }; use crate::{colors, gamelog, MasterDungeonMap}; pub struct ItemDropSystem {} impl<'a> System<'a> for ItemDropSystem { #[allow(clippy::type_complexity)] type SystemData = ( ReadExpect<'a, Entity>, Entities<'a>, WriteStorage<'a, WantsToDropItem>, ReadStorage<'a, Name>, WriteStorage<'a, Position>, WriteStorage<'a, InBackpack>, WriteStorage<'a, EquipmentChanged>, ReadStorage<'a, MagicItem>, ReadStorage<'a, ObfuscatedName>, ReadExpect<'a, MasterDungeonMap>, ); fn run(&mut self, data: Self::SystemData) { let ( player_entity, entities, mut wants_drop, names, mut positions, mut backpack, mut dirty, magic_items, obfuscated_names, dm, ) = data; for (entity, to_drop) in (&entities, &wants_drop).join() { let mut dropper_pos: Position = Position { x: 0, y: 0 }; { let dropped_pos = positions.get(entity).unwrap(); dropper_pos.x = dropped_pos.x; dropper_pos.y = dropped_pos.y; } positions .insert( to_drop.item, Position { x: dropper_pos.x, y: dropper_pos.y, }, ) .expect("Unable to drop item to position"); backpack.remove(to_drop.item); dirty .insert(entity, EquipmentChanged {}) .expect("Unable to insert equipment change"); if entity == *player_entity { gamelog::line("You drop the") .append_color( colors::CYAN, obfuscate_name(to_drop.item, &names, &magic_items, &obfuscated_names, &dm), ) .log(); } } wants_drop.clear(); } }