mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Research GUI (#302)
* Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua * Update research.lua
This commit is contained in:
@@ -1,108 +1,44 @@
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Common = require 'expcore.common' --- @dep utils.event
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local config = require 'config.research' --- @dep config.research
|
||||
local config_bonus = Common.opt_require 'config.bonus' --- @dep config.bonus
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
local config = require 'config.research' --- @dep config.research
|
||||
|
||||
local research = {}
|
||||
Global.register(research, function(tbl)
|
||||
research = tbl
|
||||
end)
|
||||
|
||||
local research_time_format = {hours=true, minutes=true, seconds=true, time=true, string=true}
|
||||
research.res_queue_enable = false
|
||||
local base_rate = 0
|
||||
|
||||
if config.bonus.enabled then
|
||||
for k, _ in pairs(config_bonus.force_bonus) do
|
||||
if config_bonus.force_bonus[k].name == config.bonus.name then
|
||||
base_rate = config_bonus.force_bonus[k].max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function research_notification(event)
|
||||
local is_inf_res = false
|
||||
|
||||
for i=1, #config.inf_res do
|
||||
if (event.research.name == config.inf_res[i].name) and (event.research.level >= config.inf_res[i].level) then
|
||||
is_inf_res = true
|
||||
end
|
||||
end
|
||||
|
||||
if config.bonus_inventory.enabled then
|
||||
if (event.research.force.mining_drill_productivity_bonus * 10) <= (config.bonus_inventory.limit / config.bonus_inventory.rate) then
|
||||
if event.research.force.technologies['toolbelt'].researched then
|
||||
event.research.force[config.bonus_inventory.name] = (math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate) + 10
|
||||
|
||||
else
|
||||
event.research.force[config.bonus_inventory.name] = math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if is_inf_res then
|
||||
if event.research.name == 'mining-productivity-4' and event.research.level > 4 then
|
||||
if config.bonus.enabled then
|
||||
event.research.force[config.bonus.name] = base_rate + event.research.level * config.bonus.rate
|
||||
end
|
||||
|
||||
if config.pollution_ageing_by_research then
|
||||
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
|
||||
end
|
||||
end
|
||||
|
||||
if not (event.by_script) then
|
||||
game.print{'expcom-res.inf', format_time(game.tick, research_time_format), event.research.name, event.research.level - 1}
|
||||
end
|
||||
|
||||
else
|
||||
if not (event.by_script) then
|
||||
game.print{'expcom-res.msg', format_time(game.tick, research_time_format), event.research.name}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function res_queue(event)
|
||||
if event.research.force.rockets_launched == 0 or event.research.force.technologies['mining-productivity-4'].level <= 4 then
|
||||
return
|
||||
end
|
||||
|
||||
local res_q = event.research.research_queue
|
||||
local function res_queue(force, res, by_script)
|
||||
local res_q = force.research_queue
|
||||
|
||||
if #res_q < config.queue_amount then
|
||||
for i=1, config.queue_amount - #res_q do
|
||||
event.research.force.add_research(event.research.force.technologies['mining-productivity-4'])
|
||||
force.add_research(force.technologies['mining-productivity-4'])
|
||||
|
||||
if not (event.by_script) then
|
||||
game.print{'expcom-res.inf-q', event.research.name, event.research.level + i}
|
||||
if not (by_script) then
|
||||
game.print{'expcom-res.inf-q', res.name, res.level + i}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function research_queue_logic(event)
|
||||
research_notification(event)
|
||||
|
||||
if research.res_queue_enable then
|
||||
res_queue(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_research_finished, research_queue_logic)
|
||||
Event.add(defines.events.on_research_cancelled, research_queue_logic)
|
||||
|
||||
Commands.new_command('auto-research', 'Automatically queue up research')
|
||||
:add_alias('ares')
|
||||
:register(function(player)
|
||||
research.res_queue_enable = not research.res_queue_enable
|
||||
|
||||
if research.res_queue_enable then
|
||||
res_queue(player.force)
|
||||
res_queue(player.force, nil, true)
|
||||
end
|
||||
|
||||
game.print{'expcom-res.res', player.name, research.res_queue_enable}
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
if research.res_queue_enable then
|
||||
if event.research.force.rockets_launched > 0 and event.research.force.technologies['mining-productivity-4'].level > 4 then
|
||||
res_queue(event.research.force, {name=event.research.name, level=event.research.level}, event.by_script)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user