gui, inventory, symmetrical shadowcasting, bugfixes

This commit is contained in:
Llywelwyn 2023-07-07 07:10:44 +01:00
parent 5b7eac3165
commit 986adb6fce
10 changed files with 355 additions and 71 deletions

68
src/inventory_system.rs Normal file
View file

@ -0,0 +1,68 @@
use super::{gamelog::GameLog, CombatStats, InBackpack, Name, Position, Potion, WantsToDrinkPotion, WantsToPickupItem};
use specs::prelude::*;
pub struct ItemCollectionSystem {}
impl<'a> System<'a> for ItemCollectionSystem {
#[allow(clippy::type_complexity)]
type SystemData = (
ReadExpect<'a, Entity>,
WriteExpect<'a, GameLog>,
WriteStorage<'a, WantsToPickupItem>,
WriteStorage<'a, Position>,
ReadStorage<'a, Name>,
WriteStorage<'a, InBackpack>,
);
fn run(&mut self, data: Self::SystemData) {
let (player_entity, mut gamelog, mut wants_pickup, mut positions, names, mut backpack) = data;
for pickup in wants_pickup.join() {
positions.remove(pickup.item);
backpack.insert(pickup.item, InBackpack { owner: pickup.collected_by }).expect("Unable to pickup item.");
if pickup.collected_by == *player_entity {
gamelog.entries.push(format!("You pick up the {}.", names.get(pickup.item).unwrap().name));
}
}
wants_pickup.clear();
}
}
pub struct PotionUseSystem {}
impl<'a> System<'a> for PotionUseSystem {
#[allow(clippy::type_complexity)]
type SystemData = (
ReadExpect<'a, Entity>,
WriteExpect<'a, GameLog>,
Entities<'a>,
WriteStorage<'a, WantsToDrinkPotion>,
ReadStorage<'a, Name>,
ReadStorage<'a, Potion>,
WriteStorage<'a, CombatStats>,
);
fn run(&mut self, data: Self::SystemData) {
let (player_entity, mut gamelog, entities, mut wants_drink, names, potions, mut combat_stats) = data;
for (entity, drink, stats) in (&entities, &wants_drink, &mut combat_stats).join() {
let potion = potions.get(drink.potion);
match potion {
None => {}
Some(potion) => {
stats.hp = i32::min(stats.max_hp, stats.hp + potion.heal_amount);
if entity == *player_entity {
gamelog.entries.push(format!(
"You quaff the {}, and heal {} hp.",
names.get(drink.potion).unwrap().name,
potion.heal_amount
));
}
entities.delete(drink.potion).expect("Delete failed");
}
}
}
wants_drink.clear();
}
}