Add callback timers

This commit is contained in:
GreenComfyTea
2023-08-05 10:50:36 +03:00
parent 31b5251c75
commit 30672922c4
4 changed files with 70 additions and 23 deletions

View File

@@ -227,11 +227,9 @@ local function main_loop()
players.update_myself_position();
quest_status.update_is_online();
--quest_status.update_is_quest_host();
time.tick();
time.update_timers();
buffs.update();
--buffs.debug();
if quest_status.flow_state == quest_status.flow_states.IN_TRAINING_AREA then
local large_monster_UI_config = config.current_config.large_monster_UI;
@@ -341,3 +339,9 @@ end);
if imgui.begin_table == nil then
re.msg(language.current_language.customization_menu.reframework_outdated);
end
--------------------------Timers-----------------------------
time.new_timer(buffs.update, 0.5);
time.new_timer(players.update_display_list, 0.5, 0.3);
time.new_timer(time.update_quest_time, 1 / 60, 0.6);
--------------------------Timers-----------------------------

View File

@@ -8,6 +8,8 @@ local consumables;
local melody_effects;
local utils;
local language;
local time;
local quest_status;
local sdk = sdk;
local tostring = tostring;
@@ -110,6 +112,11 @@ function this.init_names()
end
function this.update()
if quest_status.flow_state == quest_status.flow_states.IN_LOBBY
or quest_status.flow_state >= quest_status.flow_states.QUEST_END_ANIMATION then
return;
end
local master_player = find_master_player_method:call(singletons.player_manager);
if master_player == nil then
return;
@@ -167,6 +174,8 @@ function this.init_module()
melody_effects = require("MHR_Overlay.Buffs.melody_effects");
utils = require("MHR_Overlay.Misc.utils");
language = require("MHR_Overlay.Misc.language");
time = require("MHR_Overlay.Game_Handler.time");
quest_status = require("MHR_Overlay.Game_Handler.quest_status");
end
return this;

View File

@@ -335,6 +335,20 @@ function this.merge_damage(first, second)
return first;
end
function this.update_display_list()
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
this.display_list = {};
this.update_player_list(is_on_quest);
non_players.update_servant_list();
non_players.update_otomo_list(is_on_quest, quest_status.is_online);
this.update_dps(false);
this.sort_players();
quest_status.get_cart_count();
end
function this.update_dps(bypass_freeze)
local cached_config = config.current_config.damage_meter_UI.settings;

View File

@@ -7,6 +7,7 @@ local players;
local non_players;
local config;
local small_monster;
local utils;
local sdk = sdk;
local tostring = tostring;
@@ -51,17 +52,51 @@ this.elapsed_seconds = 0;
this.total_elapsed_script_seconds = 0;
this.last_elapsed_script_seconds = 0;
this.list = {};
function this.new_timer(callback, cooldown_seconds, start_offset_seconds)
start_offset_seconds = start_offset_seconds or 0;
if callback == nil or cooldown_seconds == nil then
return;
end
local timer = {};
timer.callback = callback;
timer.cooldown = cooldown_seconds;
timer.last_trigger_time = os.clock() + start_offset_seconds;
table.insert(this.list, timer);
callback();
end
function this.update_timers()
this.update_script_time();
for _, timer in ipairs(this.list) do
if this.total_elapsed_script_seconds - timer.last_trigger_time > timer.cooldown then
timer.last_trigger_time = this.total_elapsed_script_seconds;
timer.callback();
end
end
end
function this.update_script_time()
this.total_elapsed_script_seconds = os.clock();
end
function this.tick()
this.update_script_time();
function this.update_quest_time()
if singletons.quest_manager == nil then
return;
end
if quest_status.flow_state == quest_status.flow_states.IN_LOBBY
or quest_status.flow_state >= quest_status.flow_states.QUEST_END_TIMER then
return;
end
local quest_time_elapsed_minutes = get_quest_elapsed_time_min_method:call(singletons.quest_manager);
if quest_time_elapsed_minutes == nil then
customization_menu.status = "No quest time elapsed minutes";
@@ -77,22 +112,6 @@ function this.tick()
end
this.elapsed_seconds = quest_time_total_elapsed_seconds - quest_time_elapsed_minutes * 60;
if this.total_elapsed_script_seconds - this.last_elapsed_script_seconds > 0.5 then
this.last_elapsed_script_seconds = this.total_elapsed_script_seconds;
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
players.display_list = {};
players.update_player_list(is_on_quest);
non_players.update_servant_list();
non_players.update_otomo_list(is_on_quest, quest_status.is_online);
players.update_dps(false);
players.sort_players();
quest_status.get_cart_count();
end
end
function this.init_module()
@@ -103,6 +122,7 @@ function this.init_module()
small_monster = require("MHR_Overlay.Monsters.small_monster");
quest_status = require("MHR_Overlay.Game_Handler.quest_status");
non_players = require("MHR_Overlay.Damage_Meter.non_players");
utils = require("MHR_Overlay.Misc.utils");
end
return this;