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

@@ -34,7 +34,6 @@ function quest_status.update(args)
large_monster.list = {}; large_monster.list = {};
damage_meter_UI.freeze_displayed_players = false; damage_meter_UI.freeze_displayed_players = false;
damage_meter_UI.last_displayed_players = {}; damage_meter_UI.last_displayed_players = {};
time.last_whole_seconds = 0;
end end
quest_status.index = new_quest_status; quest_status.index = new_quest_status;

View File

@@ -3,6 +3,7 @@ local singletons;
local customization_menu; local customization_menu;
local player; local player;
local config; local config;
local small_monster;
local quest_manager_type_def = sdk.find_type_definition("snow.QuestManager"); local quest_manager_type_def = sdk.find_type_definition("snow.QuestManager");
local get_quest_elapsed_time_min_method = quest_manager_type_def:get_method("getQuestElapsedTimeMin"); local get_quest_elapsed_time_min_method = quest_manager_type_def:get_method("getQuestElapsedTimeMin");
@@ -12,9 +13,16 @@ time.total_elapsed_seconds = 0;
time.elapsed_minutes = 0; time.elapsed_minutes = 0;
time.elapsed_seconds = 0; time.elapsed_seconds = 0;
time.last_whole_seconds = 0; time.total_elapsed_script_seconds = 0;
time.last_whole_script_seconds = 0;
function time.update_script_time()
time.total_elapsed_script_seconds = os.clock();
end
function time.tick() function time.tick()
time.update_script_time();
if singletons.quest_manager == nil then if singletons.quest_manager == nil then
return; return;
end end
@@ -36,9 +44,10 @@ function time.tick()
time.total_elapsed_seconds = quest_time_total_elapsed_seconds; time.total_elapsed_seconds = quest_time_total_elapsed_seconds;
time.elapsed_seconds = quest_time_total_elapsed_seconds - quest_time_elapsed_minutes * 60; time.elapsed_seconds = quest_time_total_elapsed_seconds - quest_time_elapsed_minutes * 60;
if time.total_elapsed_seconds - time.last_whole_seconds > 1 then if time.total_elapsed_script_seconds - time.last_whole_script_seconds > 1 then
time.last_whole_seconds = time.total_elapsed_seconds; time.last_whole_script_seconds = time.total_elapsed_script_seconds;
time.update_players_dps(); time.update_players_dps();
time.update_small_monsters();
end end
end end
@@ -48,20 +57,20 @@ function time.update_players_dps()
local new_total_dps = 0; local new_total_dps = 0;
for _, _player in pairs(player.list) do for _, _player in pairs(player.list) do
if _player.join_time == -1 then if _player.join_time == -1 then
_player.join_time = time.total_elapsed_seconds; _player.join_time = time.total_elapsed_script_seconds;
end end
if cached_config.dps_mode == "Quest Time" then if cached_config.dps_mode == "Quest Time" then
if time.total_elapsed_seconds > 0 then if time.total_elapsed_script_seconds > 0 then
_player.dps = _player.display.total_damage / time.total_elapsed_seconds; _player.dps = _player.display.total_damage / time.total_elapsed_script_seconds;
end end
elseif cached_config.dps_mode == "Join Time" then elseif cached_config.dps_mode == "Join Time" then
if time.total_elapsed_seconds - _player.join_time > 0 then if time.total_elapsed_script_seconds - _player.join_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_seconds - _player.join_time); _player.dps = _player.display.total_damage / (time.total_elapsed_script_seconds - _player.join_time);
end end
elseif cached_config.dps_mode == "First Hit" then elseif cached_config.dps_mode == "First Hit" then
if time.total_elapsed_seconds - _player.first_hit_time > 0 then if time.total_elapsed_script_seconds - _player.first_hit_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_seconds - _player.first_hit_time); _player.dps = _player.display.total_damage / (time.total_elapsed_script_seconds - _player.first_hit_time);
end end
else else
end end
@@ -71,6 +80,21 @@ function time.update_players_dps()
player.total.dps = new_total_dps; player.total.dps = new_total_dps;
end end
local test = true;
function time.update_small_monsters()
for enemy, monster in pairs(small_monster.list) do
small_monster.update(enemy, monster);
if test then
test = false;
for id, ailment in pairs(monster.ailments) do
xy = xy .. "id: " .. tostring(id) ..
" enabled: " .. tostring(ailment.is_enable) .. "\n";
end
end
end
end
function time.init_module() function time.init_module()
player = require("MHR_Overlay.Damage_Meter.player"); player = require("MHR_Overlay.Damage_Meter.player");
@@ -78,6 +102,7 @@ function time.init_module()
customization_menu = require("MHR_Overlay.UI.customization_menu"); customization_menu = require("MHR_Overlay.UI.customization_menu");
time = require("MHR_Overlay.Game_Handler.time"); time = require("MHR_Overlay.Game_Handler.time");
config = require("MHR_Overlay.Misc.config"); config = require("MHR_Overlay.Misc.config");
small_monster = require("MHR_Overlay.Monsters.small_monster");
end end
return time; return time;

View File

