Migrate to os.clock() for time-based functionality

- Fixed is_enable typo for ailments.
- Make small monster updates 1/s.
This commit is contained in:
GreenComfyTea
2022-07-11 08:51:52 +03:00
parent e82612f725
commit d8a6e8c578
7 changed files with 84 additions and 142 deletions

View File

@@ -36,7 +36,7 @@ function ailment_buildup.draw_dynamic(monster, ailment_buildups_position_on_scre
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit then
goto continue;
end
@@ -167,7 +167,7 @@ function ailment_buildup.draw_static(monster, ailment_buildups_position_on_scree
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit then
goto continue;
end
@@ -295,7 +295,7 @@ function ailment_buildup.draw_highlighted(monster, ailment_buildups_position_on_
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit then
goto continue;
end
@@ -423,7 +423,7 @@ function ailment_buildup.draw_small(monster, ailment_buildups_position_on_screen
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit then
goto continue;
end

View File

@@ -68,7 +68,7 @@ function ailments.new(_ailments, ailment_id)
_ailments[ailment_id].is_active = false;
_ailments[ailment_id].activate_count = 0;
_ailments[ailment_id].last_change_time = time.total_elapsed_seconds;
_ailments[ailment_id].last_change_time = time.total_elapsed_script_seconds;
if ailment_id == ailments.paralyze_id then
_ailments[ailment_id].name = language.current_language.ailments.paralysis;
@@ -320,7 +320,7 @@ function ailments.update_ailment(monster, ailment_param, id)
local duration = get_active_time_method:call(ailment_param);
local is_active = get_is_active_method:call(ailment_param);
if is_enable ~= nil then
if is_enable == nil then
is_enable = true;
end
@@ -409,7 +409,7 @@ function ailments.update_ailment(monster, ailment_param, id)
end
function ailments.update_last_change_time(monster, id)
monster.ailments[id].last_change_time = time.total_elapsed_seconds;
monster.ailments[id].last_change_time = time.total_elapsed_script_seconds;
end
-- Code by coavins
@@ -456,7 +456,7 @@ function ailments.draw_dynamic(monster, ailments_position_on_screen, opacity_sca
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -535,7 +535,7 @@ function ailments.draw_static(monster, ailments_position_on_screen, opacity_scal
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -613,7 +613,7 @@ function ailments.draw_highlighted(monster, ailments_position_on_screen, opacity
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
goto continue;
end
@@ -690,7 +690,7 @@ function ailments.draw_small(monster, ailments_position_on_screen, opacity_scale
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - ailment.last_change_time > cached_config.settings.time_limit and not ailment.is_active then
goto continue;
end

View File

@@ -36,7 +36,7 @@ function body_part.new(id, name)
part.break_count = 0;
part.break_max_count = 0;
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
body_part.init_dynamic_UI(part);
body_part.init_static_UI(part);
@@ -123,11 +123,11 @@ function body_part.update_flinch(part, part_current, part_max)
end
if part.health ~= part_current then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.max_health ~= part_max then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
part.health = part_current;
@@ -141,19 +141,19 @@ end
function body_part.update_break(part, part_break_current, part_break_max, part_break_count, part_break_max_count)
if part.break_health ~= part_break_current then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.break_max_health ~= part_break_max then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.break_count ~= part_break_count then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.break_max_count ~= part_break_max_count then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
part.break_health = part_break_current;
@@ -169,15 +169,15 @@ end
function body_part.update_loss(part, part_loss_current, part_loss_max, is_severed)
if part.loss_health ~= part_loss_current then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.loss_max_health ~= part_loss_max then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
if part.is_severed ~= is_severed then
part.last_change_time = time.total_elapsed_seconds;
part.last_change_time = time.total_elapsed_script_seconds;
end
part.loss_health = part_loss_current;
@@ -210,7 +210,7 @@ function body_part.draw_dynamic(monster, parts_position_on_screen, opacity_scale
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - part.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - part.last_change_time > cached_config.settings.time_limit then
goto continue;
end
@@ -344,7 +344,7 @@ function body_part.draw_static(monster, parts_position_on_screen, opacity_scale)
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - part.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - part.last_change_time > cached_config.settings.time_limit then
goto continue;
end
@@ -478,7 +478,7 @@ function body_part.draw_highlighted(monster, parts_position_on_screen, opacity_s
goto continue;
end
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_seconds - part.last_change_time > cached_config.settings.time_limit then
if cached_config.settings.time_limit ~= 0 and time.total_elapsed_script_seconds - part.last_change_time > cached_config.settings.time_limit then
goto continue;
end

View File

@@ -80,25 +80,27 @@ function monster_hook.update_health(enemy_damage_stock_param)
end
function monster_hook.update_stamina(stamina_param, stamina_sub)
if stamina_sub == 0 then
return;
end
local enemy = stamina_param:call("get_Em");
if enemy == nil then
return;
end
local monster = large_monster.get_monster(enemy);
large_monster.update_stamina(enemy, monster, stamina_param);
if stamina_sub > 0 then
large_monster.update_stamina(enemy, monster, stamina_param);
return;
end
-- stamina sub gets called periodically at low rate for large monsters even without damage
large_monster.update(enemy, monster);
large_monster.update_stamina_timer(enemy, monster, stamina_param);
large_monster.update_rage_timer(enemy, monster, nil);
end
function monster_hook.update_stamina_timer(stamina_param, enemy)
local monster = large_monster.get_monster(enemy);
large_monster.update_stamina(enemy, monster, stamina_param);
large_monster.update_stamina_timer(enemy, monster, stamina_param);
end
function monster_hook.update_rage(anger_param, anger_add, enemy)
@@ -116,6 +118,7 @@ function monster_hook.update_rage_timer(anger_param, enemy)
end
function monster_hook.update_monster(enemy)
if enemy == nil then
return;
end
@@ -135,7 +138,7 @@ function monster_hook.update_monster(enemy)
if is_large == nil then
return;
end
if is_large then
monster_hook.update_large_monster(enemy);
else
@@ -146,12 +149,12 @@ end
function monster_hook.update_large_monster(enemy)
local cached_config = config.current_config.large_monster_UI;
local monster = large_monster.get_monster(enemy);
if not cached_config.dynamic.enabled then
return;
end
local monster = large_monster.get_monster(enemy);
-- this is the VERY LEAST thing we should do all the time
-- so the position doesn't lag all over the place
-- due to how infrequently we update the monster(s).
@@ -187,7 +190,7 @@ function monster_hook.update_small_monster(enemy)
num_updated_monsters = num_updated_monsters + 1;
updated_monsters[enemy] = true;
small_monster.update(enemy, monster);
--small_monster.update(enemy, monster);
end
function monster_hook.init_module()
@@ -213,11 +216,11 @@ function monster_hook.init_module()
return retval;
end);
sdk.hook(stamina_update_method, function(args)
pcall(monster_hook.update_stamina, sdk.to_managed_object(args[2]), -1, sdk.to_managed_object(args[3]));
end, function(retval)
return retval;
end);
--sdk.hook(stamina_update_method, function(args)
-- pcall(monster_hook.update_stamina_timer, sdk.to_managed_object(args[2]), -1, sdk.to_managed_object(args[3]));
--end, function(retval)
-- return retval;
--end);
sdk.hook(anger_add_method, function(args)
pcall(monster_hook.update_rage, sdk.to_managed_object(args[2]), sdk.to_float(args[3]), sdk.to_managed_object(args[4]));
@@ -225,11 +228,11 @@ function monster_hook.init_module()
return retval;
end);
sdk.hook(anger_update_method, function(args)
pcall(monster_hook.update_rage_timer, sdk.to_managed_object(args[2]), sdk.to_managed_object(args[3]));
end, function(retval)
return retval;
end);
--sdk.hook(anger_update_method, function(args)
-- pcall(monster_hook.update_rage_timer, sdk.to_managed_object(args[2]), sdk.to_managed_object(args[3]));
--end, function(retval)
-- return retval;
--end);
end