Account for no duration being possible

This commit is contained in:
Lippy13 2021-03-02 23:31:47 +00:00
parent ffd0c01bbd
commit a7c30b6721

View File

@ -94,33 +94,63 @@ fn consumable_desc(maybe_effects: Option<&Vec<Effect>>, desc: &str) -> String {
for effect in effects {
if let Effect::Buff(buff) = effect {
let strength = buff.data.strength * 0.1;
let dur_secs = buff.data.duration.unwrap().as_secs_f32();
let str_total = strength * dur_secs;
let dur_secs = match buff.data.duration {
Some(dur_secs) => dur_secs.as_secs_f32(),
None => 0.0,
};
let str_total = {
if dur_secs > 0.0 {
strength * dur_secs
} else {
strength
}
};
let buff_desc = match buff.kind {
BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => {
format!("Restores {} Health over {} seconds", str_total, dur_secs)
},
BuffKind::Potion { .. } => {
BuffKind::Saturation { .. }
| BuffKind::Regeneration { .. }
| BuffKind::Potion { .. } => {
format!("Restores {} Health", str_total)
},
BuffKind::IncreaseMaxEnergy { .. } => {
format!(
"Raises Maximum Stamina by {} for {} seconds",
strength, dur_secs
)
format!("Raises Maximum Stamina by {}", strength)
},
BuffKind::IncreaseMaxHealth { .. } => {
format!(
"Raises Maximum Health by {} for {} seconds",
strength, dur_secs
)
format!("Raises Maximum Health by {}", strength)
},
_ => String::new(),
};
if !buff_desc.is_empty() {
write!(&mut description, "\n\n{}", buff_desc).unwrap();
if buff_desc.is_empty() {
continue;
}
write!(&mut description, "\n\n{}", buff_desc).unwrap();
// The Potion buff has no real duration
if let BuffKind::Potion { .. } = buff.kind {
continue;
}
let dur_desc = {
if dur_secs > 0.0 {
match buff.kind {
BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => {
format!("over {} seconds", dur_secs)
},
BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth { .. } => {
format!("for {} seconds", dur_secs)
},
_ => String::new(),
}
} else {
"every second".to_string()
}
};
if !dur_desc.is_empty() {
write!(&mut description, " {}", dur_desc).unwrap();
}
}
}