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 = {};
damage_meter_UI.freeze_displayed_players = false;
damage_meter_UI.last_displayed_players = {};
time.last_whole_seconds = 0;
end
quest_status.index = new_quest_status;

View File

@@ -3,6 +3,7 @@ local singletons;
local customization_menu;
local player;
local config;
local small_monster;
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");
@@ -12,9 +13,16 @@ time.total_elapsed_seconds = 0;
time.elapsed_minutes = 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()
time.update_script_time();
if singletons.quest_manager == nil then
return;
end
@@ -36,9 +44,10 @@ function time.tick()
time.total_elapsed_seconds = quest_time_total_elapsed_seconds;
time.elapsed_seconds = quest_time_total_elapsed_seconds - quest_time_elapsed_minutes * 60;
if time.total_elapsed_seconds - time.last_whole_seconds > 1 then
time.last_whole_seconds = time.total_elapsed_seconds;
if time.total_elapsed_script_seconds - time.last_whole_script_seconds > 1 then
time.last_whole_script_seconds = time.total_elapsed_script_seconds;
time.update_players_dps();
time.update_small_monsters();
end
end
@@ -48,20 +57,20 @@ function time.update_players_dps()
local new_total_dps = 0;
for _, _player in pairs(player.list) do
if _player.join_time == -1 then
_player.join_time = time.total_elapsed_seconds;
_player.join_time = time.total_elapsed_script_seconds;
end
if cached_config.dps_mode == "Quest Time" then
if time.total_elapsed_seconds > 0 then
_player.dps = _player.display.total_damage / time.total_elapsed_seconds;
if time.total_elapsed_script_seconds > 0 then
_player.dps = _player.display.total_damage / time.total_elapsed_script_seconds;
end
elseif cached_config.dps_mode == "Join Time" then
if time.total_elapsed_seconds - _player.join_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_seconds - _player.join_time);
if time.total_elapsed_script_seconds - _player.join_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_script_seconds - _player.join_time);
end
elseif cached_config.dps_mode == "First Hit" then
if time.total_elapsed_seconds - _player.first_hit_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_seconds - _player.first_hit_time);
if time.total_elapsed_script_seconds - _player.first_hit_time > 0 then
_player.dps = _player.display.total_damage / (time.total_elapsed_script_seconds - _player.first_hit_time);
end
else
end
@@ -71,6 +80,21 @@ function time.update_players_dps()
player.total.dps = new_total_dps;
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()
player = require("MHR_Overlay.Damage_Meter.player");
@@ -78,6 +102,7 @@ function time.init_module()
customization_menu = require("MHR_Overlay.UI.customization_menu");
time = require("MHR_Overlay.Game_Handler.time");
config = require("MHR_Overlay.Misc.config");
small_monster = require("MHR_Overlay.Monsters.small_monster");
end
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 = {
visibility = false,
offset = {
x = 10,
y = 75
y = 40
},
spacing = {
@@ -514,7 +429,7 @@ function config.init()
visibility = false,
offset = {
x = 220,
x = 115,
y = 17
},

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