diff --git a/config/_file_loader.lua b/config/_file_loader.lua index d6234811..d87e36d0 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -63,9 +63,9 @@ return { 'modules.addons.afk-kick', 'modules.addons.report-jail', 'modules.addons.protection-jail', - 'modules.addons.deconlog', - 'modules.addons.nukeprotect', - 'modules.addons.inserter', + 'modules.addons.deconlog', + 'modules.addons.nukeprotect', + 'modules.addons.inserter', 'modules.addons.miner', -- Control @@ -78,7 +78,7 @@ return { 'modules.data.quickbar', 'modules.data.alt-view', 'modules.data.tag', - 'modules.data.bonus', + -- 'modules.data.bonus', 'modules.data.personal-logistic', 'modules.data.language', @@ -91,12 +91,13 @@ return { 'modules.gui.task-list', 'modules.gui.player-list', 'modules.gui.server-ups', + 'modules.gui.bonus', 'modules.gui.vlayer', 'modules.gui.research', 'modules.gui.module', 'modules.gui.playerdata', 'modules.gui.surveillance', - 'modules.graftorio.require', -- graftorio + 'modules.graftorio.require', -- graftorio 'modules.gui.toolbar', -- must be loaded last to register toolbar handlers --- Config Files diff --git a/config/bonus.lua b/config/bonus.lua index ecedb25d..f5287143 100644 --- a/config/bonus.lua +++ b/config/bonus.lua @@ -2,222 +2,308 @@ -- @config Bonuses return { - -- level of player bonus for lower roles, 1 level is 10 % - player_bonus_level = 1, + --[[ + TODO + force bonus + vlayer battery recharge (auto) + quick health regeneration + + Base point is equal to the amount of standard value in each parameter. + + CMMS CRS CCS CISB CHB CRDB + STD 30 90 32 20 16 12 + = 200 + + MAX 60 180 64 40 32 24 + = 400 + ]] + pts = { + base = 200 + }, + gui_display_width = { + half = 180, + label = 80, + slider = 200, + count = 80 + }, + conversion = { + ['cmms'] = 'character_mining_speed_modifier', + ['crs'] = 'character_running_speed_modifier', + ['ccs'] = 'character_crafting_speed_modifier', + ['cisb'] = 'character_inventory_slots_bonus', + ['chb'] = 'character_health_bonus', + ['crdb'] = 'character_reach_distance_bonus' + --[[ + ['cpdb'] = 'character_item_pickup_distance_bonus' + ]] + }, player_bonus = { - { - name = 'character_mining_speed_modifier', - enabled = true, - min = 0, - max = 2 + ['character_mining_speed_modifier'] = { + value = 3, + max = 6, + scale = 0.5, + cost_scale = 1, + cost = 10, + is_percentage = true }, - { - name = 'character_running_speed_modifier', - enabled = true, - min = 0, - max = 1.5 + ['character_running_speed_modifier'] = { + value = 1.5, + max = 3, + scale = 0.25, + cost_scale = 1, + cost = 60, + is_percentage = true }, - { - name = 'character_crafting_speed_modifier', - enabled = true, - min = 0, - max = 5 + ['character_crafting_speed_modifier'] = { + value = 8, + max = 16, + scale = 1, + cost_scale = 1, + cost = 4, + is_percentage = true }, - { - name = 'character_reach_distance_bonus', - enabled = true, - min = 0, - max = 10 + ['character_inventory_slots_bonus'] = { + value = 100, + max = 200, + scale = 10, + cost_scale = 10, + cost = 2, + is_percentage = false }, - { - name = 'character_resource_reach_distance_bonus', - enabled = true, - min = 0, - max = 10 + ['character_health_bonus'] = { + value = 200, + max = 400, + scale = 50, + cost_scale = 50, + cost = 4, + is_percentage = false }, - { - name = 'character_build_distance_bonus', - enabled = true, - min = 0, - max = 10 + ['character_reach_distance_bonus'] = { + value = 12, + max = 24, + scale = 2, + cost_scale = 1, + cost = 1, + is_percentage = false, + combined_bonus = { + 'character_resource_reach_distance_bonus', + 'character_build_distance_bonus' + } }, - { - name = 'character_item_pickup_distance_bonus', - enabled = false, - min = 0, - max = 0 + --[[ + ['character_item_pickup_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_loot_pickup_distance_bonus', - enabled = false, - min = 0, - max = 0 + ['character_loot_pickup_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_item_drop_distance_bonus', - enabled = false, - min = 0, - max = 5 - }, - { - name = 'character_inventory_slots_bonus', - enabled = true, - min = 0, - max = 100 - }, - { - name = 'character_health_bonus', - enabled = true, - min = 0, - max = 200 + ['character_item_drop_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false } + ]] }, force_bonus = { - { - name = 'manual_mining_speed_modifier', - enabled = false, - min = 0, - max = 2 + --[[ + ['character_mining_speed_modifier'] = { + value = 0, + max = 6, + scale = 0.5, + cost_scale = 1, + cost = 10, + is_percentage = true }, - { - name = 'character_running_speed_modifier', - enabled = false, - min = 0, - max = 1 + ['character_running_speed_modifier'] = { + value = 0, + max = 3, + scale = 0.25, + cost_scale = 1, + cost = 40, + is_percentage = true }, - { - name = 'character_crafting_speed_modifier', - enabled = false, - min = 0, - max = 5 + ['character_crafting_speed_modifier'] = { + value = 0, + max = 16, + scale = 1, + cost_scale = 1, + cost = 4, + is_percentage = true }, - { - name = 'character_reach_distance_bonus', - enabled = false, - min = 0, - max = 10 + ['character_inventory_slots_bonus'] = { + value = 0, + max = 200, + scale = 10, + cost_scale = 100, + cost = 2, + is_percentage = false }, - { - name = 'character_resource_reach_distance_bonus', - enabled = false, - min = 0, - max = 10 + ['character_health_bonus'] = { + value = 0, + max = 400, + scale = 50, + cost = 4, + is_percentage = false }, - { - name = 'character_build_distance_bonus', - enabled = false, - min = 0, - max = 10 + ['character_reach_distance_bonus'] = { + value = 0, + max = 24, + scale = 2, + cost_scale = 1, + cost = 1, + is_percentage = false, + combined_bonus = { + 'character_resource_reach_distance_bonus', + 'character_build_distance_bonus' + } }, - { - name = 'character_item_pickup_distance_bonus', - enabled = false, - min = 0, - max = 0 + ['worker_robots_speed_modifier'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_loot_pickup_distance_bonus', - enabled = false, - min = 0, - max = 0 + ]] + ['worker_robots_battery_modifier'] = { + value = 1, + max = 1, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_item_drop_distance_bonus', - enabled = false, - min = 0, - max = 5 + ['worker_robots_storage_bonus'] = { + value = 1, + max = 1, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_inventory_slots_bonus', - enabled = false, - min = 0, - max = 100 + ['following_robots_lifetime_modifier'] = { + value = 1, + max = 1, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_health_bonus', - enabled = false, - min = 0, - max = 200 + --[[ + ['character_item_pickup_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'worker_robots_speed_modifier', - enabled = false, - min = 0, - max = 1.3 + ['character_loot_pickup_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'worker_robots_battery_modifier', - enabled = true, - min = 0, - max = 1 + ['character_item_drop_distance_bonus'] = { + value = 0, + max = 20, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'worker_robots_storage_bonus', - enabled = true, - min = 0, - max = 1 + ['character_trash_slot_count'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'following_robots_lifetime_modifier', - enabled = true, - min = 0, - max = 1 + ['mining_drill_productivity_bonus'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'character_trash_slot_count', - enabled = false, - min = 0, - max = 20 + ['train_braking_force_bonus'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'mining_drill_productivity_bonus', - enabled = false, - min = 0, - max = 0 + ['laboratory_speed_modifier'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'train_braking_force_bonus', - enabled = false, - min = 0, - max = 0 + ['laboratory_productivity_bonus'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'laboratory_speed_modifier', - enabled = false, - min = 0, - max = 0 + ['inserter_stack_size_bonus'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'laboratory_productivity_bonus', - enabled = false, - min = 0, - max = 0 + ['stack_inserter_capacity_bonus'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false }, - { - name = 'inserter_stack_size_bonus', - enabled = false, - min = 0, - max = 0 - }, - { - name = 'stack_inserter_capacity_bonus', - enabled = false, - min = 0, - max = 0 - }, - { - name = 'artillery_range_modifier', - enabled = false, - min = 0, - max = 0 + ['artillery_range_modifier'] = { + value = 0, + max = 0, + scale = 0, + cost_scale = 1, + cost = 1, + is_percentage = false } + ]] }, surface_bonus = { - { - name = 'solar_power_multiplier', - enabled = false, - min = 0, - max = 0 + --[[ + ['solar_power_multiplier'] = { + value = 1, + max = 1000, + scale = 1, + cost_scale = 1, + cost = 1, + is_percentage = false } + ]] } -} \ No newline at end of file +} diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 53ff5cf2..cffdb26f 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -54,7 +54,7 @@ Roles.new_role('Administrator','Admin') 'gui/warp-list/bypass-proximity', 'gui/warp-list/bypass-cooldown', 'command/connect-all', - 'command/collectdata' + 'command/collectdata' } Roles.new_role('Moderator','Mod') @@ -75,8 +75,8 @@ Roles.new_role('Moderator','Mod') 'command/clear-reports', 'command/clear-warnings', 'command/clear-inventory', - 'command/bonus', - 'command/bonus/2', + -- 'command/bonus', + 'gui/bonus', 'command/home', 'command/home-set', 'command/home-get', @@ -165,8 +165,8 @@ Roles.new_role('Sponsor','Spon') :allow{ 'gui/rocket-info/toggle-active', 'gui/rocket-info/remote_launch', - 'command/bonus', - 'command/bonus/2', + -- 'command/bonus', + 'gui/bonus', 'command/home', 'command/home-set', 'command/home-get', diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index 28080a17..9a91db69 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -56,7 +56,6 @@ result=__1__ entites were revived and __2__ were healed to max health. [expcom-bonus] set=Your bonus has been set to __1__. perm=You dont have enough permission to set more than __1__. -wip=This command is temporary and will be replaced at some point in the future. [expcom-ratio] notSelecting=Please select an entity with a recipe. diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index e0db10ca..ae45bdd1 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -60,7 +60,7 @@ main-tooltip=Science Info eta-caption=ETA: eta-tooltip=The estimated time left for the current research eta-time=T- __1__ -unit=__1__spm +unit=__1__ spm pos-tooltip=Total made: __1__ neg-tooltip=Total used: __1__ net-tooltip=Total net: __1__ @@ -209,6 +209,47 @@ enabled=enabled disabled=disabled toggle-msg=Fast decon has been __1__ +[bonus] +main-tooltip=Bonus +control-pts-a=Points available +control-pts-n=Points needed +control-pts-r=Points remaining +control-reset=Reset +control-apply=Apply +control-pts-exceed=Points allocated exceeded allowance +display-cmms=Mining +display-cmms-tooltip=Character manual mining speed +display-crs=Running +display-crs-tooltip=Character running speed +display-ccs=Crafting +display-ccs-tooltip=Character crafting speed +display-cisb=Inventory +display-cisb-tooltip=Character inventory slots bonus +display-chb=Health +display-chb-tooltip=Character health bonus +display-crdb=Reach +display-crdb-tooltip=Character reach distance bonus +display-fmms=Mining +display-fmms-tooltip=Force manual mining speed +display-frs=Running +display-frs-tooltip=Force running speed +display-fcs=Crafting +display-fcs-tooltip=Force crafting speed +display-fisb=Inventory +display-fisb-tooltip=Force inventory slots bonus +display-fhb=Health +display-fhb-tooltip=Force health bonus +display-frdb=Reach +display-frdb-tooltip=Force reach distance bonus +display-fwrsm=Robot Speed +display-fwrsm-tooltip=Force worker robots speed modifier +display-fwrbm=Robot Battery +display-fwrbm-tooltip=Force worker robots battery modifier +display-fwrsb=Robot Storage +display-fwrsb-tooltip=Force worker robots storage bonus +display-ffrlm=Robot Lifetime +display-ffrlm-tooltip=Force following robots lifetime modifier + [vlayer] main-tooltip=Vlayer display-item-solar=[img=entity/solar-panel] Solar Panel diff --git a/locale/zh-CN/gui.cfg b/locale/zh-CN/gui.cfg index ea85e9f4..f54ba178 100644 --- a/locale/zh-CN/gui.cfg +++ b/locale/zh-CN/gui.cfg @@ -214,40 +214,40 @@ main-tooltip=Bonus 介面 control-pts-a=可用分數 control-pts-n=必要分數 control-pts-r=餘下分數 -control-refresh=刷新 +control-reset=重置 control-apply=套用 control-pts-exceed=分數超出可用上限 -display-cmms=CMMS +display-cmms=挖掘速度 display-cmms-tooltip=個人挖掘速度 -display-crs=CRS +display-crs=跑步速度 display-crs-tooltip=個人跑步速度 -display-ccs=CCS +display-ccs=合成速度 display-ccs-tooltip=個人合成速度 -display-cisb=CISB +display-cisb=儲存位 display-cisb-tooltip=個人儲存位 -display-chb=CHB +display-chb=生命 display-chb-tooltip=個人生命 -display-crdb=CRDB +display-crdb=到達距離 display-crdb-tooltip=個人到達距離 -display-fmms=FMMS +display-fmms=挖掘速度 display-fmms-tooltip=勢力挖掘速度 -display-frs=FRS +display-frs=跑步速度 display-frs-tooltip=勢力跑步速度 -display-fcs=FCS +display-fcs=合成速度 display-fcs-tooltip=勢力合成速度 -display-fisb=FISB +display-fisb=儲存位 display-fisb-tooltip=勢力儲存位 -display-fhb=FHB +display-fhb=生命 display-fhb-tooltip=勢力生命 -display-frdb=FRDB +display-frdb=到達距離 display-frdb-tooltip=勢力到達距離 -display-fwrsm=FWRSM +display-fwrsm=機械人速度 display-fwrsm-tooltip=勢力機械人速度 -display-fwrbm=FWRBM +display-fwrbm=機械人電力 display-fwrbm-tooltip=勢力機械人電力 -display-fwrsb=FWRSB +display-fwrsb=械人儲存 display-fwrsb-tooltip=勢力機械人儲存 -display-ffrlm=FFRLM +display-ffrlm=機械人生命 display-ffrlm-tooltip=勢力戰鬥機械人生命時間 [vlayer] diff --git a/locale/zh-TW/gui.cfg b/locale/zh-TW/gui.cfg index ea85e9f4..f54ba178 100644 --- a/locale/zh-TW/gui.cfg +++ b/locale/zh-TW/gui.cfg @@ -214,40 +214,40 @@ main-tooltip=Bonus 介面 control-pts-a=可用分數 control-pts-n=必要分數 control-pts-r=餘下分數 -control-refresh=刷新 +control-reset=重置 control-apply=套用 control-pts-exceed=分數超出可用上限 -display-cmms=CMMS +display-cmms=挖掘速度 display-cmms-tooltip=個人挖掘速度 -display-crs=CRS +display-crs=跑步速度 display-crs-tooltip=個人跑步速度 -display-ccs=CCS +display-ccs=合成速度 display-ccs-tooltip=個人合成速度 -display-cisb=CISB +display-cisb=儲存位 display-cisb-tooltip=個人儲存位 -display-chb=CHB +display-chb=生命 display-chb-tooltip=個人生命 -display-crdb=CRDB +display-crdb=到達距離 display-crdb-tooltip=個人到達距離 -display-fmms=FMMS +display-fmms=挖掘速度 display-fmms-tooltip=勢力挖掘速度 -display-frs=FRS +display-frs=跑步速度 display-frs-tooltip=勢力跑步速度 -display-fcs=FCS +display-fcs=合成速度 display-fcs-tooltip=勢力合成速度 -display-fisb=FISB +display-fisb=儲存位 display-fisb-tooltip=勢力儲存位 -display-fhb=FHB +display-fhb=生命 display-fhb-tooltip=勢力生命 -display-frdb=FRDB +display-frdb=到達距離 display-frdb-tooltip=勢力到達距離 -display-fwrsm=FWRSM +display-fwrsm=機械人速度 display-fwrsm-tooltip=勢力機械人速度 -display-fwrbm=FWRBM +display-fwrbm=機械人電力 display-fwrbm-tooltip=勢力機械人電力 -display-fwrsb=FWRSB +display-fwrsb=械人儲存 display-fwrsb-tooltip=勢力機械人儲存 -display-ffrlm=FFRLM +display-ffrlm=機械人生命 display-ffrlm-tooltip=勢力戰鬥機械人生命時間 [vlayer] diff --git a/modules/data/bonus.lua b/modules/data/bonus.lua index c9be9576..4fa42e0e 100644 --- a/modules/data/bonus.lua +++ b/modules/data/bonus.lua @@ -30,12 +30,12 @@ local function apply_bonus(player, stage) return end - for _, v in pairs(config.player_bonus) do - if v.enabled then - if stage == 0 then - player[v.name] = v.min - else - player[v.name] = v.min + (v.max - v.min) * stage / 10 + for k, v in pairs(config.player_bonus) do + player[k] = v.value * stage / 10 + + if v.combined_bonus then + for i=1, #v.combined_bonus, 1 do + player[v.combined_bonus[i]] = v.value * stage / 10 end end end @@ -52,16 +52,9 @@ end) Commands.new_command('bonus', 'Changes the amount of bonus you receive') :add_param('amount', 'integer-range', 0, 10) :register(function(player, amount) - if amount > config.player_bonus_level then - if not Roles.player_allowed(player, 'command/bonus/2') then - Commands.print{'expcom-bonus.perm', 2} - return - end - elseif amount <= config.player_bonus_level then - if not Roles.player_allowed(player, 'command/bonus') then - Commands.print{'expcom-bonus.perm', 1} - return - end + if not Roles.player_allowed(player, 'command/bonus') then + Commands.print{'expcom-bonus.perm', 1} + return end PlayerBonus:set(player, amount) @@ -97,16 +90,12 @@ Event.add(defines.events.on_player_created, function(event) return end - for _, v in pairs(config.force_bonus) do - if v.enabled then - game.players[event.player_index].force[v.name] = game.players[event.player_index].force[v.name] + v.max - end + for k, v in pairs(config.force_bonus) do + game.players[event.player_index].force[k] = v.value end - for _, v in pairs(config.surface_bonus) do - if v.enabled then - game.players[event.player_index].surface[v.name] = game.players[event.player_index].surface[v.name] + v.max - end + for k, v in pairs(config.surface_bonus) do + game.players[event.player_index].surface[k] = v.value end end) diff --git a/modules/gui/bonus.lua b/modules/gui/bonus.lua new file mode 100644 index 00000000..87f11576 --- /dev/null +++ b/modules/gui/bonus.lua @@ -0,0 +1,345 @@ +--[[-- Gui Module - Bonus + @gui Bonus + @alias bonus_container +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local Roles = require 'expcore.roles' --- @dep expcore.roles +local Event = require 'utils.event' --- @dep utils.event +local config = require 'config.bonus' --- @dep config.bonus +local format_number = require('util').format_number --- @dep util +local bonus_container + +local function bonus_gui_pts_needed(player) + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_2'].disp.table + local total = 0 + + for k, v in pairs(config.conversion) do + total = total + (disp['bonus_display_' .. k .. '_slider'].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost) + end + + return total +end + +local function apply_bonus(player) + if not Roles.player_allowed(player, 'gui/bonus') then + for k, v in pairs(config.player_bonus) do + player[k] = 0 + + if v.combined_bonus then + for i=1, #v.combined_bonus do + player[v.combined_bonus[i]] = 0 + end + end + end + + return + end + + if not player.character then + return + end + + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_2'].disp.table + + for k, v in pairs(config.conversion) do + player[v] = disp['bonus_display_' .. k .. '_slider'].slider_value + + if config.player_bonus[v].combined_bonus then + for i=1, #config.player_bonus[v].combined_bonus do + player[config.player_bonus[v].combined_bonus[i]] = 0 + end + end + end +end + +--- Control label for the bonus points available +-- @element bonus_gui_control_pts_a +local bonus_gui_control_pts_a = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_a', + caption = {'bonus.control-pts-a'}, + style = 'heading_1_label' +}:style{ + width = config.gui_display_width['half'] +} + +local bonus_gui_control_pts_a_count = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_a_count', + caption = config.pts.base, + style = 'heading_1_label' +}:style{ + width = config.gui_display_width['half'] +} + +--- Control label for the bonus points needed +-- @element bonus_gui_control_pts_n +local bonus_gui_control_pts_n = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_n', + caption = {'bonus.control-pts-n'}, + style = 'heading_1_label' +}:style{ + width = config.gui_display_width['half'] +} + +local bonus_gui_control_pts_n_count = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_n_count', + caption = '0', + style = 'heading_1_label' +}:style{ + width =config.gui_display_width['half'] +} + +--- Control label for the bonus points remaining +-- @element bonus_gui_control_pts_r +local bonus_gui_control_pts_r = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_r', + caption = {'bonus.control-pts-r'}, + style = 'heading_1_label' +}:style{ + width = config.gui_display_width['half'] +} + +local bonus_gui_control_pts_r_count = +Gui.element{ + type = 'label', + name = 'bonus_control_pts_r_count', + caption = '0', + style = 'heading_1_label' +}:style{ + width = config.gui_display_width['half'] +} + +--- A button used for pts calculations +-- @element bonus_gui_control_refresh +local bonus_gui_control_reset = +Gui.element{ + type = 'button', + name = Gui.unique_static_name, + caption = {'bonus.control-reset'} +}:style{ + width = config.gui_display_width['half'] +}:on_click(function(player, element, _) + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_2'].disp.table + + for k, v in pairs(config.conversion) do + local s = 'bonus_display_' .. k .. '_slider' + disp[s].slider_value = config.player_bonus[v].value + + if config.player_bonus[v].is_percentage then + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. ' %' + + else + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value) + end + end + + local r = bonus_gui_pts_needed(player) + element.parent[bonus_gui_control_pts_n_count.name].caption = r + element.parent[bonus_gui_control_pts_r_count.name].caption = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - r +end) + +--- A button used for pts apply +-- @element bonus_gui_control_apply +local bonus_gui_control_apply = +Gui.element{ + type = 'button', + name = Gui.unique_static_name, + caption = {'bonus.control-apply'} +}:style{ + width = config.gui_display_width['half'] +}:on_click(function(player, element, _) + local n = bonus_gui_pts_needed(player) + element.parent[bonus_gui_control_pts_n_count.name].caption = n + local r = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - n + element.parent[bonus_gui_control_pts_r_count.name].caption = r + + if r >= 0 then + apply_bonus(player) + end +end) + +--- A vertical flow containing all the bonus control +-- @element bonus_control_set +local bonus_control_set = +Gui.element(function(_, parent, name) + local bonus_set = parent.add{type='flow', direction='vertical', name=name} + local disp = Gui.scroll_table(bonus_set, 360, 2, 'disp') + + bonus_gui_control_pts_a(disp) + bonus_gui_control_pts_a_count(disp) + + bonus_gui_control_pts_n(disp) + bonus_gui_control_pts_n_count(disp) + + bonus_gui_control_pts_r(disp) + bonus_gui_control_pts_r_count(disp) + + bonus_gui_control_reset(disp) + bonus_gui_control_apply(disp) + + return bonus_set +end) + +--- Display group +-- @element bonus_gui_slider +local bonus_gui_slider = +Gui.element(function(_definition, parent, name, caption, tooltip, bonus) + local label = parent.add{ + type = 'label', + caption = caption, + tooltip = tooltip, + style = 'heading_1_label' + } + label.style.width = config.gui_display_width['label'] + + local value = bonus.value + + if bonus.is_percentage then + value = format_number(value * 100) .. ' %' + + else + value = format_number(value) + end + + local slider = parent.add{ + type = 'slider', + name = name .. '_slider', + value = bonus.value, + maximum_value = bonus.max, + value_step = bonus.scale, + discrete_values = true, + style = 'notched_slider', + tags = { + counter = name .. '_count', + is_percentage = bonus.is_percentage + } + } + slider.style.width = config.gui_display_width['slider'] + slider.style.horizontally_stretchable = true + + local count = parent.add{ + type = 'label', + name = name .. '_count', + caption = value, + style = 'heading_1_label', + } + count.style.width = config.gui_display_width['count'] + + return slider +end) +:on_value_changed(function(player, element, _event) + if element.tags.is_percentage then + element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. ' %' + + else + element.parent[element.tags.counter].caption = format_number(element.slider_value) + end + + local r = bonus_gui_pts_needed(player) + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_1'].disp.table + disp[bonus_gui_control_pts_n_count.name].caption = r + disp[bonus_gui_control_pts_r_count.name].caption = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - r +end) + +--- A vertical flow containing all the bonus data +-- @element bonus_data_set +local bonus_data_set = +Gui.element(function(_, parent, name) + local bonus_set = parent.add{type='flow', direction='vertical', name=name} + local disp = Gui.scroll_table(bonus_set, 360, 3, 'disp') + + for k, v in pairs(config.conversion) do + bonus_gui_slider(disp, 'bonus_display_' .. k, {'bonus.display-' .. k}, {'bonus.display-' .. k .. '-tooltip'}, config.player_bonus[v]) + end + + return bonus_set +end) + +--- The main container for the bonus gui +-- @element bonus_container +bonus_container = +Gui.element(function(definition, parent) + local player = Gui.get_player_from_element(parent) + local container = Gui.container(parent, definition.name, 320) + + bonus_control_set(container, 'bonus_st_1') + bonus_data_set(container, 'bonus_st_2') + + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_1'].disp.table + local n = bonus_gui_pts_needed(player) + disp[bonus_gui_control_pts_n_count.name].caption = n + local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n + disp[bonus_gui_control_pts_r_count.name].caption = r + + apply_bonus(player) + return container.parent +end) +:static_name(Gui.unique_static_name) +:add_to_left_flow() + +--- Button on the top flow used to toggle the task list container +-- @element toggle_left_element +Gui.left_toolbar_button('item/exoskeleton-equipment', {'bonus.main-tooltip'}, bonus_container, function(player) + return Roles.player_allowed(player, 'gui/bonus') +end) + +Event.add(defines.events.on_player_created, function(event) + if event.player_index ~= 1 then + return + end + + for k, v in pairs(config.force_bonus) do + game.players[event.player_index].force[k] = v.value + end + + for k, v in pairs(config.surface_bonus) do + game.players[event.player_index].surface[k] = v.value + end +end) + +Event.add(Roles.events.on_role_assigned, function(event) + apply_bonus(game.players[event.player_index]) +end) + +Event.add(Roles.events.on_role_unassigned, function(event) + apply_bonus(game.players[event.player_index]) +end) + +--- When a player respawns re-apply bonus +Event.add(defines.events.on_player_respawned, function(event) + local player = game.players[event.player_index] + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container['bonus_st_1'].disp.table + local n = bonus_gui_pts_needed(player) + disp[bonus_gui_control_pts_n_count.name].caption = n + local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n + disp[bonus_gui_control_pts_r_count.name].caption = r + + if r >= 0 then + apply_bonus(player) + end +end) + +--- When a player dies allow them to have instant respawn +Event.add(defines.events.on_player_died, function(event) + local player = game.players[event.player_index] + + if Roles.player_has_flag(player, 'instant-respawn') then + player.ticks_to_respawn = 120 + end +end)