mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gzNew health fix so i dont die
src/character/character.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/character/character.cpp b/src/character/character.cpp index 76da0a5..524279e 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -708,8 +708,41 @@ Character::add_ToStatsBonus(InventoryObjectType object_type, void Character::reduce_StatsBonus() { - for (auto it = stats_bonus.begin(); it != stats_bonus.end(); ) { + for (auto it = stats_bonus.begin(); it != stats_bonus.end(); ) + { + float total_duration = it->stats.duration; + if (total_duration <= 0.0f) + { + it = stats_bonus.erase(it); + continue; + } + + float previous_ratio = it->duration / total_duration; + it->duration -= Default::delta_time; + if (it->duration < 0.0f) + it->duration = 0.0f; + + float new_ratio = it->duration / total_duration; + + float scale = (previous_ratio > 0.0f) + ? (new_ratio / previous_ratio) + : 0.0f; + + float oh = it->stats.health; + float os = it->stats.stamina; + it->stats.health *= scale; + it->stats.stamina *= scale; + it->stats.thirst *= scale; + it->stats.demage *= scale; + + stats.health_reduced -= (oh - it->stats.health); + if (stats.health_reduced <= 0.0f) + stats.health_reduced = 0.0f; + + stats.stamina_reduced -= (os - it->stats.stamina); + if (stats.stamina_reduced <= 0.0f) + stats.stamina_reduced = 0.0f; if (it->duration <= 0.0f) it = stats_bonus.erase(it);