inventory finishes

This commit is contained in:
Llywelwyn 2023-07-07 08:37:29 +01:00
parent aadb966fa4
commit f26adf352e
6 changed files with 126 additions and 5 deletions

View file

@ -1,4 +1,7 @@
use super::{gamelog::GameLog, CombatStats, InBackpack, Name, Position, Potion, WantsToDrinkPotion, WantsToPickupItem};
use super::{
gamelog::GameLog, CombatStats, InBackpack, Name, Position, Potion, WantsToDrinkPotion, WantsToDropItem,
WantsToPickupItem,
};
use specs::prelude::*;
pub struct ItemCollectionSystem {}
@ -66,3 +69,41 @@ impl<'a> System<'a> for PotionUseSystem {
wants_drink.clear();
}
}
pub struct ItemDropSystem {}
impl<'a> System<'a> for ItemDropSystem {
#[allow(clippy::type_complexity)]
type SystemData = (
ReadExpect<'a, Entity>,
WriteExpect<'a, GameLog>,
Entities<'a>,
WriteStorage<'a, WantsToDropItem>,
ReadStorage<'a, Name>,
WriteStorage<'a, Position>,
WriteStorage<'a, InBackpack>,
);
fn run(&mut self, data: Self::SystemData) {
let (player_entity, mut gamelog, entities, mut wants_drop, names, mut positions, mut backpack) = 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("Failed to insert position.");
backpack.remove(to_drop.item);
if entity == *player_entity {
gamelog.entries.push(format!("You drop the {}.", names.get(to_drop.item).unwrap().name));
}
}
wants_drop.clear();
}
}