unused potions now are collected in the inventory and can be consumed with the p key
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user