@@ -275,98 +275,13 @@ function config.init()
} }
} }
}, },
stamina = {
visibility = false,
offset = {
x = 10,
y = 30
},
text_label = {
visibility = true,
text = "%s",
offset = {
x = 5,
y = 0
},
color = 0xFFA3F5F0,
shadow = {
visibility = true,
offset = {
x = 1,
y = 1
},
color = 0xFF000000
}
},
value_label = {
visibility = true,
text = "%.0f/%.0f", -- current_health/max_health
offset = {
x = 25,
y = 16
},
color = 0xFFA3F5F0,
shadow = {
visibility = true,
offset = {
x = 1,
y = 1
},
color = 0xFF000000
}
},
percentage_label = {
visibility = false,
text = "%5.1f%%",
offset = {
x = 45,
y = 29
},
color = 0xFFA3F5F0,
shadow = {
visibility = true,
offset = {
x = 1,
y = 1
},
color = 0xFF000000
}
},
bar = {
visibility = true,
offset = {
x = 0,
y = 17
},
size = {
width = 90,
height = 4
},
colors = {
foreground = 0xB966CCC5,
background = 0x88000000
}
}
},
ailments = { ailments = {
visibility = false, visibility = false,
offset = { offset = {
x = 10, x = 10,
y = 75 y = 40
}, },
spacing = { spacing = {
@@ -514,7 +429,7 @@ function config.init()
visibility = false, visibility = false,
offset = { offset = {
x = 220, x = 115,
y = 17 y = 17
}, },

View File

@@ -36,7 +36,7 @@ function ailment_buildup.draw_dynamic(monster, ailment_buildups_position_on_scre
goto continue; goto continue;
end 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; goto continue;
end end
@@ -167,7 +167,7 @@ function ailment_buildup.draw_static(monster, ailment_buildups_position_on_scree
goto continue; goto continue;
end 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; goto continue;
end end
@@ -295,7 +295,7 @@ function ailment_buildup.draw_highlighted(monster, ailment_buildups_position_on_
goto continue; goto continue;
end 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; goto continue;
end end
@@ -423,7 +423,7 @@ function ailment_buildup.draw_small(monster, ailment_buildups_position_on_screen
goto continue; goto continue;
end 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; goto continue;
end end

View File

@@ -68,7 +68,7 @@ function ailments.new(_ailments, ailment_id)
_ailments[ailment_id].is_active = false; _ailments[ailment_id].is_active = false;
_ailments[ailment_id].activate_count = 0; _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 if ailment_id == ailments.paralyze_id then
_ailments[ailment_id].name = language.current_language.ailments.paralysis; _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 duration = get_active_time_method:call(ailment_param);
local is_active = get_is_active_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; is_enable = true;
end end
@@ -409,7 +409,7 @@ function ailments.update_ailment(monster, ailment_param, id)
end end
function ailments.update_last_change_time(monster, id) 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 end
-- Code by coavins -- Code by coavins
@@ -456,7 +456,7 @@ function ailments.draw_dynamic(monster, ailments_position_on_screen, opacity_sca
goto continue; goto continue;
end 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; goto continue;
end end
@@ -535,7 +535,7 @@ function ailments.draw_static(monster, ailments_position_on_screen, opacity_scal
goto continue; goto continue;
end 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; goto continue;
end end
@@ -613,7 +613,7 @@ function ailments.draw_highlighted(monster, ailments_position_on_screen, opacity
goto continue; goto continue;
end 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; goto continue;
end end
@@ -690,7 +690,7 @@ function ailments.draw_small(monster, ailments_position_on_screen, opacity_scale
goto continue; goto continue;
end 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; goto continue;
end end

View File

@@ -36,7 +36,7 @@ function body_part.new(id, name)
part.break_count = 0; part.break_count = 0;
part.break_max_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_dynamic_UI(part);
body_part.init_static_UI(part); body_part.init_static_UI(part);
@@ -123,11 +123,11 @@ function body_part.update_flinch(part, part_current, part_max)
end end
if part.health ~= part_current then if part.health ~= part_current then
part.last_change_time = time.total_elapsed_seconds; part.last_change_time = time.total_elapsed_script_seconds;
end end
if part.max_health ~= part_max then 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 end
part.health = part_current; 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) 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 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 end
if part.break_max_health ~= part_break_max then 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 end
if part.break_count ~= part_break_count then 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 end
if part.break_max_count ~= part_break_max_count then 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 end
part.break_health = part_break_current; 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) function body_part.update_loss(part, part_loss_current, part_loss_max, is_severed)
if part.loss_health ~= part_loss_current then 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 end
if part.loss_max_health ~= part_loss_max then 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 end
if part.is_severed ~= is_severed then 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 end
part.loss_health = part_loss_current; part.loss_health = part_loss_current;
@@ -210,7 +210,7 @@ function body_part.draw_dynamic(monster, parts_position_on_screen, opacity_scale
goto continue; goto continue;
end 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; goto continue;
end end
@@ -344,7 +344,7 @@ function body_part.draw_static(monster, parts_position_on_screen, opacity_scale)
goto continue; goto continue;
end 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; goto continue;
end end
@@ -478,7 +478,7 @@ function body_part.draw_highlighted(monster, parts_position_on_screen, opacity_s
goto continue; goto continue;
end 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; goto continue;
end end

View File

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