unused potions now are collected in the inventory and can be consumed with the p key

This commit is contained in:
2024-10-21 21:52:07 +02:00
parent a0635de65a
commit 2b8f7eebba
3 changed files with 54 additions and 7 deletions

View File

@@ -54,10 +54,12 @@ impl Artifact for Chest {
}
}
#[derive(Clone, Copy)]
pub struct Potion {
/// a potion that restores some health
position: Position,
health: usize,
was_collected: bool,
}
impl Potion {
@@ -67,6 +69,7 @@ impl Potion {
Self {
position,
health: rand::thread_rng().gen_range(min_health_gain..=max_health_gain),
was_collected: false,
}
}
}
@@ -89,15 +92,20 @@ impl Artifact for Potion {
format!("picked up potion and gained {} health.", new - old).to_string(),
);
self.health = 0;
self.was_collected = true;
} else {
messages.insert(
0,
"not using the potion because you're healthy.".to_string(),
);
messages.insert(0, "move potion to inventory.".to_string());
player.add_to_inventory(self);
self.was_collected = true;
}
}
fn was_collected(&self) -> bool {
self.health == 0
self.was_collected
}
}
impl Potion {
pub fn get_health(&self) -> usize {
self.health
}
}