- added basic tests for cell, direction, entity, action
- fixed bugs
This commit is contained in:
2024-05-24 16:35:25 +02:00
parent 012d6322e3
commit 6030ba0b73
3 changed files with 299 additions and 4 deletions

View File

@@ -147,6 +147,11 @@ pub struct TurnBasedDamage {
time: u8,
damage: i32,
}
impl TurnBasedDamage {
pub fn new(time: u8, damage: i32) -> Self {
Self { time, damage }
}
}
#[typetag::serde]
impl Effect for TurnBasedDamage {
fn is_persistent(&self) -> bool {
@@ -155,10 +160,12 @@ impl Effect for TurnBasedDamage {
fn apply_to(&self, entity: &mut Entity, _floor: &mut Floor) {
if self.time > 0 {
entity.apply_damage(self.damage);
entity.add_effect(Box::new(Self {
time: self.time - 1,
damage: self.damage,
}));
if self.time > 1 {
entity.add_effect(Box::new(Self {
time: self.time - 1,
damage: self.damage,
}));
}
}
}
}

View File

@@ -127,6 +127,13 @@ impl Entity {
self.effects.push_back(effect);
}
/// Permette di vedere tutti gli effetti che in questo momento sono applicati all'entità.\
/// Gli effetti qui elencati sono in uno stato di attesa prima di essere effettivamente
/// applicati tremite la funzione update.
pub fn get_effects(& self) -> impl Iterator<Item = &Box<dyn Effect>> {
self.effects.iter()
}
/// Indica se l'entità è considerata ancora in gioco o meno.\
/// Per far si che l'entità non sia più in gioco bisobna far arrivare la vita a 0.
/// Nota: una entità con vita negativa è considerata "viva"