Refactoring

This commit is contained in:
GreenComfyTea
2023-08-21 17:29:57 +03:00
parent 1d31a86a3f
commit e67fbf923f
7 changed files with 172 additions and 1020 deletions

View File

@@ -51,6 +51,7 @@ this.list = {
go_fight_win = nil
};
local otomo_moves_type_name = "otomo_moves";
local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager");
local get_player_data_method = player_manager_type_def:get_method("get_PlayerData");
@@ -64,222 +65,9 @@ local kijin_otomo_timer_field = player_data_type_def:get_field("_KijinOtomoTimer
local runhigh_otomo_timer_field = player_data_type_def:get_field("_RunhighOtomoTimer");
function this.update(player_data)
this.update_generic_timer("rousing_roar", player_data, beast_roar_otomo_timer_field);
this.update_generic_timer("power_drum", player_data, kijin_otomo_timer_field);
this.update_generic_timer("go_fight_win", player_data, runhigh_otomo_timer_field);
end
function this.update_generic_timer(otomo_move_key, timer_owner, timer_field, is_infinite)
if is_infinite == nil then is_infinite = false; end
local timer = nil;
if timer_field ~= nil then
timer = timer_field:get_data(timer_owner);
if timer == nil then
error_handler.report("otomo_moves.update_generic_timer", string.format("Failed to access Data: %s_timer", otomo_move_key));
return;
end
if utils.number.is_equal(timer, 0) then
this.list[otomo_move_key] = nil;
return;
end
if is_infinite then
timer = nil;
else
timer = timer / 60;
end
end
this.update_generic(otomo_move_key, 1, timer);
end
function this.update_generic_number_value_field(otomo_move_key, timer_owner, value_field, timer_field, is_infinite, minimal_value)
if minimal_value == nil then minimal_value = 1; end
if is_infinite == nil then is_infinite = false; end
local level = 1;
if value_field ~= nil then
local value = value_field:get_data(timer_owner);
if value == nil then
error_handler.report("otomo_moves.update_generic_number_value_field", string.format("Failed to access Data: %s_value", otomo_move_key));
return;
end
if value < minimal_value then
this.list[otomo_move_key] = nil;
return;
end
end
local timer = nil;
if timer_field ~= nil then
timer = timer_field:get_data(timer_owner);
if timer == nil then
error_handler.report("otomo_moves.update_generic_number_value_field", string.format("Failed to access Data: %s_timer", otomo_move_key));
return;
end
if value_field == nil and utils.number.is_equal(timer, 0) then
this.list[otomo_move_key] = nil;
return;
end
if is_infinite then
timer = nil;
else
timer = timer / 60;
end
end
this.update_generic(otomo_move_key, level, timer);
end
function this.update_generic_boolean_value_field(otomo_move_key, timer_owner, value_field, timer_field, is_infinite, minimal_value)
if minimal_value == nil then minimal_value = true; end
if is_infinite == nil then is_infinite = false; end
if value_field ~= nil then
local value = value_field:get_data(timer_owner);
if value == nil then
error_handler.report("otomo_moves.update_generic_boolean_value_field", string.format("Failed to access Data: %s_value", otomo_move_key));
return;
end
if value < minimal_value then
this.list[otomo_move_key] = nil;
return;
end
end
local timer = nil;
if timer_field ~= nil then
timer = timer_field:get_data(timer_owner);
if timer == nil then
error_handler.report("otomo_moves.update_generic_boolean_value_field", string.format("Failed to access Data: %s_timer", otomo_move_key));
return;
end
if value_field == nil and utils.number.is_equal(timer, 0) then
this.list[otomo_move_key] = nil;
return;
end
if is_infinite then
timer = nil;
else
timer = timer / 60;
end
end
this.update_generic(otomo_move_key, 1, timer);
end
function this.update_generic_number_value_method(otomo_move_key, timer_owner, value_method, timer_field, is_infinite, minimal_value)
if minimal_value == nil then minimal_value = 1; end
if is_infinite == nil then is_infinite = false; end
local level = 1;
if value_method ~= nil then
local value = value_method:call(timer_owner);
if value == nil then
error_handler.report("otomo_moves.update_generic_number_value_method", string.format("Failed to access Data: %s_value", otomo_move_key));
return;
end
if value < minimal_value then
this.list[otomo_move_key] = nil;
return;
end
end
local timer = nil;
if timer_field ~= nil then
timer = timer_field:get_data(timer_owner);
if timer == nil then
error_handler.report("otomo_moves.update_generic_number_value_method", string.format("Failed to access Data: %s_timer", otomo_move_key));
return;
end
if value_method == nil and utils.number.is_equal(timer, 0) then
this.list[otomo_move_key] = nil;
return;
end
if is_infinite then
timer = nil;
else
timer = timer / 60;
end
end
this.update_generic(otomo_move_key, level, timer);
end
function this.update_generic_boolean_value_method(otomo_move_key, timer_owner, value_method, timer_field, is_infinite, minimal_value)
if minimal_value == nil then minimal_value = true; end
if is_infinite == nil then is_infinite = false; end
if value_method ~= nil then
local value = value_method:call(timer_owner);
if value == nil then
error_handler.report("otomo_moves.update_generic_boolean_value_method", string.format("Failed to access Data: %s_value", otomo_move_key));
return;
end
if value ~= minimal_value then
this.list[otomo_move_key] = nil;
return;
end
end
local timer = nil;
if timer_field ~= nil then
timer = timer_field:get_data(timer_owner);
if timer == nil then
error_handler.report("otomo_moves.update_generic_boolean_value_method", string.format("Failed to access Data: %s_timer", otomo_move_key));
return;
end
if value_method == nil and utils.number.is_equal(timer, 0) then
this.list[otomo_move_key] = nil;
return;
end
if is_infinite then
timer = nil;
else
timer = timer / 60;
end
end
this.update_generic(otomo_move_key, 1, timer);
end
function this.update_generic(otomo_move_key, level, timer, duration)
duration = duration or timer;
local otomo_move = this.list[otomo_move_key];
if otomo_move == nil then
local name = language.current_language.otomo_moves[otomo_move_key];
otomo_move = buffs.new(buffs.types.otomo_move, otomo_move_key, name, level, duration);
this.list[otomo_move_key] = otomo_move;
else
otomo_move.level = level;
if timer ~= nil then
buffs.update_timer(otomo_move, timer);
end
end
buffs.update_generic_buff(this.list, otomo_moves_type_name, "rousing_roar", nil, nil, player_data, beast_roar_otomo_timer_field);
buffs.update_generic_buff(this.list, otomo_moves_type_name, "power_drum", nil, nil, player_data, kijin_otomo_timer_field);
buffs.update_generic_buff(this.list, otomo_moves_type_name, "go_fight_win", nil, nil, player_data, runhigh_otomo_timer_field);
end
function this.init_names()