Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Fix hero:set_invincible() not working without duration
Browse files Browse the repository at this point in the history
Closes #805.
  • Loading branch information
christopho committed Dec 21, 2015
1 parent 7a704de commit c2b3ff7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions src/entities/Hero.cpp
Expand Up @@ -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;
}
}

Expand All @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Expand Up @@ -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"
)

Expand Down
26 changes: 26 additions & 0 deletions 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,
}

25 changes: 25 additions & 0 deletions 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
1 change: 1 addition & 0 deletions tests/testing_quest/data/project_db.dat
Expand Up @@ -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" }
Expand Down

0 comments on commit c2b3ff7

Please sign in to comment.