diff --git a/changelog.txt b/changelog.txt index 9cc5283ca..ce8bfca52 100644 --- a/changelog.txt +++ b/changelog.txt @@ -18,6 +18,7 @@ Engine changes * Fix sol.input.get_mouse_coordinates() (#734). * Fix straight movement precision. * Fix sword tapping sound still played when the game is suspended (#797). +* Fix hero:set_invincible() not working without duration (#805). * Fix custom_entity:set_can_traverse_ground() not working for some grounds (#794). * Fix custom entity collisions not detected for entities that do not move (#671). * Fix creating an entity with the same name as another one just removed (#795). diff --git a/src/entities/Hero.cpp b/src/entities/Hero.cpp index 1118a3cd3..a431c28da 100644 --- a/src/entities/Hero.cpp +++ b/src/entities/Hero.cpp @@ -2011,7 +2011,7 @@ void Hero::set_invincible(bool invincible, uint32_t duration) { this->invincible = invincible; this->end_invincible_date = 0; if (invincible) { - this->end_invincible_date = System::now() + duration; + this->end_invincible_date = (duration == 0) ? 0 : System::now() + duration; } } @@ -2020,8 +2020,9 @@ void Hero::set_invincible(bool invincible, uint32_t duration) { */ void Hero::update_invincibility() { - if (is_invincible() - && System::now() >= end_invincible_date) { + if (is_invincible() && + end_invincible_date != 0 && + System::now() >= end_invincible_date) { set_invincible(false, 0); } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec5d4b4e5..f7f0ed1e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ set(lua_test_maps "bugs/794_custom_entity_set_can_traverse_ground" "bugs/795_recreate_entity_same_name" "bugs/796_map_get_entities_by_type" + "bugs/805_hero_set_invincible" "bugs/807_cannot_traverse_own_ground" ) diff --git a/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.dat b/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.dat new file mode 100644 index 000000000..5d70a3f6e --- /dev/null +++ b/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.dat @@ -0,0 +1,26 @@ +properties{ + x = 0, + y = 0, + width = 320, + height = 240, + min_layer = 0, + max_layer = 2, + tileset = "castle", +} + +tile{ + layer = 0, + x = 0, + y = 0, + width = 320, + height = 240, + pattern = "3", +} + +destination{ + layer = 0, + x = 24, + y = 29, + direction = 1, +} + diff --git a/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.lua b/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.lua new file mode 100644 index 000000000..cc35ccd01 --- /dev/null +++ b/tests/testing_quest/data/maps/bugs/805_hero_set_invincible.lua @@ -0,0 +1,25 @@ +local map = ... + +function map:on_started() + + -- Set invincible with no limit. + hero:set_invincible(true) + assert(hero:is_invincible()) + + sol.timer.start(10, function() + assert(hero:is_invincible()) + + -- Stop invincibility. + hero:set_invincible(false) + assert(not hero:is_invincible()) + + -- Set invincible again, this time with a limit. + hero:set_invincible(true, 10) + assert(hero:is_invincible()) + + sol.timer.start(20, function() + assert(not hero:is_invincible()) + sol.main.exit() + end) + end) +end diff --git a/tests/testing_quest/data/project_db.dat b/tests/testing_quest/data/project_db.dat index 6552b9d40..f0c700775 100644 --- a/tests/testing_quest/data/project_db.dat +++ b/tests/testing_quest/data/project_db.dat @@ -14,6 +14,7 @@ map{ id = "bugs/781_assert_teletransporter_same_map", description = "#781: Asser map{ id = "bugs/794_custom_entity_set_can_traverse_ground", description = "#794: custom_entity:set_can_traverse_ground(\"traversable\", false) does not work" } map{ id = "bugs/795_recreate_entity_same_name", description = "#795: Cannot create an entity with the same name as another one just removed" } map{ id = "bugs/796_map_get_entities_by_type", description = "#796: Add map:get_entities_by_type()" } +map{ id = "bugs/805_hero_set_invincible", description = "#805: hero:set_invincible() not working" } map{ id = "bugs/807_cannot_traverse_own_ground", description = "#807: Entity stuck if cannot traverse its own ground" } map{ id = "dynamic_tile_tests", description = "Dynamic tile tests" } map{ id = "jumper_tests", description = "Jumper tests" }