From dab23f969a1e86f026b163a54909982e59c06f85 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 25 May 2021 22:19:20 +0200 Subject: [PATCH] refactor --- comfy_panel/admin.lua | 2 +- comfy_panel/bottom_frame.lua | 120 +++--- comfy_panel/config.lua | 93 +++- comfy_panel/main.lua | 1 + comfy_panel/poll.lua | 1 + commands/misc.lua | 29 +- maps/dungeons/boss_arena.lua | 18 +- maps/dungeons/functions.lua | 2 +- maps/dungeons/tiered_dungeon.lua | 20 +- .../biters_yield_coins.lua | 4 +- maps/mountain_fortress_v3/breached_wall.lua | 23 +- maps/mountain_fortress_v3/entities.lua | 15 +- maps/mountain_fortress_v3/gui.lua | 14 +- maps/mountain_fortress_v3/ic/functions.lua | 9 + maps/mountain_fortress_v3/ic/gui.lua | 138 ++++-- maps/mountain_fortress_v3/ic/table.lua | 1 + maps/mountain_fortress_v3/locomotive.lua | 11 +- maps/mountain_fortress_v3/main.lua | 42 +- maps/mountain_fortress_v3/mining.lua | 4 +- modules/autostash.lua | 3 - modules/biter_health_booster_v2.lua | 4 - modules/difficulty_vote_by_amount.lua | 1 + modules/floaty_chat.lua | 3 - modules/rpg.lua | 1 - modules/rpg/commands.lua | 30 +- modules/rpg/core.lua | 18 + modules/rpg/explosive_gun_bullets.lua | 11 +- modules/rpg/functions.lua | 398 +++++++++--------- modules/rpg/gui.lua | 203 +++++---- modules/rpg/main.lua | 201 ++++----- modules/rpg/settings.lua | 138 +++--- modules/rpg/spells.lua | 2 +- modules/rpg/table.lua | 32 ++ modules/show_inventory.lua | 15 + modules/wave_defense/main.lua | 12 +- player_modifiers.lua | 83 ++-- 36 files changed, 960 insertions(+), 742 deletions(-) create mode 100644 modules/rpg/core.lua diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index 52f58fee..c7f8f018 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -22,7 +22,7 @@ local function jail(player, source_player) if player.name == source_player.name then return player.print("You can't select yourself!", {r = 1, g = 0.5, b = 0.1}) end - Jailed.try_ul_data(player.name, true, source_player.name) + Jailed.try_ul_data(player.name, true, source_player.name, 'Jailed by script!') end local function free(player, source_player) diff --git a/comfy_panel/bottom_frame.lua b/comfy_panel/bottom_frame.lua index a518f688..576685a5 100644 --- a/comfy_panel/bottom_frame.lua +++ b/comfy_panel/bottom_frame.lua @@ -7,7 +7,6 @@ local Gui = require 'utils.gui' local this = { players = {}, activate_custom_buttons = false, - bottom_right = false, bottom_quickbar_button = {} } @@ -56,13 +55,20 @@ function Public.set(key, value) end end +function Public.clear_data(player) + this.players[player.index] = nil + this.bottom_quickbar_button[player.index] = nil +end + function Public.reset() local players = game.players for i = 1, #players do local player = players[i] - if not player.connected then - this.players[player.index] = nil - this.bottom_quickbar_button[player.index] = nil + if player and player.valid then + if not player.connected then + this.players[player.index] = nil + this.bottom_quickbar_button[player.index] = nil + end end end end @@ -75,34 +81,41 @@ local function destroy_frame(player) if frame and frame.valid then frame.destroy() end - this.bottom_quickbar_button[player.index] = nil end -local function create_frame(player, rebuild) +local function create_frame(player, alignment, location, portable) local gui = player.gui local frame = gui.screen[bottom_guis_frame] if frame and frame.valid then - if rebuild then - frame.destroy() - else - return frame - end + destroy_frame(player) end + alignment = alignment or 'vertical' + frame = player.gui.screen.add { type = 'frame', name = bottom_guis_frame, - direction = 'vertical' + direction = alignment } + frame.style.padding = 3 - frame.style.minimal_height = 96 frame.style.top_padding = 4 + if alignment == 'vertical' then + frame.style.minimal_height = 96 + end + + frame.location = location + if portable then + frame.caption = '•' + end + global.frame = frame + local inner_frame = frame.add { type = 'frame', - direction = 'vertical' + direction = alignment } inner_frame.style = 'quick_bar_inner_panel' @@ -131,30 +144,51 @@ local function create_frame(player, rebuild) return frame end -local function set_location(player) - local frame = create_frame(player) +local function set_location(player, state) + local data = Public.get_player_data(player) + local alignment = 'vertical' + + local location local resolution = player.display_resolution local scale = player.display_scale - if this.players[player.index] and this.players[player.index].bottom_left then - frame.location = { - x = (resolution.width / 2) - ((54 + 445) * scale), - y = (resolution.height - (96 * scale)) - } - return - end - - if this.bottom_right then - frame.location = { + if state == 'bottom_left' then + if data.above then + location = { + x = (resolution.width / 2) - ((259) * scale), + y = (resolution.height - (150 * scale)) + } + alignment = 'horizontal' + else + location = { + x = (resolution.width / 2) - ((54 + 444) * scale), + y = (resolution.height - (96 * scale)) + } + end + data.bottom_state = 'bottom_left' + elseif state == 'bottom_right' then + if data.above then + location = { + x = (resolution.width / 2) - ((-376) * scale), + y = (resolution.height - (150 * scale)) + } + alignment = 'horizontal' + else + location = { + x = (resolution.width / 2) - ((54 + -528) * scale), + y = (resolution.height - (96 * scale)) + } + end + data.bottom_state = 'bottom_right' + else + Public.get_player_data(player, true) + location = { x = (resolution.width / 2) - ((54 + -528) * scale), y = (resolution.height - (96 * scale)) } - else - frame.location = { - x = (resolution.width / 2) - ((54 + 445) * scale), - y = (resolution.height - (96 * scale)) - } end + + create_frame(player, alignment, location, data.portable) end --- Activates the custom buttons @@ -172,16 +206,6 @@ function Public.is_custom_buttons_enabled() return this.activate_custom_buttons end ---- Sets the buttons to be aligned bottom right ----@param boolean -function Public.bottom_right(value) - if value then - this.bottom_right = value - else - this.bottom_right = false - end -end - Gui.on_click( clear_corpse_button_name, function(event) @@ -219,19 +243,6 @@ Event.add( end ) -Event.add( - defines.events.on_player_died, - function(event) - local player = game.get_player(event.player_index) - if this.activate_custom_buttons then - local frame = player.gui.screen[bottom_guis_frame] - if frame and frame.valid then - frame.destroy() - end - end - end -) - Event.add( defines.events.on_player_display_scale_changed, function(event) @@ -247,6 +258,7 @@ Event.add( function(event) local player = game.get_player(event.player_index) destroy_frame(player) + Public.clear_data(player) end ) diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua index 91450e96..a6bc3cd9 100644 --- a/comfy_panel/config.lua +++ b/comfy_panel/config.lua @@ -16,7 +16,9 @@ local Public = {} local this = { gui_config = { - spaghett = {}, + spaghett = { + undo = {} + }, poll_trusted = false } } @@ -122,20 +124,47 @@ local functions = { game.players[event.player_index].spectator = false end end, - ['comfy_panel_bottom_right_frame'] = function(event) + ['comfy_panel_bottom_location'] = function(event) local player = game.get_player(event.player_index) if event.element.switch_state == 'left' then - local bottom_frame = BottomFrame.get_player_data(player) - if not bottom_frame then - return - end - bottom_frame.bottom_left = true - BottomFrame.set_location(player) + BottomFrame.set_location(player, 'bottom_left') else - BottomFrame.get_player_data(player, true) - BottomFrame.set_location(player) + BottomFrame.set_location(player, 'bottom_right') end end, + ['comfy_panel_middle_location'] = function(event) + local player = game.get_player(event.player_index) + local data = BottomFrame.get_player_data(player) + if event.element.switch_state == 'left' then + data.above = true + data.portable = false + else + data.above = false + data.portable = false + end + if not data.bottom_state then + data.bottom_state = 'bottom_right' + end + + BottomFrame.set_location(player, data.bottom_state) + end, + ['comfy_panel_portable_button'] = function(event) + local player = game.get_player(event.player_index) + local data = BottomFrame.get_player_data(player) + if event.element.switch_state == 'left' then + data.above = false + data.portable = true + else + data.portable = false + data.above = false + end + + if not data.bottom_state then + data.bottom_state = 'bottom_right' + end + + BottomFrame.set_location(player, data.bottom_state) + end, ['comfy_panel_auto_hotbar_switch'] = function(event) if event.element.switch_state == 'left' then global.auto_hotbar_enabled[event.player_index] = true @@ -345,6 +374,7 @@ local function build_config_gui(data) } local scroll_style = scroll_pane.style scroll_style.vertically_squashable = true + scroll_style.minimal_height = 350 scroll_style.bottom_padding = 2 scroll_style.left_padding = 2 scroll_style.right_padding = 2 @@ -395,18 +425,51 @@ local function build_config_gui(data) end if BottomFrame.is_custom_buttons_enabled() then + label = scroll_pane.add({type = 'label', caption = 'Bottom Buttons Settings'}) + label.style.font = 'default-bold' + label.style.padding = 0 + label.style.left_padding = 10 + label.style.top_padding = 10 + label.style.horizontal_align = 'left' + label.style.vertical_align = 'bottom' + label.style.font_color = Color.white_smoke + + scroll_pane.add({type = 'line'}) + switch_state = 'right' - local bottom_frame = BottomFrame.get('players') - if bottom_frame[player.index] then + local bottom_frame = BottomFrame.get_player_data(player) + if bottom_frame and bottom_frame.bottom_state == 'bottom_left' then switch_state = 'left' end add_switch( scroll_pane, switch_state, - 'comfy_panel_bottom_right_frame', - 'Button Location', - 'Toggle to select if you want the bottom button on the right side or the left side.' + 'comfy_panel_bottom_location', + 'Position - bottom', + 'Toggle to select if you want the bottom button on the left side or the right side.' ) + + scroll_pane.add({type = 'line'}) + + switch_state = 'right' + if bottom_frame and bottom_frame.above then + switch_state = 'left' + end + add_switch( + scroll_pane, + switch_state, + 'comfy_panel_middle_location', + 'Position - middle', + 'Toggle to select if you want the bottom button above the quickbar or the side of the quickbar.' + ) + + scroll_pane.add({type = 'line'}) + + switch_state = 'right' + if bottom_frame and bottom_frame.portable then + switch_state = 'left' + end + add_switch(scroll_pane, switch_state, 'comfy_panel_portable_button', 'Position - portable', 'Toggle to select if you want the bottom button to be portable or not.') scroll_pane.add({type = 'line'}) end diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index 76f46558..73caee73 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -247,6 +247,7 @@ local function on_gui_click(event) end Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_player_created, on_player_joined_game) Event.add(defines.events.on_gui_click, on_gui_click) return Public diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index 25b95ad7..eb814430 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -805,6 +805,7 @@ local function tick() end Event.add(defines.events.on_player_joined_game, player_joined) +Event.add(defines.events.on_player_created, player_joined) Event.on_nth_tick(60, tick) Gui.on_click(main_button_name, toggle) diff --git a/commands/misc.lua b/commands/misc.lua index 76b06212..1c6d2aaa 100644 --- a/commands/misc.lua +++ b/commands/misc.lua @@ -250,13 +250,13 @@ commands.add_command( game.print('[CREATIVE] ' .. player.name .. ' has activated creative-mode!', Color.warning) Server.to_discord_bold(table.concat {'[Creative] ' .. player.name .. ' has activated creative-mode!'}) - for k, v in pairs(game.connected_players) do - if v.character ~= nil then - if v.get_inventory(defines.inventory.character_armor) then - v.get_inventory(defines.inventory.character_armor).clear() + for k, _player in pairs(game.connected_players) do + if _player.character ~= nil then + if _player.get_inventory(defines.inventory.character_armor) then + _player.get_inventory(defines.inventory.character_armor).clear() end - v.insert {name = 'power-armor-mk2', count = 1} - local p_armor = v.get_inventory(5)[1].grid + _player.insert {name = 'power-armor-mk2', count = 1} + local p_armor = _player.get_inventory(5)[1].grid if p_armor and p_armor.valid then p_armor.put({name = 'fusion-reactor-equipment'}) p_armor.put({name = 'fusion-reactor-equipment'}) @@ -282,9 +282,9 @@ commands.add_command( Modifiers.update_single_modifier(player, 'character_mining_speed_modifier', 'creative', 50) Modifiers.update_single_modifier(player, 'character_health_bonus', 'creative', 2000) Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'creative', 50) - v.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative') - v.insert {name = _k, count = _v.stack_size} - v.print('[CREATIVE] Inserted all base items.', Color.success) + _player.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative') + _player.insert {name = _k, count = _v.stack_size} + _player.print('[CREATIVE] Inserted all base items.', Color.success) Modifiers.update_player_modifiers(player) end end @@ -442,15 +442,14 @@ function Public.insert_all_items(player) end local item = game.item_prototypes local i = 0 - local p_modifer = Modifiers.get_table() for _k, _v in pairs(item) do i = i + 1 if _k and _v.type ~= 'mining-tool' then - p_modifer[player.index].character_inventory_slots_bonus['creative'] = tonumber(i) - p_modifer[player.index].character_mining_speed_modifier['creative'] = 50 - p_modifer[player.index].character_health_bonus['creative'] = 2000 - p_modifer[player.index].character_crafting_speed_modifier['creative'] = 50 - player.character_inventory_slots_bonus = p_modifer[player.index].character_inventory_slots_bonus['creative'] + Modifiers.update_single_modifier(player, 'character_inventory_slots_bonus', 'creative', tonumber(i)) + Modifiers.update_single_modifier(player, 'character_mining_speed_modifier', 'creative', 50) + Modifiers.update_single_modifier(player, 'character_health_bonus', 'creative', 2000) + Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'creative', 50) + player.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative') player.insert {name = _k, count = _v.stack_size} player.print('[CREATIVE] Inserted all base items.', Color.success) Modifiers.update_player_modifiers(player) diff --git a/maps/dungeons/boss_arena.lua b/maps/dungeons/boss_arena.lua index fe79967c..ca85c51b 100644 --- a/maps/dungeons/boss_arena.lua +++ b/maps/dungeons/boss_arena.lua @@ -1,6 +1,4 @@ -local RPG_F = require 'modules.rpg.functions' -local RPG_T = require 'modules.rpg.table' ---local RPG_S = require "modules.rpg.settings" +local RPG = require 'modules.rpg.main' local BiterHealthBooster = require 'modules.biter_health_booster_v2' local Alert = require 'utils.alert' local DungeonsTable = require 'maps.dungeons.table' @@ -167,9 +165,9 @@ local function spawn_boss(arena, biter, level) end local function hide_rpg(player, show) - local rpg_button = RPG_T.draw_main_frame_name - local rpg_frame = RPG_T.main_frame_name - local rpg_settings = RPG_T.settings_frame_name + local rpg_button = RPG.draw_main_frame_name + local rpg_frame = RPG.main_frame_name + local rpg_settings = RPG.settings_frame_name local rpg_b = player.gui.top[rpg_button] local rpg_f = player.gui.screen[rpg_frame] @@ -196,7 +194,7 @@ local function teleport_player_out(arena, player) local arenatable = DungeonsTable.get_arenatable() local surface = arenatable.previous_position[arena].surface local position = arenatable.previous_position[arena].position - local rpg = RPG_T.get('rpg_t') + local rpg = RPG.get('rpg_t') rpg[player.index].one_punch = true hide_rpg(player, true) player.teleport(surface.find_non_colliding_position('character', position, 20, 0.5), surface) @@ -213,7 +211,7 @@ local function teleport_player_in(arena, player) arenatable.previous_position[arena].position = player.position arenatable.previous_position[arena].surface = player.surface arenatable.timer[arena] = game.tick - local rpg = RPG_T.get('rpg_t') + local rpg = RPG.get('rpg_t') rpg[player.index].one_punch = false rpg[player.index].enable_entity_spawn = false hide_rpg(player, false) @@ -261,7 +259,7 @@ local function boss_died(arena) arenatable.won[arena] = true arenatable.timer[arena] = game.tick - 30 --teleport_player_out(arena, player) - RPG_F.gain_xp(player, 4 + level, true) + RPG.gain_xp(player, 4 + level, true) if level % 10 == 0 and level > 0 then Alert.alert_all_players(8, {'dungeons_tiered.player_won', player.name, arenatable.bosses[player.index]}, {r = 0.8, g = 0.2, b = 0}, 'entity/behemoth-biter', 0.7) else @@ -301,7 +299,7 @@ local function enter_arena(player) -- player.print({"dungeons_tiered.arena_occupied"}) return end - local rpg_t = RPG_T.get('rpg_t') + local rpg_t = RPG.get('rpg_t') if rpg_t[player.index].level < 5 then Alert.alert_player_warning(player, 8, {'dungeons_tiered.arena_level_needed'}) return diff --git a/maps/dungeons/functions.lua b/maps/dungeons/functions.lua index 0d7caf94..31eca168 100644 --- a/maps/dungeons/functions.lua +++ b/maps/dungeons/functions.lua @@ -4,7 +4,7 @@ local BiterRaffle = require 'functions.biter_raffle' local LootRaffle = require 'functions.loot_raffle' local Get_noise = require 'utils.get_noise' local DungeonsTable = require 'maps.dungeons.table' -require 'modules.rpg.table' +require 'modules.rpg.main' local table_shuffle_table = table.shuffle_table local math_random = math.random diff --git a/maps/dungeons/tiered_dungeon.lua b/maps/dungeons/tiered_dungeon.lua index 595db396..300517ee 100644 --- a/maps/dungeons/tiered_dungeon.lua +++ b/maps/dungeons/tiered_dungeon.lua @@ -6,9 +6,7 @@ require 'modules.charging_station' local MapInfo = require 'modules.map_info' local Room_generator = require 'functions.room_generator' -require 'modules.rpg.main' -local RPG_F = require 'modules.rpg.functions' -local RPG_T = require 'modules.rpg.table' +local RPG = require 'modules.rpg.main' local BiterHealthBooster = require 'modules.biter_health_booster_v2' local BiterRaffle = require 'functions.biter_raffle' local Functions = require 'maps.dungeons.functions' @@ -263,7 +261,7 @@ local function draw_light(player) if not player.character then return end - local rpg = RPG_T.get('rpg_t') + local rpg = RPG.get('rpg_t') local magicka = rpg[player.index].magicka local scale = 1 if magicka < 50 then @@ -497,7 +495,7 @@ local function on_player_mined_entity(event) if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then entity.surface.create_entity({name = entity.name, position = entity.position}) entity.destroy() - RPG_F.gain_xp(player, -10) + RPG.gain_xp(player, -10) Alert.alert_player_warning(player, 30, {'dungeons_tiered.too_small'}, {r = 0.98, g = 0.22, b = 0}) event.buffer.clear() return @@ -514,7 +512,7 @@ local function on_player_mined_entity(event) end local function on_entity_died(event) - -- local rpg_extra = RPG_T.get('rpg_extra') + -- local rpg_extra = RPG.get('rpg_extra') -- local hp_units = BiterHealthBooster.get('biter_health_boost_units') local entity = event.entity if not entity.valid then @@ -555,7 +553,7 @@ end local function get_lowest_safe_floor(player) local dungeontable = DungeonsTable.get_dungeontable() - local rpg = RPG_T.get('rpg_t') + local rpg = RPG.get('rpg_t') local level = rpg[player.index].level local sizes = dungeontable.surface_size local safe = dungeontable.original_surface_index @@ -574,7 +572,7 @@ end local function descend(player, button, shift) local dungeontable = DungeonsTable.get_dungeontable() - local rpg = RPG_T.get('rpg_t') + local rpg = RPG.get('rpg_t') if player.surface.index >= dungeontable.original_surface_index + 50 then player.print({'dungeons_tiered.max_depth'}) return @@ -758,7 +756,7 @@ local function transfer_signals(surface_index) end -- local function setup_magic() --- local rpg_spells = RPG_T.get("rpg_spells") +-- local rpg_spells = RPG.get("rpg_spells") -- end local function on_init() @@ -820,8 +818,8 @@ local function on_init() for _, tech in pairs(locked_researches) do game.forces.player.technologies[tech].enabled = false end - RPG_T.set_surface_name('dungeons_floor') - local rpg_table = RPG_T.get('rpg_extra') + RPG.set_surface_name('dungeons_floor') + local rpg_table = RPG.get('rpg_extra') rpg_table.personal_tax_rate = 0 -- rpg_table.enable_mana = true -- setup_magic() diff --git a/maps/mountain_fortress_v3/biters_yield_coins.lua b/maps/mountain_fortress_v3/biters_yield_coins.lua index 5d3246ae..df32aaee 100644 --- a/maps/mountain_fortress_v3/biters_yield_coins.lua +++ b/maps/mountain_fortress_v3/biters_yield_coins.lua @@ -1,5 +1,5 @@ local Event = require 'utils.event' -local RPG_Settings = require 'modules.rpg.table' +local RPG = require 'modules.rpg.main' local BiterHealthBooster = require 'modules.biter_health_booster_v2' local insert = table.insert local floor = math.floor @@ -111,7 +111,7 @@ local function on_entity_died(event) for _, player in pairs(players_to_reward) do local forest_zone if p then - forest_zone = RPG_Settings.get_value_from_player(p.index, 'forest_zone') + forest_zone = RPG.get_value_from_player(p.index, 'forest_zone') end if forest_zone then if random(1, 12) == 1 then diff --git a/maps/mountain_fortress_v3/breached_wall.lua b/maps/mountain_fortress_v3/breached_wall.lua index 9e8cc45d..25557bf9 100644 --- a/maps/mountain_fortress_v3/breached_wall.lua +++ b/maps/mountain_fortress_v3/breached_wall.lua @@ -1,8 +1,7 @@ local Collapse = require 'modules.collapse' local Terrain = require 'maps.mountain_fortress_v3.terrain' local Balance = require 'maps.mountain_fortress_v3.balance' -local RPG_Settings = require 'modules.rpg.table' -local Functions = require 'modules.rpg.functions' +local RPG = require 'modules.rpg.main' local WPT = require 'maps.mountain_fortress_v3.table' local Alert = require 'utils.alert' local Event = require 'utils.event' @@ -86,20 +85,20 @@ local compare_player_pos = function(player) local index = player.index local zone = floor((abs(p.y / level_depth)) % 22) if scrap[zone] then - RPG_Settings.set_value_to_player(index, 'scrap_zone', true) + RPG.set_value_to_player(index, 'scrap_zone', true) else - local has_scrap = RPG_Settings.get_value_from_player(index, 'scrap_zone') + local has_scrap = RPG.get_value_from_player(index, 'scrap_zone') if has_scrap then - RPG_Settings.set_value_to_player(index, 'scrap_zone', false) + RPG.set_value_to_player(index, 'scrap_zone', false) end end if forest[zone] then - RPG_Settings.set_value_to_player(index, 'forest_zone', true) + RPG.set_value_to_player(index, 'forest_zone', true) else - local is_in_forest = RPG_Settings.get_value_from_player(index, 'forest_zone') + local is_in_forest = RPG.get_value_from_player(index, 'forest_zone') if is_in_forest then - RPG_Settings.set_value_to_player(index, 'forest_zone', false) + RPG.set_value_to_player(index, 'forest_zone', false) end end end @@ -140,8 +139,8 @@ end local function distance(player) local index = player.index - local bonus = RPG_Settings.get_value_from_player(index, 'bonus') - local rpg_extra = RPG_Settings.get('rpg_extra') + local bonus = RPG.get_value_from_player(index, 'bonus') + local rpg_extra = RPG.get('rpg_extra') local breached_wall = WPT.get('breached_wall') local bonus_xp_on_join = WPT.get('bonus_xp_on_join') local enable_arties = WPT.get('enable_arties') @@ -217,9 +216,9 @@ local function distance(player) Task.set_timeout_in_ticks(550, collapse_message, data) end - RPG_Settings.set_value_to_player(index, 'bonus', bonus + 1) + RPG.set_value_to_player(index, 'bonus', bonus + 1) - Functions.gain_xp(player, bonus_xp_on_join * bonus) + RPG.gain_xp(player, bonus_xp_on_join * bonus) return end end diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index d8f456a9..e80bbdbc 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -4,8 +4,7 @@ local Event = require 'utils.event' local Server = require 'utils.server' local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies' local Loot = require 'maps.mountain_fortress_v3.loot' -local RPG_Settings = require 'modules.rpg.table' -local Functions = require 'modules.rpg.functions' +local RPG = require 'modules.rpg.main' local Callbacks = require 'maps.mountain_fortress_v3.functions' local Mining = require 'maps.mountain_fortress_v3.mining' local Terrain = require 'maps.mountain_fortress_v3.terrain' @@ -344,7 +343,7 @@ local function protect_entities(event) end local function hidden_treasure(player, entity) - local rpg = RPG_Settings.get('rpg_t') + local rpg = RPG.get('rpg_t') local magic = rpg[player.index].magicka if magic > 50 then @@ -404,7 +403,7 @@ local function angry_tree(entity, cause, player) position = {entity.position.x + (-20 + random(0, 40)), entity.position.y + (-20 + random(0, 40))} end if player then - local forest_zone = RPG_Settings.get_value_from_player(player.index, 'forest_zone') + local forest_zone = RPG.get_value_from_player(player.index, 'forest_zone') if forest_zone and random(1, 32) == 1 then local cbl = Callbacks.refill_turret_callback local data = {callback_data = Callbacks.piercing_rounds_magazine_ammo} @@ -438,7 +437,7 @@ end local function give_coin(player) local coin_amount = WPT.get('coin_amount') local coin_override = WPT.get('coin_override') - local forest_zone = RPG_Settings.get_value_from_player(player.index, 'forest_zone') + local forest_zone = RPG.get_value_from_player(player.index, 'forest_zone') if forest_zone then if random(1, 3) ~= 1 then @@ -697,7 +696,7 @@ local function on_player_mined_entity(event) if not entity.valid then return end - local rpg = RPG_Settings.get('rpg_t') + local rpg = RPG.get('rpg_t') local rpg_char = rpg[player.index] local map_name = 'mountain_fortress_v3' @@ -906,8 +905,8 @@ local function on_player_repaired_entity(event) if carriages_numbers[entity.unit_number] then local player = game.players[event.player_index] - local repair_speed = Functions.get_magicka(player) - if repair_speed <= 0 then + local repair_speed = RPG.get_magicka(player) + if table <= 0 then set_train_final_health(-1, true) return else diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index b0b1f1cd..32f17f7d 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -1,5 +1,5 @@ local Event = require 'utils.event' -local RPG_Settings = require 'modules.rpg.table' +local RPG = require 'modules.rpg.main' local WPT = require 'maps.mountain_fortress_v3.table' local IC_Gui = require 'maps.mountain_fortress_v3.ic.gui' local IC_Minimap = require 'maps.mountain_fortress_v3.ic.minimap' @@ -245,9 +245,9 @@ local function on_player_changed_surface(event) return end - local rpg_button = RPG_Settings.draw_main_frame_name - local rpg_frame = RPG_Settings.main_frame_name - local rpg_settings = RPG_Settings.settings_frame_name + local rpg_button = RPG.draw_main_frame_name + local rpg_frame = RPG.main_frame_name + local rpg_settings = RPG.settings_frame_name local main = WPT.get('locomotive') local icw_locomotive = WPT.get('icw_locomotive') local wagon_surface = icw_locomotive.surface @@ -259,7 +259,7 @@ local function on_player_changed_surface(event) local diff = player.gui.top['difficulty_gui'] local charging = player.gui.top['charging_station'] local frame = player.gui.top[main_frame_name] - local spell_gui_frame_name = RPG_Settings.spell_gui_frame_name + local spell_gui_frame_name = RPG.spell_gui_frame_name local spell_cast_buttons = player.gui.screen[spell_gui_frame_name] if info then @@ -352,7 +352,7 @@ local function enable_guis(event) return end - local rpg_button = RPG_Settings.draw_main_frame_name + local rpg_button = RPG.draw_main_frame_name local info = player.gui.top[main_button_name] local wd = player.gui.top['wave_defense'] local rpg_b = player.gui.top[rpg_button] @@ -405,7 +405,7 @@ function Public.update_gui(player) end local gui = player.gui.top[main_frame_name] - local rpg_extra = RPG_Settings.get('rpg_extra') + local rpg_extra = RPG.get('rpg_extra') local mined_scrap = WPT.get('mined_scrap') local biters_killed = WPT.get('biters_killed') local upgrades = WPT.get('upgrades') diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 987abe63..8bfaf3bb 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -649,6 +649,15 @@ function Public.kill_car(ic, entity) return end + local trust_system = IC.get('trust_system') + local owner = car.owner + + if owner then + if trust_system[owner.index] then + trust_system[owner.index] = nil + end + end + local surface_index = car.surface local surface = game.surfaces[surface_index] kick_players_out_of_vehicles(car) diff --git a/maps/mountain_fortress_v3/ic/gui.lua b/maps/mountain_fortress_v3/ic/gui.lua index 38d65520..a96c25d6 100644 --- a/maps/mountain_fortress_v3/ic/gui.lua +++ b/maps/mountain_fortress_v3/ic/gui.lua @@ -6,11 +6,13 @@ local Tabs = require 'comfy_panel.main' local Event = require 'utils.event' local Public = {} +local insert = table.insert --! Gui Frames local save_add_player_button_name = Gui.uid_name() local save_transfer_car_button_name = Gui.uid_name() local discard_add_player_button_name = Gui.uid_name() +local transfer_player_select_name = Gui.uid_name() local discard_transfer_car_button_name = Gui.uid_name() local main_frame_name = Gui.uid_name() local draw_add_player_frame_name = Gui.uid_name() @@ -55,6 +57,28 @@ local function does_player_table_exist(player) end end +local function get_players(player, frame, all) + local tbl = {} + local players = game.connected_players + local trust_system = create_player_table(player) + + for _, p in pairs(players) do + if next(trust_system.players) and not all then + if not trust_system.players[p.name] then + insert(tbl, tostring(p.name)) + end + else + insert(tbl, tostring(p.name)) + end + end + insert(tbl, 'Select Player') + + local selected_index = #tbl + + local f = frame.add({type = 'drop-down', name = transfer_player_select_name, items = tbl, selected_index = selected_index}) + return f +end + local function transfer_player_table(player, new_player) local trust_system = ICT.get('trust_system') if not trust_system[player.index] then @@ -69,8 +93,8 @@ local function transfer_player_table(player, new_player) trust_system[new_player.index] = trust_system[player.index] local name = new_player.name - if not trust_system[new_player.index][name] then - increment(trust_system[new_player.index], name) + if not trust_system[new_player.index].players[name] then + increment(trust_system[new_player.index].players, name) end local cars = ICT.get('cars') @@ -101,7 +125,7 @@ local function remove_main_frame(main_frame) main_frame.destroy() end -local function draw_add_player(frame) +local function draw_add_player(player, frame) local main_frame = frame.add( { @@ -127,8 +151,7 @@ local function draw_add_player(frame) inside_table_style.bottom_padding = 10 inside_table_style.width = 325 - local add_player_frame = main_frame.add({type = 'textfield', text = 'Name of the player.'}) - add_player_frame.style.width = 140 + local add_player_frame = get_players(player, main_frame) local bottom_flow = main_frame.add({type = 'flow', direction = 'horizontal'}) @@ -150,7 +173,7 @@ local function draw_add_player(frame) Gui.set_data(save_button, add_player_frame) end -local function draw_transfer_car(frame) +local function draw_transfer_car(player, frame) local main_frame = frame.add( { @@ -178,8 +201,7 @@ local function draw_transfer_car(frame) local transfer_car_alert_frame = main_frame.add({type = 'label', caption = "Warning, this action can't be undone!"}) transfer_car_alert_frame.style.font_color = {r = 255, g = 0, b = 0} - local transfer_car_frame = main_frame.add({type = 'textfield', text = 'Name of the player.'}) - transfer_car_frame.style.width = 140 + local transfer_car_frame = get_players(player, main_frame, true) local bottom_flow = main_frame.add({type = 'flow', direction = 'horizontal'}) @@ -432,7 +454,7 @@ Gui.on_click( end local player_frame = frame[draw_add_player_frame_name] if not player_frame or not player_frame.valid then - draw_add_player(frame) + draw_add_player(player, frame) else player_frame.destroy() end @@ -454,7 +476,7 @@ Gui.on_click( end local player_frame = frame[draw_transfer_car_frame_name] if not player_frame or not player_frame.valid then - draw_transfer_car(frame) + draw_transfer_car(player, frame) else player_frame.destroy() end @@ -477,10 +499,10 @@ Gui.on_click( if frame and frame.valid then if player_list.allow_anyone == 'right' then player_list.allow_anyone = 'left' - player.print('Everyone is allowed to enter your car!', Color.warning) + player.print('[IC] Everyone is allowed to enter your car!', Color.warning) else player_list.allow_anyone = 'right' - player.print('Everyone is disallowed to enter your car except your trusted list!', Color.warning) + player.print('[IC] Everyone is disallowed to enter your car except your trusted list!', Color.warning) end if player.gui.screen[main_frame_name] then @@ -505,24 +527,26 @@ Gui.on_click( local add_player_frame = Gui.get_data(event.element) if frame and frame.valid then - if add_player_frame and add_player_frame.valid and add_player_frame.text then - local text = add_player_frame.text - if not text then + if add_player_frame and add_player_frame.valid and add_player_frame then + local player_gui_data = ICT.get('player_gui_data') + local fetched_name = player_gui_data[player.name] + if not fetched_name then return end - local player_to_add = game.get_player(text) + + local player_to_add = game.get_player(fetched_name) if not player_to_add or not player_to_add.valid then - return player.print('Target player was not valid.', Color.warning) + return player.print('[IC] Target player was not valid.', Color.warning) end local name = player_to_add.name if not player_list.players[name] then - player.print(name .. ' was added to your vehicle.', Color.info) + player.print('[IC] ' .. name .. ' was added to your vehicle.', Color.info) player_to_add.print(player.name .. ' added you to their vehicle. You may now enter it.', Color.info) increment(player_list.players, name) else - return player.print('Target player is already trusted.', Color.warning) + return player.print('[IC] Target player is already trusted.', Color.warning) end remove_main_frame(event.element) @@ -548,33 +572,30 @@ Gui.on_click( local transfer_car_frame = Gui.get_data(event.element) if frame and frame.valid then - if transfer_car_frame and transfer_car_frame.valid and transfer_car_frame.text then - local text = transfer_car_frame.text - if not text then + if transfer_car_frame and transfer_car_frame.valid then + local player_gui_data = ICT.get('player_gui_data') + local fetched_name = player_gui_data[player.name] + if not fetched_name then return end - local player_to_add = game.get_player(text) + + local player_to_add = game.get_player(fetched_name) if not player_to_add or not player_to_add.valid then - return player.print('Target player was not valid.', Color.warning) + return player.print('[IC] Target player was not valid.', Color.warning) end - local name = player_to_add.name - local does_player_have_a_car = does_player_table_exist(name) + + local does_player_have_a_car = does_player_table_exist(player_to_add) if does_player_have_a_car then - return player.print(name .. ' already has a vehicle.', Color.warning) + return player.print('[IC] ' .. name .. ' already has a vehicle.', Color.warning) end - local to_add = game.get_player(name) - if not (to_add and to_add.valid) then - return player.print(name .. ' does not exist.', Color.warning) - end - - local success = transfer_player_table(player, to_add) + local success = transfer_player_table(player, player_to_add) if not success then - player.print('Please try again.', Color.warning) + player.print('[IC] Please try again.', Color.warning) else - player.print('You have successfully transferred your car to ' .. name, Color.success) - to_add.print('You have become the rightfully owner of ' .. player.name .. "'s car!", Color.success) + player.print('[IC] You have successfully transferred your car to ' .. name, Color.success) + player_to_add.print('[IC] You have become the rightfully owner of ' .. player.name .. "'s car!", Color.success) end remove_main_frame(event.element) @@ -608,13 +629,13 @@ Gui.on_click( end local target = game.get_player(player_name) if not target or not target.valid then - player.print('Target player was not valid.', Color.warning) + player.print('[IC] Target player was not valid.', Color.warning) return end local name = target.name if player_list.players[name] then - player.print(name .. ' was removed from your vehicle.', Color.info) + player.print('[IC] ' .. name .. ' was removed from your vehicle.', Color.info) decrement(player_list.players, name) raise_event( ICT.events.on_player_kicked_from_surface, @@ -696,6 +717,47 @@ Gui.on_click( end ) +Gui.on_selection_state_changed( + transfer_player_select_name, + function(event) + local player = event.player + if not player or not player.valid or not player.character then + return + end + + local screen = player.gui.screen + local frame = screen[main_frame_name] + if not frame or not frame.valid then + return + end + + local element = event.element + if not element or not element.valid then + return + end + + local player_gui_data = ICT.get('player_gui_data') + local selected = element.items[element.selected_index] + if not selected then + return + end + + if selected == 'Select Player' then + player.print('[IC] No target player selected.', Color.warning) + player_gui_data[player.name] = nil + return + end + + if selected == player.name then + player.print('[IC] You can´t select yourself.', Color.warning) + player_gui_data[player.name] = nil + return + end + + player_gui_data[player.name] = selected + end +) + Public.draw_main_frame = draw_main_frame Public.toggle = toggle Public.add_toolbar = add_toolbar diff --git a/maps/mountain_fortress_v3/ic/table.lua b/maps/mountain_fortress_v3/ic/table.lua index 11801527..437a8032 100644 --- a/maps/mountain_fortress_v3/ic/table.lua +++ b/maps/mountain_fortress_v3/ic/table.lua @@ -38,6 +38,7 @@ function Public.reset() this.allowed_surface = 'nauvis' this.trust_system = {} this.players = {} + this.player_gui_data = {} this.surfaces = {} this.minimap = {} this.entity_type = { diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 61c77a6e..ae8682eb 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -7,8 +7,7 @@ local WD = require 'modules.wave_defense.table' local Session = require 'utils.datastore.session_data' local Difficulty = require 'modules.difficulty_vote_by_amount' local Jailed = require 'utils.datastore.jail_data' -local RPG_Settings = require 'modules.rpg.table' -local Functions = require 'modules.rpg.functions' +local RPG = require 'modules.rpg.main' local Gui = require 'utils.gui' local Server = require 'utils.server' local Alert = require 'utils.alert' @@ -24,7 +23,7 @@ local format_number = require 'util'.format_number local Public = {} local concat = table.concat local main_frame_name = Gui.uid_name() -local rpg_main_frame = RPG_Settings.main_frame_name +local rpg_main_frame = RPG.main_frame_name local random = math.random local floor = math.floor local round = math.round @@ -355,7 +354,7 @@ local function property_boost(data) if Math2D.bounding_box.contains_point(area, player.position) or player.surface.index == loco_surface.index then Public.add_player_to_permission_group(player, 'locomotive') local pos = player.position - Functions.gain_xp(player, 0.5 * (rpg[player.index].bonus + xp_points)) + RPG.gain_xp(player, 0.5 * (rpg[player.index].bonus + xp_points)) player.create_local_flying_text { text = '+' .. '', @@ -1226,7 +1225,7 @@ local function gui_click(event) player.name .. ' has bought the explosive bullet modifier for ' .. format_number(item.price) .. ' coins.' } ) - RPG_Settings.enable_explosive_bullets(true) + RPG.enable_explosive_bullets(true) this.explosive_bullets = true redraw_market_items(data.item_frame, player, data.search_text) @@ -1903,7 +1902,7 @@ function Public.refresh_gui() end function Public.boost_players_around_train() - local rpg = RPG_Settings.get('rpg_t') + local rpg = RPG.get('rpg_t') local active_surface_index = WPT.get('active_surface_index') if not active_surface_index then return diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index a9d0ff84..dab86fd2 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -1,5 +1,3 @@ -require 'modules.rpg.main' - local Functions = require 'maps.mountain_fortress_v3.functions' local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies' @@ -19,8 +17,7 @@ local Gui_mf = require 'maps.mountain_fortress_v3.gui' local ICW = require 'maps.mountain_fortress_v3.icw.main' local WD = require 'modules.wave_defense.table' local Map = require 'modules.map_info' -local RPG_Settings = require 'modules.rpg.table' -local RPG_Func = require 'modules.rpg.functions' +local RPG = require 'modules.rpg.main' local Event = require 'utils.event' local WPT = require 'maps.mountain_fortress_v3.table' local Locomotive = require 'maps.mountain_fortress_v3.locomotive' @@ -31,7 +28,7 @@ local Difficulty = require 'modules.difficulty_vote_by_amount' local Task = require 'utils.task' local Token = require 'utils.token' local Alert = require 'utils.alert' --- local BottomFrame = require 'comfy_panel.bottom_frame' +local BottomFrame = require 'comfy_panel.bottom_frame' local AntiGrief = require 'antigrief' local Misc = require 'commands.misc' local Modifiers = require 'player_modifiers' @@ -132,11 +129,10 @@ function Public.reset_map() Autostash.insert_into_furnace(true) Autostash.insert_into_wagon(true) - Autostash.bottom_button(false) - BuriedEnemies.reset() - --[[ BottomFrame.reset() + Autostash.bottom_button(true) + BottomFrame.reset() BottomFrame.activate_custom_buttons(true) - BottomFrame.bottom_right(true) ]] + BuriedEnemies.reset() Poll.reset() ICW.reset() IC.reset() @@ -145,20 +141,20 @@ function Public.reset_map() game.reset_time_played() WPT.reset_table() - RPG_Func.rpg_reset_all_players() - RPG_Settings.set_surface_name(game.surfaces[this.active_surface_index].name) - RPG_Settings.enable_health_and_mana_bars(true) - RPG_Settings.enable_wave_defense(true) - RPG_Settings.enable_mana(true) - RPG_Settings.enable_flame_boots(true) - RPG_Settings.personal_tax_rate(0.4) - RPG_Settings.enable_stone_path(true) - RPG_Settings.enable_one_punch(true) - RPG_Settings.enable_one_punch_globally(false) - RPG_Settings.enable_auto_allocate(true) - RPG_Settings.disable_cooldowns_on_spells() - RPG_Settings.enable_explosive_bullets_globally(true) - RPG_Settings.enable_explosive_bullets(false) + RPG.rpg_reset_all_players() + RPG.set_surface_name(game.surfaces[this.active_surface_index].name) + RPG.enable_health_and_mana_bars(true) + RPG.enable_wave_defense(true) + RPG.enable_mana(true) + RPG.enable_flame_boots(true) + RPG.personal_tax_rate(0.4) + RPG.enable_stone_path(true) + RPG.enable_one_punch(true) + RPG.enable_one_punch_globally(false) + RPG.enable_auto_allocate(true) + RPG.disable_cooldowns_on_spells() + RPG.enable_explosive_bullets_globally(true) + RPG.enable_explosive_bullets(false) Group.reset_groups() Group.alphanumeric_only(false) diff --git a/maps/mountain_fortress_v3/mining.lua b/maps/mountain_fortress_v3/mining.lua index 4503b90b..897c515a 100644 --- a/maps/mountain_fortress_v3/mining.lua +++ b/maps/mountain_fortress_v3/mining.lua @@ -1,5 +1,5 @@ local WPT = require 'maps.mountain_fortress_v3.table' -local RPG_Settings = require 'modules.rpg.table' +local RPG = require 'modules.rpg.main' require 'modules.check_fullness' local Public = {} @@ -433,7 +433,7 @@ function Public.on_player_mined_entity(event) local index = player.index - local scrap_zone = RPG_Settings.get_value_from_player(index, 'scrap_zone') + local scrap_zone = RPG.get_value_from_player(index, 'scrap_zone') if scrap_zone or is_scrap then randomness_scrap(data) else diff --git a/modules/autostash.lua b/modules/autostash.lua index d1374765..003fa0b3 100644 --- a/modules/autostash.lua +++ b/modules/autostash.lua @@ -598,9 +598,6 @@ local function do_whitelist() end local function on_player_joined_game(event) - if is_loaded('maps.biter_battles_v2.main') then - return - end create_gui_button(game.players[event.player_index]) end diff --git a/modules/biter_health_booster_v2.lua b/modules/biter_health_booster_v2.lua index 8f24f901..fa3be9ad 100644 --- a/modules/biter_health_booster_v2.lua +++ b/modules/biter_health_booster_v2.lua @@ -91,10 +91,6 @@ local removeUnit = end ) -if is_loaded('maps.biter_hatchery.terrain') then - entity_types['unit-spawner'] = nil -end - local function loaded_biters(event) local cause = event.cause local entity = event.entity diff --git a/modules/difficulty_vote_by_amount.lua b/modules/difficulty_vote_by_amount.lua index b54eabaf..3fe78822 100644 --- a/modules/difficulty_vote_by_amount.lua +++ b/modules/difficulty_vote_by_amount.lua @@ -356,6 +356,7 @@ function Public.get(key) end end +Event.add(defines.events.on_player_created, on_player_joined_game) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/modules/floaty_chat.lua b/modules/floaty_chat.lua index 4e42310f..e04a8f20 100644 --- a/modules/floaty_chat.lua +++ b/modules/floaty_chat.lua @@ -25,9 +25,6 @@ local function on_console_chat(event) end local y_offset = -4 - if is_loaded('modules.rpg') then - y_offset = -4.5 - end if this.player_floaty_chat[player.index] then rendering.destroy(this.player_floaty_chat[player.index]) diff --git a/modules/rpg.lua b/modules/rpg.lua index 054fd734..46d3fee9 100644 --- a/modules/rpg.lua +++ b/modules/rpg.lua @@ -151,7 +151,6 @@ local function update_char_button(player) end local function update_player_stats(player) - local player_modifiers = P.get_table() local strength = rpg_t[player.index].strength - 10 P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', math.round(strength * 0.2, 3)) P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', math.round(strength * 0.008, 3)) diff --git a/modules/rpg/commands.lua b/modules/rpg/commands.lua index d0ae8e34..2b28fca7 100644 --- a/modules/rpg/commands.lua +++ b/modules/rpg/commands.lua @@ -7,7 +7,7 @@ local round = math.round local validate_args = function(data) local player = data.player local target = data.target - local rpg_t = data.rpg_t + local rpg_t = RPG.get_value_from_player(target.index) if not target then return false @@ -54,7 +54,7 @@ local validate_args = function(data) return false end - if not rpg_t[target.index] then + if not rpg_t then Utils.print_to(player, 'Invalid target.') return false end @@ -62,20 +62,21 @@ local validate_args = function(data) return true end -local print_stats = function(target, tbl) +local print_stats = function(target) if not target then return end - if not tbl then + local rpg_t = RPG.get_value_from_player(target.index) + if not rpg_t then return end - local t = tbl[target.index] - local level = t.level - local xp = round(t.xp) - local strength = t.strength - local magicka = t.magicka - local dexterity = t.dexterity - local vitality = t.vitality + + local level = rpg_t.level + local xp = round(rpg_t.xp) + local strength = rpg_t.strength + local magicka = rpg_t.magicka + local dexterity = rpg_t.dexterity + local vitality = rpg_t.vitality local output = '[color=blue]' .. target.name .. '[/color] has the following stats: \n' output = output .. '[color=green]Level:[/color] ' .. level .. '\n' output = output .. '[color=green]XP:[/color] ' .. xp .. '\n' @@ -111,16 +112,13 @@ commands.add_command( return end - local rpg_t = RPG.get('rpg_t') - local data = { player = player, - target = target, - rpg_t = rpg_t + target = target } if validate_args(data) then - local msg = print_stats(target, rpg_t) + local msg = print_stats(target) player.play_sound {path = 'utility/scenario_message', volume_modifier = 1} player.print(msg) else diff --git a/modules/rpg/core.lua b/modules/rpg/core.lua new file mode 100644 index 00000000..37099440 --- /dev/null +++ b/modules/rpg/core.lua @@ -0,0 +1,18 @@ +local Public = require 'modules.rpg.table' + +local Bullets = require 'modules.rpg.explosive_gun_bullets' +Public.explosive_bullet = Bullets + +local Functions = require 'modules.rpg.functions' +Public.functions = Functions + +local Gui = require 'modules.rpg.gui' +Public.gui = Gui + +local Settings = require 'modules.rpg.settings' +Public.settings = Settings + +local Spells = require 'modules.rpg.spells' +Public.spells = Spells + +return Public diff --git a/modules/rpg/explosive_gun_bullets.lua b/modules/rpg/explosive_gun_bullets.lua index 833dde4e..bb7e1dbc 100644 --- a/modules/rpg/explosive_gun_bullets.lua +++ b/modules/rpg/explosive_gun_bullets.lua @@ -1,11 +1,9 @@ -local RPG_T = require 'modules.rpg.table' +local Public = require 'modules.rpg.table' local radius = 3 local random = math.random local floor = math.floor local sqrt = math.sqrt -local Public = {} - local function splash_damage(surface, position, final_damage_amount) local create = surface.create_entity local damage = random(floor(final_damage_amount * 3), floor(final_damage_amount * 4)) @@ -26,7 +24,7 @@ local function splash_damage(surface, position, final_damage_amount) end function Public.explosive_bullets(event) - local is_explosive_bullets_enabled = RPG_T.get_explosive_bullets() + local is_explosive_bullets_enabled = Public.get_explosive_bullets() if not is_explosive_bullets_enabled then return end @@ -57,8 +55,7 @@ function Public.explosive_bullets(event) return end - local player_data = RPG_T.get('rpg_t') - local rpg_player = player_data[p.index] + local rpg_player = Public.get_value_from_player(p.index) if not rpg_player.explosive_bullets then return end @@ -88,5 +85,3 @@ function Public.explosive_bullets(event) splash_damage(surface, entity.position, event.final_damage_amount) end end - -return Public diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 9dcd1186..238884dd 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -1,21 +1,20 @@ +local Public = require 'modules.rpg.table' local Task = require 'utils.task' -local RPG = require 'modules.rpg.table' local Gui = require 'utils.gui' local Color = require 'utils.color_presets' local Token = require 'utils.token' local Alert = require 'utils.alert' -local Public = {} - local level_up_floating_text_color = {0, 205, 0} -local visuals_delay = RPG.visuals_delay -local xp_floating_text_color = RPG.xp_floating_text_color -local experience_levels = RPG.experience_levels -local points_per_level = RPG.points_per_level +local visuals_delay = Public.visuals_delay +local xp_floating_text_color = Public.xp_floating_text_color +local experience_levels = Public.experience_levels +local points_per_level = Public.points_per_level +local settings_level = Public.gui_settings_levels --RPG Frames -local main_frame_name = RPG.main_frame_name -local spell_gui_frame_name = RPG.spell_gui_frame_name +local main_frame_name = Public.main_frame_name +local spell_gui_frame_name = Public.spell_gui_frame_name local travelings = { 'bzzZZrrt', @@ -100,14 +99,13 @@ local function set_bar(min, max, id, mana) end local function level_up(player) - local rpg_t = RPG.get('rpg_t') - local RPG_GUI = is_loaded('modules.rpg.gui') - local names = RPG.auto_allocate_nodes_func + local rpg_t = Public.get_value_from_player(player.index) + local names = Public.auto_allocate_nodes_func local distribute_points_gain = 0 - for i = rpg_t[player.index].level + 1, #experience_levels, 1 do - if rpg_t[player.index].xp > experience_levels[i] then - rpg_t[player.index].level = i + for i = rpg_t.level + 1, #experience_levels, 1 do + if rpg_t.xp > experience_levels[i] then + rpg_t.level = i distribute_points_gain = distribute_points_gain + points_per_level else break @@ -116,29 +114,37 @@ local function level_up(player) if distribute_points_gain == 0 then return end - RPG_GUI.draw_level_text(player) - rpg_t[player.index].points_left = rpg_t[player.index].points_left + distribute_points_gain - if rpg_t[player.index].allocate_index ~= 1 then - local node = rpg_t[player.index].allocate_index + + if rpg_t.level >= settings_level['one_punch_label'] then + rpg_t.one_punch = true + end + if rpg_t.level >= settings_level['stone_path_label'] then + rpg_t.stone_path = true + end + + Public.draw_level_text(player) + rpg_t.points_left = rpg_t.points_left + distribute_points_gain + if rpg_t.allocate_index ~= 1 then + local node = rpg_t.allocate_index local index = names[node]:lower() - rpg_t[player.index][index] = rpg_t[player.index][index] + distribute_points_gain - rpg_t[player.index].points_left = rpg_t[player.index].points_left - distribute_points_gain - if not rpg_t[player.index].reset then - rpg_t[player.index].total = rpg_t[player.index].total + distribute_points_gain + rpg_t[index] = rpg_t[index] + distribute_points_gain + rpg_t.points_left = rpg_t.points_left - distribute_points_gain + if not rpg_t.reset then + rpg_t.total = rpg_t.total + distribute_points_gain end - RPG_GUI.update_player_stats(player) + Public.update_player_stats(player) else - RPG_GUI.update_char_button(player) + Public.update_char_button(player) end if player.gui.screen[main_frame_name] then - RPG_GUI.toggle(player, true) + Public.toggle(player, true) end Public.level_up_effects(player) end local function add_to_global_pool(amount, personal_tax) - local rpg_extra = RPG.get('rpg_extra') + local rpg_extra = Public.get('rpg_extra') if not rpg_extra.global_pool then return @@ -256,13 +262,13 @@ function Public.validate_player(player) end function Public.update_mana(player) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if not rpg_extra.enable_mana then return end - if not rpg_t[player.index] then + if not rpg_t then return end @@ -270,38 +276,38 @@ function Public.update_mana(player) local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.mana and data.mana.valid then - data.mana.caption = rpg_t[player.index].mana + data.mana.caption = rpg_t.mana end end if player.gui.screen[spell_gui_frame_name] then local f = player.gui.screen[spell_gui_frame_name] if f['spell_table'] then if f['spell_table']['mana'] then - f['spell_table']['mana'].caption = math.floor(rpg_t[player.index].mana) + f['spell_table']['mana'].caption = math.floor(rpg_t.mana) end if f['spell_table']['maxmana'] then - f['spell_table']['maxmana'].caption = math.floor(rpg_t[player.index].mana_max) + f['spell_table']['maxmana'].caption = math.floor(rpg_t.mana_max) end end end - if rpg_t[player.index].mana < 1 then + if rpg_t.mana < 1 then return end if rpg_extra.enable_health_and_mana_bars then - if rpg_t[player.index].show_bars then + if rpg_t.show_bars then if player.character and player.character.valid then - if not rpg_t[player.index].mana_bar then - rpg_t[player.index].mana_bar = create_manabar(player, 0.5) - elseif not rendering.is_valid(rpg_t[player.index].mana_bar) then - rpg_t[player.index].mana_bar = create_manabar(player, 0.5) + if not rpg_t.mana_bar then + rpg_t.mana_bar = create_manabar(player, 0.5) + elseif not rendering.is_valid(rpg_t.mana_bar) then + rpg_t.mana_bar = create_manabar(player, 0.5) end - set_bar(rpg_t[player.index].mana, rpg_t[player.index].mana_max, rpg_t[player.index].mana_bar, true) + set_bar(rpg_t.mana, rpg_t.mana_max, rpg_t.mana_bar, true) end else - if rpg_t[player.index].mana_bar then - if rendering.is_valid(rpg_t[player.index].mana_bar) then - rendering.destroy(rpg_t[player.index].mana_bar) + if rpg_t.mana_bar then + if rendering.is_valid(rpg_t.mana_bar) then + rendering.destroy(rpg_t.mana_bar) end end end @@ -309,8 +315,8 @@ function Public.update_mana(player) end function Public.reward_mana(player, mana_to_add) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if not rpg_extra.enable_mana then return end @@ -319,7 +325,7 @@ function Public.reward_mana(player, mana_to_add) return end - if not rpg_t[player.index] then + if not rpg_t then return end @@ -327,36 +333,36 @@ function Public.reward_mana(player, mana_to_add) local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.mana and data.mana.valid then - data.mana.caption = rpg_t[player.index].mana + data.mana.caption = rpg_t.mana end end if player.gui.screen[spell_gui_frame_name] then local f = player.gui.screen[spell_gui_frame_name] if f['spell_table'] then if f['spell_table']['mana'] then - f['spell_table']['mana'].caption = math.floor(rpg_t[player.index].mana) + f['spell_table']['mana'].caption = math.floor(rpg_t.mana) end if f['spell_table']['maxmana'] then - f['spell_table']['maxmana'].caption = math.floor(rpg_t[player.index].mana_max) + f['spell_table']['maxmana'].caption = math.floor(rpg_t.mana_max) end end end - if rpg_t[player.index].mana_max < 1 then + if rpg_t.mana_max < 1 then return end - if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then - rpg_t[player.index].mana = rpg_t[player.index].mana_max + if rpg_t.mana >= rpg_t.mana_max then + rpg_t.mana = rpg_t.mana_max return end - rpg_t[player.index].mana = rpg_t[player.index].mana + mana_to_add + rpg_t.mana = rpg_t.mana + mana_to_add end function Public.update_health(player) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if not player or not player.valid then return @@ -366,7 +372,7 @@ function Public.update_health(player) return end - if not rpg_t[player.index] then + if not rpg_t then return end @@ -392,18 +398,18 @@ function Public.update_health(player) end if rpg_extra.enable_health_and_mana_bars then - if rpg_t[player.index].show_bars then + if rpg_t.show_bars then local max_life = math.floor(player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus) - if not rpg_t[player.index].health_bar then - rpg_t[player.index].health_bar = create_healthbar(player, 0.5) - elseif not rendering.is_valid(rpg_t[player.index].health_bar) then - rpg_t[player.index].health_bar = create_healthbar(player, 0.5) + if not rpg_t.health_bar then + rpg_t.health_bar = create_healthbar(player, 0.5) + elseif not rendering.is_valid(rpg_t.health_bar) then + rpg_t.health_bar = create_healthbar(player, 0.5) end - set_bar(player.character.health, max_life, rpg_t[player.index].health_bar) + set_bar(player.character.health, max_life, rpg_t.health_bar) else - if rpg_t[player.index].health_bar then - if rendering.is_valid(rpg_t[player.index].health_bar) then - rendering.destroy(rpg_t[player.index].health_bar) + if rpg_t.health_bar then + if rendering.is_valid(rpg_t.health_bar) then + rendering.destroy(rpg_t.health_bar) end end end @@ -411,8 +417,8 @@ function Public.update_health(player) end function Public.level_limit_exceeded(player, value) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if not rpg_extra.level_limit_enabled then return false end @@ -430,7 +436,7 @@ function Public.level_limit_exceeded(player, value) [10] = 210 } - local level = rpg_t[player.index].level + local level = rpg_t.level local zone = rpg_extra.breached_walls if zone >= 11 then zone = 10 @@ -474,37 +480,37 @@ function Public.xp_effects(player) end function Public.get_melee_modifier(player) - local rpg_t = RPG.get('rpg_t') - return (rpg_t[player.index].strength - 10) * 0.10 + local rpg_t = Public.get_value_from_player(player.index) + return (rpg_t.strength - 10) * 0.10 end function Public.get_heal_modifier(player) - local rpg_t = RPG.get('rpg_t') - return (rpg_t[player.index].vitality - 10) * 0.06 + local rpg_t = Public.get_value_from_player(player.index) + return (rpg_t.vitality - 10) * 0.06 end function Public.get_mana_modifier(player) - local rpg_t = RPG.get('rpg_t') - if rpg_t[player.index].level <= 40 then - return (rpg_t[player.index].magicka - 10) * 0.02000 - elseif rpg_t[player.index].level <= 80 then - return (rpg_t[player.index].magicka - 10) * 0.01800 + local rpg_t = Public.get_value_from_player(player.index) + if rpg_t.level <= 40 then + return (rpg_t.magicka - 10) * 0.02000 + elseif rpg_t.level <= 80 then + return (rpg_t.magicka - 10) * 0.01800 else - return (rpg_t[player.index].magicka - 10) * 0.01400 + return (rpg_t.magicka - 10) * 0.01400 end end function Public.get_life_on_hit(player) - local rpg_t = RPG.get('rpg_t') - return (rpg_t[player.index].vitality - 10) * 0.4 + local rpg_t = Public.get_value_from_player(player.index) + return (rpg_t.vitality - 10) * 0.4 end function Public.get_one_punch_chance(player) - local rpg_t = RPG.get('rpg_t') - if rpg_t[player.index].strength < 100 then + local rpg_t = Public.get_value_from_player(player.index) + if rpg_t.strength < 100 then return 0 end - local chance = math.round(rpg_t[player.index].strength * 0.01, 1) + local chance = math.round(rpg_t.strength * 0.01, 1) if chance > 100 then chance = 100 end @@ -512,20 +518,20 @@ function Public.get_one_punch_chance(player) end function Public.get_extra_following_robots(player) - local rpg_t = RPG.get('rpg_t') - local strength = rpg_t[player.index].strength + local rpg_t = Public.get_value_from_player(player.index) + local strength = rpg_t.strength local count = math.round(strength / 2 * 0.03, 3) return count end function Public.get_magicka(player) - local rpg_t = RPG.get('rpg_t') - return (rpg_t[player.index].magicka - 10) * 0.10 + local rpg_t = Public.get_value_from_player(player.index) + return (rpg_t.magicka - 10) * 0.10 end --- Gives connected player some bonus xp if the map was preemptively shut down. -- amount (integer) -- 10 levels --- local Public = require 'modules.rpg.functions' Public.give_xp(512) +-- local Public = require 'modules.rpg.table' Public.give_xp(512) function Public.give_xp(amount) for _, player in pairs(game.connected_players) do if not Public.validate_player(player) then @@ -540,94 +546,104 @@ function Public.rpg_reset_player(player, one_time_reset) player.set_controller({type = defines.controllers.god}) player.create_character() end - local RPG_GUI = is_loaded('modules.rpg.gui') - local rpg_t = RPG.get('rpg_t') - local rpg_extra = RPG.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) + local rpg_extra = Public.get('rpg_extra') if one_time_reset then - local total = rpg_t[player.index].total + local total = rpg_t.total if not total then total = 0 end - local old_level = rpg_t[player.index].level - local old_points_to_distribute = rpg_t[player.index].points_left - local old_xp = rpg_t[player.index].xp - rpg_t[player.index] = { - level = 1, - xp = 0, - strength = 10, - magicka = 10, - dexterity = 10, - vitality = 10, - mana = 0, - mana_max = 0, - last_spawned = 0, - dropdown_select_index = 1, - dropdown_select_index1 = 1, - dropdown_select_index2 = 1, - dropdown_select_index3 = 1, - allocate_index = 1, - flame_boots = false, - explosive_bullets = false, - enable_entity_spawn = false, - health_bar = rpg_t[player.index].health_bar, - mana_bar = rpg_t[player.index].mana_bar, - points_left = 0, - last_floaty_text = visuals_delay, - xp_since_last_floaty_text = 0, - reset = true, - capped = false, - bonus = rpg_extra.breached_walls or 1, - rotated_entity_delay = 0, - last_mined_entity_position = {x = 0, y = 0}, - show_bars = false, - stone_path = false, - one_punch = false - } - rpg_t[player.index].points_left = old_points_to_distribute + total - rpg_t[player.index].xp = old_xp - rpg_t[player.index].level = old_level + if rpg_t.text then + rendering.destroy(rpg_t.text) + rpg_t.text = nil + end + local old_level = rpg_t.level + local old_points_left = rpg_t.points_left + local old_xp = rpg_t.xp + rpg_t = + Public.set_new_player_tbl( + player.index, + { + level = 1, + xp = 0, + strength = 10, + magicka = 10, + dexterity = 10, + vitality = 10, + mana = 0, + mana_max = 0, + last_spawned = 0, + dropdown_select_index = 1, + dropdown_select_index1 = 1, + dropdown_select_index2 = 1, + dropdown_select_index3 = 1, + allocate_index = 1, + flame_boots = false, + explosive_bullets = false, + enable_entity_spawn = false, + health_bar = rpg_t.health_bar, + mana_bar = rpg_t.mana_bar, + points_left = 0, + last_floaty_text = visuals_delay, + xp_since_last_floaty_text = 0, + reset = true, + capped = false, + bonus = rpg_extra.breached_walls or 1, + rotated_entity_delay = 0, + last_mined_entity_position = {x = 0, y = 0}, + show_bars = false, + stone_path = false, + one_punch = false + } + ) + rpg_t.points_left = old_points_left + total + rpg_t.xp = old_xp + rpg_t.level = old_level else - rpg_t[player.index] = { - level = 1, - xp = 0, - strength = 10, - magicka = 10, - dexterity = 10, - vitality = 10, - mana = 0, - mana_max = 0, - last_spawned = 0, - dropdown_select_index = 1, - dropdown_select_index1 = 1, - dropdown_select_index2 = 1, - dropdown_select_index3 = 1, - allocate_index = 1, - flame_boots = false, - explosive_bullets = false, - enable_entity_spawn = false, - points_left = 0, - last_floaty_text = visuals_delay, - xp_since_last_floaty_text = 0, - reset = false, - capped = false, - total = 0, - bonus = 1, - rotated_entity_delay = 0, - last_mined_entity_position = {x = 0, y = 0}, - show_bars = false, - stone_path = false, - one_punch = false - } + Public.set_new_player_tbl( + player.index, + { + level = 1, + xp = 0, + strength = 10, + magicka = 10, + dexterity = 10, + vitality = 10, + mana = 0, + mana_max = 0, + last_spawned = 0, + dropdown_select_index = 1, + dropdown_select_index1 = 1, + dropdown_select_index2 = 1, + dropdown_select_index3 = 1, + allocate_index = 1, + flame_boots = false, + explosive_bullets = false, + enable_entity_spawn = false, + points_left = 0, + last_floaty_text = visuals_delay, + xp_since_last_floaty_text = 0, + reset = false, + capped = false, + total = 0, + bonus = 1, + rotated_entity_delay = 0, + last_mined_entity_position = {x = 0, y = 0}, + show_bars = false, + stone_path = false, + one_punch = false + } + ) end - RPG_GUI.draw_gui_char_button(player) - RPG_GUI.draw_level_text(player) - RPG_GUI.update_char_button(player) - RPG_GUI.update_player_stats(player) + Public.draw_gui_char_button(player) + Public.draw_level_text(player) + Public.update_char_button(player) + Public.update_player_stats(player) end function Public.rpg_reset_all_players() - local rpg_t = RPG.get('rpg_t') - local rpg_extra = RPG.get('rpg_extra') + local rpg_t = Public.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') for k, _ in pairs(rpg_t) do rpg_t[k] = nil end @@ -643,13 +659,13 @@ function Public.gain_xp(player, amount, added_to_pool, text) if not Public.validate_player(player) then return end - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if Public.level_limit_exceeded(player) then add_to_global_pool(amount, false) - if not rpg_t[player.index].capped then - rpg_t[player.index].capped = true + if not rpg_t.capped then + rpg_t.capped = true local message = ({'rpg_functions.max_level'}) Alert.alert_player_warning(player, 10, message) end @@ -658,27 +674,27 @@ function Public.gain_xp(player, amount, added_to_pool, text) local text_to_draw - if rpg_t[player.index].capped then - rpg_t[player.index].capped = false + if rpg_t.capped then + rpg_t.capped = false end if not added_to_pool then - RPG.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) + Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) local fee = amount - add_to_global_pool(amount, true) - RPG.debug_log('RPG - ' .. player.name .. ' got fee: ' .. fee) + Public.debug_log('RPG - ' .. player.name .. ' got fee: ' .. fee) amount = math.round(amount, 3) - fee if rpg_extra.difficulty then amount = amount + rpg_extra.difficulty end - RPG.debug_log('RPG - ' .. player.name .. ' got after fee: ' .. amount) + Public.debug_log('RPG - ' .. player.name .. ' got after fee: ' .. amount) else - RPG.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) + Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) end - rpg_t[player.index].xp = math.round(rpg_t[player.index].xp + amount, 3) - rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount + rpg_t.xp = math.round(rpg_t.xp + amount, 3) + rpg_t.xp_since_last_floaty_text = rpg_t.xp_since_last_floaty_text + amount - if not experience_levels[rpg_t[player.index].level + 1] then + if not experience_levels[rpg_t.level + 1] then return end @@ -686,15 +702,15 @@ function Public.gain_xp(player, amount, added_to_pool, text) if f and f.valid then local d = Gui.get_data(f) if d.exp_gui and d.exp_gui.valid then - d.exp_gui.caption = math.floor(rpg_t[player.index].xp) + d.exp_gui.caption = math.floor(rpg_t.xp) end end - if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then + if rpg_t.xp >= experience_levels[rpg_t.level + 1] then level_up(player) end - if rpg_t[player.index].last_floaty_text > game.tick then + if rpg_t.last_floaty_text > game.tick then if not text then return end @@ -703,7 +719,7 @@ function Public.gain_xp(player, amount, added_to_pool, text) if text then text_to_draw = '+' .. math.floor(amount) .. ' xp' else - text_to_draw = '+' .. math.floor(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp' + text_to_draw = '+' .. math.floor(rpg_t.xp_since_last_floaty_text) .. ' xp' end player.create_local_flying_text { @@ -714,12 +730,12 @@ function Public.gain_xp(player, amount, added_to_pool, text) speed = 2 } - rpg_t[player.index].xp_since_last_floaty_text = 0 - rpg_t[player.index].last_floaty_text = game.tick + visuals_delay + rpg_t.xp_since_last_floaty_text = 0 + rpg_t.last_floaty_text = game.tick + visuals_delay end function Public.global_pool(players, count) - local rpg_extra = RPG.get('rpg_extra') + local rpg_extra = Public.get('rpg_extra') if not rpg_extra.global_pool then return @@ -739,7 +755,7 @@ function Public.global_pool(players, count) local share = pool / count - RPG.debug_log('RPG - Share per player:' .. share) + Public.debug_log('RPG - Share per player:' .. share) for i = 1, #players do local p = players[i] @@ -750,14 +766,14 @@ function Public.global_pool(players, count) else share = share / 10 rpg_extra.leftover_pool = rpg_extra.leftover_pool + share - RPG.debug_log('RPG - player capped: ' .. p.name .. '. Amount to pool:' .. share) + Public.debug_log('RPG - player capped: ' .. p.name .. '. Amount to pool:' .. share) end else local message = ({'rpg_functions.pool_reward', p.name}) Alert.alert_player_warning(p, 10, message) share = share / 10 rpg_extra.leftover_pool = rpg_extra.leftover_pool + share - RPG.debug_log('RPG - player AFK: ' .. p.name .. '. Amount to pool:' .. share) + Public.debug_log('RPG - player AFK: ' .. p.name .. '. Amount to pool:' .. share) end end @@ -801,5 +817,3 @@ function Public.distribute_pool() end Public.add_to_global_pool = add_to_global_pool - -return Public diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index 51b100a3..fe05cc05 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -3,29 +3,24 @@ local P = require 'player_modifiers' local Gui = require 'utils.gui' --RPG Modules -local Functions = require 'modules.rpg.functions' -local RPG = require 'modules.rpg.table' -local Settings = require 'modules.rpg.settings' - -local Public = {} - -local classes = RPG.classes +local Public = require 'modules.rpg.table' +local classes = Public.classes --RPG Settings -local experience_levels = RPG.experience_levels +local experience_levels = Public.experience_levels --RPG Frames -local main_frame_name = RPG.main_frame_name -local draw_main_frame_name = RPG.draw_main_frame_name -local settings_button_name = RPG.settings_button_name -local settings_frame_name = RPG.settings_frame_name -local discard_button_name = RPG.discard_button_name -local save_button_name = RPG.save_button_name -local spell_gui_button_name = RPG.spell_gui_button_name -local spell_gui_frame_name = RPG.spell_gui_frame_name -local spell1_button_name = RPG.spell1_button_name -local spell2_button_name = RPG.spell2_button_name -local spell3_button_name = RPG.spell3_button_name +local main_frame_name = Public.main_frame_name +local draw_main_frame_name = Public.draw_main_frame_name +local settings_button_name = Public.settings_button_name +local settings_frame_name = Public.settings_frame_name +local discard_button_name = Public.discard_button_name +local save_button_name = Public.save_button_name +local spell_gui_button_name = Public.spell_gui_button_name +local spell_gui_frame_name = Public.spell_gui_frame_name +local spell1_button_name = Public.spell1_button_name +local spell2_button_name = Public.spell2_button_name +local spell3_button_name = Public.spell3_button_name local sub = string.sub @@ -44,11 +39,11 @@ function Public.draw_gui_char_button(player) end function Public.update_char_button(player) - local rpg_t = RPG.get('rpg_t') + local rpg_t = Public.get_value_from_player(player.index) if not player.gui.top[draw_main_frame_name] then Public.draw_gui_char_button(player) end - if rpg_t[player.index].points_left > 0 then + if rpg_t.points_left > 0 then player.gui.top[draw_main_frame_name].style.font_color = {245, 0, 0} else player.gui.top[draw_main_frame_name].style.font_color = {175, 175, 175} @@ -56,13 +51,13 @@ function Public.update_char_button(player) end local function get_class(player) - local rpg_t = RPG.get('rpg_t') - local average = (rpg_t[player.index].strength + rpg_t[player.index].magicka + rpg_t[player.index].dexterity + rpg_t[player.index].vitality) / 4 + local rpg_t = Public.get_value_from_player(player.index) + local average = (rpg_t.strength + rpg_t.magicka + rpg_t.dexterity + rpg_t.vitality) / 4 local high_attribute = 0 local high_attribute_name = '' for _, attribute in pairs({'strength', 'magicka', 'dexterity', 'vitality'}) do - if rpg_t[player.index][attribute] > high_attribute then - high_attribute = rpg_t[player.index][attribute] + if rpg_t[attribute] > high_attribute then + high_attribute = rpg_t[attribute] high_attribute_name = attribute end end @@ -116,10 +111,10 @@ local function add_elem_stat(element, value, width, height, font, tooltip, name, end local function add_gui_increase_stat(element, name, player) - local rpg_t = RPG.get('rpg_t') + local rpg_t = Public.get_value_from_player(player.index) local sprite = 'virtual-signal/signal-red' local symbol = '✚' - if rpg_t[player.index].points_left <= 0 then + if rpg_t.points_left <= 0 then sprite = 'virtual-signal/signal-black' end local e = element.add({type = 'sprite-button', name = name, caption = symbol, sprite = sprite}) @@ -133,7 +128,7 @@ local function add_gui_increase_stat(element, name, player) e.style.vertical_align = 'center' e.style.padding = 0 e.style.margin = 0 - e.tooltip = ({'rpg_gui.allocate_info', tostring(RPG.points_per_level)}) + e.tooltip = ({'rpg_gui.allocate_info', tostring(Public.points_per_level)}) return e end @@ -182,8 +177,8 @@ local function draw_main_frame(player, location) end local data = {} - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) local inside_frame = main_frame.add { @@ -231,21 +226,21 @@ local function draw_main_frame(player, location) add_gui_description(scroll_table, ({'rpg_gui.level_name'}), 80) if rpg_extra.level_limit_enabled then - local level_tooltip = ({'rpg_gui.level_limit', Functions.level_limit_exceeded(player, true)}) - add_gui_stat(scroll_table, rpg_t[player.index].level, 80, level_tooltip) + local level_tooltip = ({'rpg_gui.level_limit', Public.level_limit_exceeded(player, true)}) + add_gui_stat(scroll_table, rpg_t.level, 80, level_tooltip) else - add_gui_stat(scroll_table, rpg_t[player.index].level, 80) + add_gui_stat(scroll_table, rpg_t.level, 80) end add_gui_description(scroll_table, ({'rpg_gui.experience_name'}), 100) - local exp_gui = add_gui_stat(scroll_table, math.floor(rpg_t[player.index].xp), 125, ({'rpg_gui.gain_info_tooltip'})) + local exp_gui = add_gui_stat(scroll_table, math.floor(rpg_t.xp), 125, ({'rpg_gui.gain_info_tooltip'})) data.exp_gui = exp_gui add_gui_description(scroll_table, ' ', 75) add_gui_description(scroll_table, ' ', 75) add_gui_description(scroll_table, ({'rpg_gui.next_level_name'}), 100) - add_gui_stat(scroll_table, experience_levels[rpg_t[player.index].level + 1], 125, ({'rpg_gui.gain_info_tooltip'})) + add_gui_stat(scroll_table, experience_levels[rpg_t.level + 1], 125, ({'rpg_gui.gain_info_tooltip'})) add_separator(scroll_pane, 400) @@ -258,24 +253,24 @@ local function draw_main_frame(player, location) local w2 = 63 add_gui_description(left_bottom_table, ({'rpg_gui.strength_name'}), w1, ({'rpg_gui.strength_tooltip'})) - add_gui_stat(left_bottom_table, rpg_t[player.index].strength, w2, ({'rpg_gui.strength_tooltip'})) + add_gui_stat(left_bottom_table, rpg_t.strength, w2, ({'rpg_gui.strength_tooltip'})) add_gui_increase_stat(left_bottom_table, 'strength', player) add_gui_description(left_bottom_table, ({'rpg_gui.magic_name'}), w1, ({'rpg_gui.magic_tooltip'})) - add_gui_stat(left_bottom_table, rpg_t[player.index].magicka, w2, ({'rpg_gui.magic_tooltip'})) + add_gui_stat(left_bottom_table, rpg_t.magicka, w2, ({'rpg_gui.magic_tooltip'})) add_gui_increase_stat(left_bottom_table, 'magicka', player) add_gui_description(left_bottom_table, ({'rpg_gui.dexterity_name'}), w1, ({'rpg_gui.dexterity_tooltip'})) - add_gui_stat(left_bottom_table, rpg_t[player.index].dexterity, w2, ({'rpg_gui.dexterity_tooltip'})) + add_gui_stat(left_bottom_table, rpg_t.dexterity, w2, ({'rpg_gui.dexterity_tooltip'})) add_gui_increase_stat(left_bottom_table, 'dexterity', player) add_gui_description(left_bottom_table, ({'rpg_gui.vitality_name'}), w1, ({'rpg_gui.vitality_tooltip'})) - add_gui_stat(left_bottom_table, rpg_t[player.index].vitality, w2, ({'rpg_gui.vitality_tooltip'})) + add_gui_stat(left_bottom_table, rpg_t.vitality, w2, ({'rpg_gui.vitality_tooltip'})) add_gui_increase_stat(left_bottom_table, 'vitality', player) add_gui_description(left_bottom_table, ({'rpg_gui.points_to_dist'}), w1) - add_gui_stat(left_bottom_table, rpg_t[player.index].points_left, w2, nil, nil, {200, 0, 0}) + add_gui_stat(left_bottom_table, rpg_t.points_left, w2, nil, nil, {200, 0, 0}) add_gui_description(left_bottom_table, ' ', w2) add_gui_description(left_bottom_table, ' ', 40) @@ -320,14 +315,14 @@ local function draw_main_frame(player, location) end if rpg_extra.enable_mana then - local mana = rpg_t[player.index].mana - local mana_max = rpg_t[player.index].mana_max + local mana = rpg_t.mana + local mana_max = rpg_t.mana_max local mana_tip = ({'rpg_gui.mana_tooltip'}) add_gui_description(left_bottom_table, ({'rpg_gui.mana_name'}), w1, mana_tip) local mana_regen_tip = ({'rpg_gui.mana_regen_current'}) local mana_max_regen_tip - if rpg_t[player.index].mana_max >= rpg_extra.mana_limit then + if rpg_t.mana_max >= rpg_extra.mana_limit then mana_max_regen_tip = ({'rpg_gui.mana_max_limit'}) else mana_max_regen_tip = ({'rpg_gui.mana_max'}) @@ -353,14 +348,14 @@ local function draw_main_frame(player, location) add_gui_description(right_bottom_table, ' ', w0) add_gui_description(right_bottom_table, ({'rpg_gui.melee_name'}), w1) - local melee_damage_value = math.round(100 * (1 + Functions.get_melee_modifier(player))) .. '%' + local melee_damage_value = math.round(100 * (1 + Public.get_melee_modifier(player))) .. '%' local melee_damage_tooltip if rpg_extra.enable_one_punch then melee_damage_tooltip = ({ 'rpg_gui.one_punch_chance', - Functions.get_life_on_hit(player), - Functions.get_one_punch_chance(player), - Functions.get_extra_following_robots(player) + Public.get_life_on_hit(player), + Public.get_one_punch_chance(player), + Public.get_extra_following_robots(player) }) else melee_damage_tooltip = ({'rpg_gui.one_punch_disabled'}) @@ -380,7 +375,7 @@ local function draw_main_frame(player, location) player.character_loot_pickup_distance_bonus, player.character_item_pickup_distance_bonus, player.character_resource_reach_distance_bonus, - Functions.get_magicka(player) + Public.get_magicka(player) }) add_gui_description(right_bottom_table, ' ', w0) @@ -404,17 +399,17 @@ local function draw_main_frame(player, location) add_gui_description(right_bottom_table, ' ', w0) add_gui_description(right_bottom_table, ({'rpg_gui.health_bonus_name'}), w1) local health_bonus_value = '+ ' .. math.round((player.force.character_health_bonus + player.character_health_bonus)) - local health_tooltip = ({'rpg_gui.health_tooltip', Functions.get_heal_modifier(player)}) + local health_tooltip = ({'rpg_gui.health_tooltip', Public.get_heal_modifier(player)}) add_gui_stat(right_bottom_table, health_bonus_value, w2, health_tooltip) add_gui_description(right_bottom_table, ' ', w0) if rpg_extra.enable_mana then add_gui_description(right_bottom_table, ({'rpg_gui.mana_bonus'}), w1) - local mana_bonus_value = '+ ' .. (math.floor(Functions.get_mana_modifier(player) * 10) / 10) + local mana_bonus_value = '+ ' .. (math.floor(Public.get_mana_modifier(player) * 10) / 10) local mana_bonus_tooltip = ({ 'rpg_gui.mana_regen_bonus', - (math.floor(Functions.get_mana_modifier(player) * 10) / 10) + (math.floor(Public.get_mana_modifier(player) * 10) / 10) }) add_gui_stat(right_bottom_table, mana_bonus_value, w2, mana_bonus_tooltip) end @@ -432,15 +427,15 @@ function Public.draw_level_text(player) return end - local rpg_t = RPG.get('rpg_t') + local rpg_t = Public.get_value_from_player(player.index) - if not rpg_t[player.index] then + if not rpg_t then return end - if rpg_t[player.index].text then - rendering.destroy(rpg_t[player.index].text) - rpg_t[player.index].text = nil + if rpg_t.text then + rendering.destroy(rpg_t.text) + rpg_t.text = nil end local players = {} @@ -453,9 +448,9 @@ function Public.draw_level_text(player) return end - rpg_t[player.index].text = + rpg_t.text = rendering.draw_text { - text = 'lvl ' .. rpg_t[player.index].level, + text = 'lvl ' .. rpg_t.level, surface = player.surface, target = player.character, target_offset = {0, -3.25}, @@ -474,14 +469,14 @@ function Public.draw_level_text(player) end function Public.update_player_stats(player) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') - local strength = rpg_t[player.index].strength - 10 + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) + local strength = rpg_t.strength - 10 P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', math.round(strength * 0.2, 3)) P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', math.round(strength * 0.007, 3)) P.update_single_modifier(player, 'character_maximum_following_robot_count_bonus', 'rpg', math.round(strength / 2 * 0.03, 3)) - local magic = rpg_t[player.index].magicka - 10 + local magic = rpg_t.magicka - 10 local v = magic * 0.22 P.update_single_modifier(player, 'character_build_distance_bonus', 'rpg', math.min(60, math.round(v * 0.25, 3))) P.update_single_modifier(player, 'character_item_drop_distance_bonus', 'rpg', math.min(60, math.round(v * 0.25, 3))) @@ -489,16 +484,16 @@ function Public.update_player_stats(player) P.update_single_modifier(player, 'character_loot_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.22, 3))) P.update_single_modifier(player, 'character_item_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.25, 3))) P.update_single_modifier(player, 'character_resource_reach_distance_bonus', 'rpg', math.min(20, math.round(v * 0.15, 3))) - if rpg_t[player.index].mana_max >= rpg_extra.mana_limit then - rpg_t[player.index].mana_max = rpg_extra.mana_limit + if rpg_t.mana_max >= rpg_extra.mana_limit then + rpg_t.mana_max = rpg_extra.mana_limit else - rpg_t[player.index].mana_max = math.round((magic) * 2, 3) + rpg_t.mana_max = math.round((magic) * 2, 3) end - local dexterity = rpg_t[player.index].dexterity - 10 + local dexterity = rpg_t.dexterity - 10 P.update_single_modifier(player, 'character_running_speed_modifier', 'rpg', math.round(dexterity * 0.0015, 3)) P.update_single_modifier(player, 'character_crafting_speed_modifier', 'rpg', math.round(dexterity * 0.015, 3)) - P.update_single_modifier(player, 'character_health_bonus', 'rpg', math.round((rpg_t[player.index].vitality - 10) * 6, 3)) + P.update_single_modifier(player, 'character_health_bonus', 'rpg', math.round((rpg_t.vitality - 10) * 6, 3)) P.update_player_modifiers(player) end @@ -572,50 +567,50 @@ Gui.on_click( local one_punch_gui_input = data.one_punch_gui_input local auto_allocate_gui_input = data.auto_allocate_gui_input - local rpg_t = RPG.get('rpg_t') + local rpg_t = Public.get_value_from_player(player.index) if frame and frame.valid then if auto_allocate_gui_input and auto_allocate_gui_input.valid and auto_allocate_gui_input.selected_index then - rpg_t[player.index].allocate_index = auto_allocate_gui_input.selected_index + rpg_t.allocate_index = auto_allocate_gui_input.selected_index end if one_punch_gui_input and one_punch_gui_input.valid then if not one_punch_gui_input.state then - rpg_t[player.index].one_punch = false + rpg_t.one_punch = false elseif one_punch_gui_input.state then - rpg_t[player.index].one_punch = true + rpg_t.one_punch = true end end if stone_path_gui_input and stone_path_gui_input.valid then if not stone_path_gui_input.state then - rpg_t[player.index].stone_path = false + rpg_t.stone_path = false elseif stone_path_gui_input.state then - rpg_t[player.index].stone_path = true + rpg_t.stone_path = true end end if enable_entity_gui_input and enable_entity_gui_input.valid then if not enable_entity_gui_input.state then - rpg_t[player.index].enable_entity_spawn = false + rpg_t.enable_entity_spawn = false elseif enable_entity_gui_input.state then - rpg_t[player.index].enable_entity_spawn = true + rpg_t.enable_entity_spawn = true end end if flame_boots_gui_input and flame_boots_gui_input.valid then if not flame_boots_gui_input.state then - rpg_t[player.index].flame_boots = false + rpg_t.flame_boots = false elseif flame_boots_gui_input.state then - rpg_t[player.index].flame_boots = true + rpg_t.flame_boots = true end end if explosive_bullets_gui_input and explosive_bullets_gui_input.valid then if not explosive_bullets_gui_input.state then - rpg_t[player.index].explosive_bullets = false + rpg_t.explosive_bullets = false elseif explosive_bullets_gui_input.state then - rpg_t[player.index].explosive_bullets = true + rpg_t.explosive_bullets = true end end @@ -649,37 +644,37 @@ Gui.on_click( end end if conjure_gui_input and conjure_gui_input.valid and conjure_gui_input.selected_index then - rpg_t[player.index].dropdown_select_index = conjure_gui_input.selected_index + rpg_t.dropdown_select_index = conjure_gui_input.selected_index end if spell_gui_input1 and spell_gui_input1.valid and spell_gui_input1.selected_index then - rpg_t[player.index].dropdown_select_index1 = spell_gui_input1.selected_index + rpg_t.dropdown_select_index1 = spell_gui_input1.selected_index end if spell_gui_input2 and spell_gui_input2.valid and spell_gui_input2.selected_index then - rpg_t[player.index].dropdown_select_index2 = spell_gui_input2.selected_index + rpg_t.dropdown_select_index2 = spell_gui_input2.selected_index end if spell_gui_input3 and spell_gui_input3.valid and spell_gui_input3.selected_index then - rpg_t[player.index].dropdown_select_index3 = spell_gui_input3.selected_index + rpg_t.dropdown_select_index3 = spell_gui_input3.selected_index end if player.gui.screen[spell_gui_frame_name] then - Settings.update_spell_gui(player, nil) + Public.update_spell_gui(player, nil) end if reset_gui_input and reset_gui_input.valid and reset_gui_input.state then - if not rpg_t[player.index].reset then - rpg_t[player.index].allocate_index = 1 - rpg_t[player.index].reset = true - Functions.rpg_reset_player(player, true) + if not rpg_t.reset then + rpg_t.allocate_index = 1 + rpg_t.reset = true + Public.rpg_reset_player(player, true) end end if health_bar_gui_input and health_bar_gui_input.valid then if not health_bar_gui_input.state then - rpg_t[player.index].show_bars = false - Functions.update_health(player) - Functions.update_mana(player) + rpg_t.show_bars = false + Public.update_health(player) + Public.update_mana(player) elseif health_bar_gui_input.state then - rpg_t[player.index].show_bars = true - Functions.update_health(player) - Functions.update_mana(player) + rpg_t.show_bars = true + Public.update_health(player) + Public.update_mana(player) end end @@ -718,7 +713,7 @@ Gui.on_click( return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end @@ -727,7 +722,7 @@ Gui.on_click( Gui.remove_data_recursively(frame) frame.destroy() else - Settings.extra_settings(player) + Public.extra_settings(player) end end ) @@ -742,7 +737,7 @@ Gui.on_click( return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end @@ -751,7 +746,7 @@ Gui.on_click( Gui.remove_data_recursively(frame) frame.destroy() else - Settings.spell_gui_settings(player) + Public.spell_gui_settings(player) end end ) @@ -766,13 +761,13 @@ Gui.on_click( return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end if frame and frame.valid then - Settings.update_spell_gui(player, 1) + Public.update_spell_gui(player, 1) end end ) @@ -787,13 +782,13 @@ Gui.on_click( return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end if frame and frame.valid then - Settings.update_spell_gui(player, 2) + Public.update_spell_gui(player, 2) end end ) @@ -808,13 +803,13 @@ Gui.on_click( return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end if frame and frame.valid then - Settings.update_spell_gui(player, 3) + Public.update_spell_gui(player, 3) end end ) diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index d28cdef9..ea8974b2 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -1,3 +1,5 @@ +--RPG Modules +local Public = require 'modules.rpg.core' local Gui = require 'utils.gui' local Event = require 'utils.event' local AntiGrief = require 'antigrief' @@ -9,21 +11,14 @@ local Explosives = require 'modules.explosives' local WD = require 'modules.wave_defense.table' local Math2D = require 'math2d' ---RPG Modules -require 'modules.rpg.commands' -local ExplosiveBullets = require 'modules.rpg.explosive_gun_bullets' -local RPG = require 'modules.rpg.table' -local Functions = require 'modules.rpg.functions' -local RPG_GUI = require 'modules.rpg.gui' - --RPG Settings -local enemy_types = RPG.enemy_types -local die_cause = RPG.die_cause -local points_per_level = RPG.points_per_level -local nth_tick = RPG.nth_tick +local enemy_types = Public.enemy_types +local die_cause = Public.die_cause +local points_per_level = Public.points_per_level +local nth_tick = Public.nth_tick --RPG Frames -local main_frame_name = RPG.main_frame_name +local main_frame_name = Public.main_frame_name local sub = string.sub @@ -50,7 +45,7 @@ local function on_gui_click(event) end end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end @@ -68,7 +63,7 @@ local function on_gui_click(event) return end - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) local index = element.name if not rpg_t[index] then @@ -88,12 +83,12 @@ local function on_gui_click(event) if not rpg_t.reset then rpg_t.total = rpg_t.total + count end - RPG_GUI.toggle(player, true) - RPG_GUI.update_player_stats(player) + Public.toggle(player, true) + Public.update_player_stats(player) elseif event.button == defines.mouse_button_type.right then for _ = 1, points_per_level, 1 do if rpg_t.points_left <= 0 then - RPG_GUI.toggle(player, true) + Public.toggle(player, true) return end rpg_t.points_left = rpg_t.points_left - 1 @@ -101,14 +96,14 @@ local function on_gui_click(event) if not rpg_t.reset then rpg_t.total = rpg_t.total + 1 end - RPG_GUI.update_player_stats(player) + Public.update_player_stats(player) end - RPG_GUI.toggle(player, true) + Public.toggle(player, true) return end if rpg_t.points_left <= 0 then - RPG_GUI.toggle(player, true) + Public.toggle(player, true) return end rpg_t.points_left = rpg_t.points_left - 1 @@ -116,8 +111,8 @@ local function on_gui_click(event) if not rpg_t.reset then rpg_t.total = rpg_t.total + 1 end - RPG_GUI.update_player_stats(player) - RPG_GUI.toggle(player, true) + Public.update_player_stats(player) + Public.toggle(player, true) end local function train_type_cause(cause) @@ -201,13 +196,13 @@ local function on_entity_died(event) end end end - Functions.gain_xp(entity.last_user, 1) - Functions.reward_mana(entity.last_user, 1) + Public.gain_xp(entity.last_user, 1) + Public.reward_mana(entity.last_user, 1) return end end - local rpg_extra = RPG.get('rpg_extra') + local rpg_extra = Public.get('rpg_extra') if rpg_extra.enable_wave_defense then if rpg_extra.rpg_xp_yield['big-biter'] <= 16 then @@ -245,10 +240,10 @@ local function on_entity_died(event) end if rpg_extra.turret_kills_to_global_pool then - Functions.add_to_global_pool(amount, false) + Public.add_to_global_pool(amount, false) end else - Functions.add_to_global_pool(0.5, false) + Public.add_to_global_pool(0.5, false) end return end @@ -284,13 +279,13 @@ local function on_entity_died(event) amount = rpg_extra.rpg_xp_yield[entity.name] end if rpg_extra.turret_kills_to_global_pool then - local inserted = Functions.add_to_global_pool(amount, true) - Functions.gain_xp(player, inserted, true) + local inserted = Public.add_to_global_pool(amount, true) + Public.gain_xp(player, inserted, true) else - Functions.gain_xp(player, amount) + Public.gain_xp(player, amount) end else - Functions.gain_xp(player, 0.5 * (1 / health_pool[2])) + Public.gain_xp(player, 0.5 * (1 / health_pool[2])) end end return @@ -303,13 +298,13 @@ local function on_entity_died(event) if rpg_extra.rpg_xp_yield[entity.name] then local amount = rpg_extra.rpg_xp_yield[entity.name] if rpg_extra.turret_kills_to_global_pool then - local inserted = Functions.add_to_global_pool(amount, true) - Functions.gain_xp(player, inserted, true) + local inserted = Public.add_to_global_pool(amount, true) + Public.gain_xp(player, inserted, true) else - Functions.gain_xp(player, amount) + Public.gain_xp(player, amount) end else - Functions.gain_xp(player, 0.5) + Public.gain_xp(player, 0.5) end end end @@ -317,7 +312,7 @@ end local function regen_health_player(players) for i = 1, #players do local player = players[i] - local heal_per_tick = Functions.get_heal_modifier(player) + local heal_per_tick = Public.get_heal_modifier(player) if heal_per_tick <= 0 then goto continue end @@ -330,16 +325,16 @@ local function regen_health_player(players) ::continue:: - Functions.update_health(player) + Public.update_health(player) end end local function regen_mana_player(players) for i = 1, #players do local player = players[i] - local mana_per_tick = Functions.get_mana_modifier(player) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get_value_from_player(player.index) + local mana_per_tick = Public.get_mana_modifier(player) + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) if mana_per_tick <= 0.1 then mana_per_tick = rpg_extra.mana_per_tick end @@ -366,12 +361,16 @@ local function regen_mana_player(players) ::continue:: - Functions.update_mana(player) + Public.update_mana(player) end end local function give_player_flameboots(player) - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) + if not rpg_t then + return + end + if not rpg_t.flame_boots then return end @@ -531,9 +530,9 @@ local function on_entity_damaged(event) cause.get_inventory(defines.inventory.character_ammo)[cause.selected_gun_index].valid_for_read or cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index].valid_for_read then - local is_explosive_bullets_enabled = RPG.get_explosive_bullets() + local is_explosive_bullets_enabled = Public.get_explosive_bullets() if is_explosive_bullets_enabled then - ExplosiveBullets.explosive_bullets(event) + Public.explosive_bullets(event) end return end @@ -543,7 +542,7 @@ local function on_entity_damaged(event) local p = cause.player - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(p.surface.name, 0, #surface_name) ~= surface_name then return end @@ -571,13 +570,13 @@ local function on_entity_damaged(event) end end - Functions.reward_mana(cause.player, 2) + Public.reward_mana(cause.player, 2) --Grant the player life-on-hit. - cause.health = cause.health + Functions.get_life_on_hit(cause.player) + cause.health = cause.health + Public.get_life_on_hit(cause.player) --Calculate modified damage. - local damage = event.original_damage_amount + event.original_damage_amount * Functions.get_melee_modifier(cause.player) + local damage = event.original_damage_amount + event.original_damage_amount * Public.get_melee_modifier(cause.player) if entity.prototype.resistances then if entity.prototype.resistances.physical then damage = damage - entity.prototype.resistances.physical.decrease @@ -589,13 +588,13 @@ local function on_entity_damaged(event) damage = 1 end - local enable_one_punch = RPG.get('rpg_extra').enable_one_punch - local rpg_t = RPG.get_value_from_player(cause.player.index) + local enable_one_punch = Public.get('rpg_extra').enable_one_punch + local rpg_t = Public.get_value_from_player(cause.player.index) --Cause a one punch. if enable_one_punch then if rpg_t.one_punch then - if math.random(0, 999) < Functions.get_one_punch_chance(cause.player) * 10 then + if math.random(0, 999) < Public.get_one_punch_chance(cause.player) * 10 then one_punch(cause, entity, damage) if entity.valid then entity.die(entity.force.name, cause) @@ -662,9 +661,9 @@ local function on_entity_damaged(event) entity.die(cause.force.name, cause) end - local is_explosive_bullets_enabled = RPG.get_explosive_bullets() + local is_explosive_bullets_enabled = Public.get_explosive_bullets() if is_explosive_bullets_enabled then - ExplosiveBullets.explosive_bullets(event) + Public.explosive_bullets(event) end end @@ -693,10 +692,10 @@ local function on_player_repaired_entity(event) return end - Functions.gain_xp(player, 0.05) - Functions.reward_mana(player, 0.2) + Public.gain_xp(player, 0.05) + Public.reward_mana(player, 0.2) - local repair_speed = Functions.get_magicka(player) + local repair_speed = Public.get_magicka(player) if repair_speed <= 0 then return end @@ -713,12 +712,12 @@ local function on_player_rotated_entity(event) return end - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) if rpg_t.rotated_entity_delay > game.tick then return end rpg_t.rotated_entity_delay = game.tick + 20 - Functions.gain_xp(player, 0.20) + Public.gain_xp(player, 0.20) end local function on_player_changed_position(event) @@ -727,7 +726,7 @@ local function on_player_changed_position(event) return end - local enable_flame_boots = RPG.get('rpg_extra').enable_flame_boots + local enable_flame_boots = Public.get('rpg_extra').enable_flame_boots if enable_flame_boots then give_player_flameboots(player) @@ -742,7 +741,7 @@ local function on_player_changed_position(event) if player.character.driving then return end - Functions.gain_xp(player, 1.0) + Public.gain_xp(player, 1.0) end local building_and_mining_blacklist = { @@ -758,7 +757,7 @@ local function on_player_died(event) return end - RPG_GUI.remove_frame(player) + Public.remove_frame(player) end local function on_pre_player_left_game(event) @@ -768,7 +767,7 @@ local function on_pre_player_left_game(event) return end - RPG_GUI.remove_frame(player) + Public.remove_frame(player) end local function on_pre_player_mined_item(event) @@ -788,12 +787,12 @@ local function on_pre_player_mined_item(event) return end - local surface_name = RPG.get('rpg_extra').surface_name + local surface_name = Public.get('rpg_extra').surface_name if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) if rpg_t.last_mined_entity_position.x == event.entity.position.x and rpg_t.last_mined_entity_position.y == event.entity.position.y then return end @@ -817,8 +816,8 @@ local function on_pre_player_mined_item(event) end end - Functions.gain_xp(player, xp_amount) - Functions.reward_mana(player, 0.5 * distance_multiplier) + Public.gain_xp(player, xp_amount) + Public.reward_mana(player, 0.5 * distance_multiplier) end local function on_player_crafted_item(event) @@ -834,7 +833,7 @@ local function on_player_crafted_item(event) return end - local rpg_extra = RPG.get('rpg_extra') + local rpg_extra = Public.get('rpg_extra') local is_blacklisted = rpg_extra.tweaked_crafting_items local tweaked_crafting_items_enabled = rpg_extra.tweaked_crafting_items_enabled @@ -850,41 +849,41 @@ local function on_player_crafted_item(event) end end - Functions.gain_xp(player, event.recipe.energy * amount) - Functions.reward_mana(player, amount) + Public.gain_xp(player, event.recipe.energy * amount) + Public.reward_mana(player, amount) end local function on_player_respawned(event) local player = game.players[event.player_index] - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) if not rpg_t then - Functions.rpg_reset_player(player) + Public.rpg_reset_player(player) return end - RPG_GUI.update_player_stats(player) - RPG_GUI.draw_level_text(player) - Functions.update_health(player) - Functions.update_mana(player) + Public.update_player_stats(player) + Public.draw_level_text(player) + Public.update_health(player) + Public.update_mana(player) end local function on_player_joined_game(event) local player = game.players[event.player_index] - local rpg_t = RPG.get_value_from_player(player.index) - local rpg_extra = RPG.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) + local rpg_extra = Public.get('rpg_extra') if not rpg_t then - Functions.rpg_reset_player(player) + Public.rpg_reset_player(player) if rpg_extra.reward_new_players > 10 then - Functions.gain_xp(player, rpg_extra.reward_new_players) + Public.gain_xp(player, rpg_extra.reward_new_players) end end for _, p in pairs(game.connected_players) do - RPG_GUI.draw_level_text(p) + Public.draw_level_text(p) end - RPG_GUI.draw_gui_char_button(player) + Public.draw_gui_char_button(player) if not player.character then return end - RPG_GUI.update_player_stats(player) + Public.update_player_stats(player) end local function create_projectile(surface, name, position, force, target, max_range) @@ -985,14 +984,14 @@ local function tame_unit_effects(player, entity) end local function on_player_used_capsule(event) - local enable_mana = RPG.get('rpg_extra').enable_mana - local surface_name = RPG.get('rpg_extra').surface_name + local enable_mana = Public.get('rpg_extra').enable_mana + local surface_name = Public.get('rpg_extra').surface_name if not enable_mana then return end - local conjure_items = RPG.get_spells() - local projectile_types = RPG.get_projectiles + local conjure_items = Public.get_spells() + local projectile_types = Public.get_projectiles local player = game.players[event.player_index] if not player or not player.valid then @@ -1019,7 +1018,7 @@ local function on_player_used_capsule(event) return end - local rpg_t = RPG.get_value_from_player(player.index) + local rpg_t = Public.get_value_from_player(player.index) if not rpg_t.enable_entity_spawn then return @@ -1092,11 +1091,11 @@ local function on_player_used_capsule(event) force = 'player' end if obj_name == 'suicidal_comfylatron' then - Functions.suicidal_comfylatron(position, surface) + Public.suicidal_comfylatron(position, surface) p(({'rpg_main.suicidal_comfylatron', 'Suicidal Comfylatron'}), Color.success) rpg_t.mana = rpg_t.mana - object.mana_cost elseif obj_name == 'repair_aoe' then - local ents = Functions.repair_aoe(player, position) + local ents = Public.repair_aoe(player, position) p(({'rpg_main.repair_aoe', ents}), Color.success) rpg_t.mana = rpg_t.mana - object.mana_cost elseif obj_name == 'pointy_explosives' then @@ -1118,7 +1117,7 @@ local function on_player_used_capsule(event) elseif obj_name == 'warp-gate' then player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface) rpg_t.mana = 0 - Functions.damage_player_over_time(player, math.random(8, 16)) + Public.damage_player_over_time(player, math.random(8, 16)) player.play_sound {path = 'utility/armor_insert', volume_modifier = 1} p(({'rpg_main.warped_ok'}), Color.info) rpg_t.mana = rpg_t.mana - object.mana_cost @@ -1179,14 +1178,14 @@ local function on_player_used_capsule(event) local msg = player.name .. ' casted ' .. obj_name .. '. ' rpg_t.last_spawned = game.tick + object.tick - Functions.update_mana(player) + Public.update_mana(player) local reward_xp = object.mana_cost * 0.085 if reward_xp < 1 then reward_xp = 1 end - Functions.gain_xp(player, reward_xp) + Public.gain_xp(player, reward_xp) AntiGrief.insert_into_capsule_history(player, position, msg) @@ -1195,18 +1194,22 @@ end local function on_player_changed_surface(event) local player = game.get_player(event.player_index) - RPG_GUI.draw_level_text(player) + Public.draw_level_text(player) +end + +local function on_player_removed(event) + Public.remove_player(event.player_index) end local function tick() local ticker = game.tick local count = #game.connected_players local players = game.connected_players - local enable_flameboots = RPG.get('rpg_extra').enable_flameboots - local enable_mana = RPG.get('rpg_extra').enable_mana + local enable_flameboots = Public.get('rpg_extra').enable_flameboots + local enable_mana = Public.get('rpg_extra').enable_mana if ticker % nth_tick == 0 then - Functions.global_pool(players, count) + Public.global_pool(players, count) end if ticker % 30 == 0 then @@ -1240,7 +1243,7 @@ if _DEBUG then return end p('Distributed ' .. param .. ' of xp.') - Functions.give_xp(param) + Public.give_xp(param) end end end @@ -1255,10 +1258,14 @@ Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.add(defines.events.on_player_crafted_item, on_player_crafted_item) Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_player_created, on_player_joined_game) Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity) Event.add(defines.events.on_player_respawned, on_player_respawned) Event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity) Event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item) Event.add(defines.events.on_player_used_capsule, on_player_used_capsule) Event.add(defines.events.on_player_changed_surface, on_player_changed_surface) +Event.add(defines.events.on_player_removed, on_player_removed) Event.on_nth_tick(10, tick) + +return Public diff --git a/modules/rpg/settings.lua b/modules/rpg/settings.lua index 89c6a79e..b9c2d7e7 100644 --- a/modules/rpg/settings.lua +++ b/modules/rpg/settings.lua @@ -1,18 +1,18 @@ -local RPG = require 'modules.rpg.table' +local Public = require 'modules.rpg.table' local Gui = require 'utils.gui' local P = require 'player_modifiers' local Session = require 'utils.datastore.session_data' -local Public = {} +local settings_frame_name = Public.settings_frame_name +local save_button_name = Public.save_button_name +local discard_button_name = Public.discard_button_name +local spell_gui_button_name = Public.spell_gui_button_name +local spell_gui_frame_name = Public.spell_gui_frame_name +local spell1_button_name = Public.spell1_button_name +local spell2_button_name = Public.spell2_button_name +local spell3_button_name = Public.spell3_button_name -local settings_frame_name = RPG.settings_frame_name -local save_button_name = RPG.save_button_name -local discard_button_name = RPG.discard_button_name -local spell_gui_button_name = RPG.spell_gui_button_name -local spell_gui_frame_name = RPG.spell_gui_frame_name -local spell1_button_name = RPG.spell1_button_name -local spell2_button_name = RPG.spell2_button_name -local spell3_button_name = RPG.spell3_button_name +local settings_level = Public.gui_settings_levels local function create_input_element(frame, type, value, items, index) if type == 'slider' then @@ -28,8 +28,8 @@ local function create_input_element(frame, type, value, items, index) end function Public.update_spell_gui(player, spell_index) - local rpg_t = RPG.get('rpg_t') - local spells, names = RPG.rebuild_spells() + local rpg_t = Public.get_value_from_player(player.index) + local spells, names = Public.rebuild_spells() local main_frame = player.gui.screen[spell_gui_frame_name] if not main_frame then return @@ -37,48 +37,48 @@ function Public.update_spell_gui(player, spell_index) local spell_table = main_frame['spell_table'] if spell_index then if spell_index == 1 then - rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index1 + rpg_t.dropdown_select_index = rpg_t.dropdown_select_index1 elseif spell_index == 2 then - rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index2 + rpg_t.dropdown_select_index = rpg_t.dropdown_select_index2 elseif spell_index == 3 then - rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index3 + rpg_t.dropdown_select_index = rpg_t.dropdown_select_index3 end end - spell_table[spell1_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---' - spell_table[spell1_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite - spell_table[spell2_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---' - spell_table[spell2_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite - spell_table[spell3_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---' - spell_table[spell3_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite - if rpg_t[player.index].dropdown_select_index1 == rpg_t[player.index].dropdown_select_index then + spell_table[spell1_button_name].tooltip = names[rpg_t.dropdown_select_index1] or '---' + spell_table[spell1_button_name].sprite = spells[rpg_t.dropdown_select_index1].sprite + spell_table[spell2_button_name].tooltip = names[rpg_t.dropdown_select_index2] or '---' + spell_table[spell2_button_name].sprite = spells[rpg_t.dropdown_select_index2].sprite + spell_table[spell3_button_name].tooltip = names[rpg_t.dropdown_select_index3] or '---' + spell_table[spell3_button_name].sprite = spells[rpg_t.dropdown_select_index3].sprite + if rpg_t.dropdown_select_index1 == rpg_t.dropdown_select_index then spell_table[spell1_button_name].enabled = false spell_table[spell1_button_name].number = 1 else spell_table[spell1_button_name].enabled = true spell_table[spell1_button_name].number = nil end - if rpg_t[player.index].dropdown_select_index2 == rpg_t[player.index].dropdown_select_index then + if rpg_t.dropdown_select_index2 == rpg_t.dropdown_select_index then spell_table[spell2_button_name].enabled = false spell_table[spell2_button_name].number = 1 else spell_table[spell2_button_name].enabled = true spell_table[spell2_button_name].number = nil end - if rpg_t[player.index].dropdown_select_index3 == rpg_t[player.index].dropdown_select_index then + if rpg_t.dropdown_select_index3 == rpg_t.dropdown_select_index then spell_table[spell3_button_name].enabled = false spell_table[spell3_button_name].number = 1 else spell_table[spell3_button_name].enabled = true spell_table[spell3_button_name].number = nil end - spell_table['mana-cost'].caption = spells[rpg_t[player.index].dropdown_select_index].mana_cost - spell_table['mana'].caption = math.floor(rpg_t[player.index].mana) - spell_table['maxmana'].caption = math.floor(rpg_t[player.index].mana_max) + spell_table['mana-cost'].caption = spells[rpg_t.dropdown_select_index].mana_cost + spell_table['mana'].caption = math.floor(rpg_t.mana) + spell_table['maxmana'].caption = math.floor(rpg_t.mana_max) end function Public.spell_gui_settings(player) - local rpg_t = RPG.get('rpg_t') - local spells, names = RPG.rebuild_spells() + local rpg_t = Public.get_value_from_player(player.index) + local spells, names = Public.rebuild_spells() local main_frame = player.gui.screen[spell_gui_frame_name] if not main_frame or not main_frame.valid then main_frame = @@ -95,25 +95,25 @@ function Public.spell_gui_settings(player) table.add( { type = 'sprite-button', - sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite, + sprite = spells[rpg_t.dropdown_select_index1].sprite, name = spell1_button_name, - tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---' + tooltip = names[rpg_t.dropdown_select_index1] or '---' } ) table.add( { type = 'sprite-button', - sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite, + sprite = spells[rpg_t.dropdown_select_index2].sprite, name = spell2_button_name, - tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---' + tooltip = names[rpg_t.dropdown_select_index2] or '---' } ) table.add( { type = 'sprite-button', - sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite, + sprite = spells[rpg_t.dropdown_select_index3].sprite, name = spell3_button_name, - tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---' + tooltip = names[rpg_t.dropdown_select_index3] or '---' } ) local b1 = table.add({type = 'sprite-button', name = 'mana-cost', tooltip = {'rpg_settings.mana_cost'}, caption = 0}) @@ -129,8 +129,8 @@ function Public.spell_gui_settings(player) end function Public.extra_settings(player) - local rpg_extra = RPG.get('rpg_extra') - local rpg_t = RPG.get('rpg_t') + local rpg_extra = Public.get('rpg_extra') + local rpg_t = Public.get_value_from_player(player.index) local trusted = Session.get_trusted_table() local main_frame = player.gui.screen.add( @@ -195,7 +195,7 @@ function Public.extra_settings(player) local input_style = health_bar_input.style input_style.height = 35 input_style.vertical_align = 'center' - health_bar_gui_input = create_input_element(health_bar_input, 'boolean', rpg_t[player.index].show_bars) + health_bar_gui_input = create_input_element(health_bar_input, 'boolean', rpg_t.show_bars) health_bar_gui_input.tooltip = ({'rpg_settings.tooltip_check'}) if not rpg_extra.enable_mana then health_bar_label.caption = ({'rpg_settings.health_only_text_label'}) @@ -222,13 +222,13 @@ function Public.extra_settings(player) reset_input_style.vertical_align = 'center' local reset_gui_input = create_input_element(reset_input, 'boolean', false) - if not rpg_t[player.index].reset then + if not rpg_t.reset then if not trusted[player.name] then reset_gui_input.enabled = false reset_gui_input.tooltip = ({'rpg_settings.not_trusted'}) goto continue end - if rpg_t[player.index].level < 50 then + if rpg_t.level < settings_level['reset_text_label'] then reset_gui_input.enabled = false reset_gui_input.tooltip = ({'rpg_settings.low_level', 50}) reset_label.tooltip = ({'rpg_settings.low_level', 50}) @@ -330,14 +330,14 @@ function Public.extra_settings(player) stone_path_input_style.height = 35 stone_path_input_style.vertical_align = 'center' local stone_path - if rpg_t[player.index].stone_path then - stone_path = rpg_t[player.index].stone_path + if rpg_t.stone_path then + stone_path = rpg_t.stone_path else stone_path = false end stone_path_gui_input = create_input_element(stone_path_input, 'boolean', stone_path) - if rpg_t[player.index].level < 20 then + if rpg_t.level < settings_level['stone_path_label'] then stone_path_gui_input.enabled = false stone_path_gui_input.tooltip = ({'rpg_settings.low_level', 20}) stone_path_label.tooltip = ({'rpg_settings.low_level', 20}) @@ -367,8 +367,8 @@ function Public.extra_settings(player) one_punch_input_style.height = 35 one_punch_input_style.vertical_align = 'center' local one_punch - if rpg_t[player.index].one_punch then - one_punch = rpg_t[player.index].one_punch + if rpg_t.one_punch then + one_punch = rpg_t.one_punch else one_punch = false end @@ -379,7 +379,7 @@ function Public.extra_settings(player) one_punch_gui_input.enabled = false one_punch_gui_input.tooltip = ({'rpg_settings.one_punch_globally'}) else - if rpg_t[player.index].level < 30 then + if rpg_t.level < settings_level['one_punch_label'] then one_punch_gui_input.enabled = false one_punch_gui_input.tooltip = ({'rpg_settings.low_level', 30}) else @@ -409,15 +409,15 @@ function Public.extra_settings(player) flame_boots_input_style.height = 35 flame_boots_input_style.vertical_align = 'center' local flame_mod - if rpg_t[player.index].flame_boots then - flame_mod = rpg_t[player.index].flame_boots + if rpg_t.flame_boots then + flame_mod = rpg_t.flame_boots else flame_mod = false end flame_boots_gui_input = create_input_element(flame_boots_input, 'boolean', flame_mod) - if rpg_t[player.index].mana > 50 then - if rpg_t[player.index].level < 100 then + if rpg_t.mana > 50 then + if rpg_t.level < settings_level['flameboots_label'] then flame_boots_gui_input.enabled = false flame_boots_gui_input.tooltip = ({'rpg_settings.low_level', 100}) flame_boots_label.tooltip = ({'rpg_settings.low_level', 100}) @@ -451,14 +451,14 @@ function Public.extra_settings(player) explosive_bullet_input_style.height = 35 explosive_bullet_input_style.vertical_align = 'center' local explosive_bullets - if rpg_t[player.index].explosive_bullets then - explosive_bullets = rpg_t[player.index].explosive_bullets + if rpg_t.explosive_bullets then + explosive_bullets = rpg_t.explosive_bullets else explosive_bullets = false end explosive_bullets_gui_input = create_input_element(explosive_bullet_input, 'boolean', explosive_bullets) - if rpg_t[player.index].level < 50 then + if rpg_t.level < settings_level['explosive_bullets_label'] then explosive_bullets_gui_input.enabled = false explosive_bullets_gui_input.tooltip = ({'rpg_settings.low_level', 50}) explosive_bullets_label.tooltip = ({'rpg_settings.low_level', 50}) @@ -513,8 +513,8 @@ function Public.extra_settings(player) entity_input_style.vertical_align = 'center' entity_input_style.horizontal_align = 'right' local entity_mod - if rpg_t[player.index].enable_entity_spawn then - entity_mod = rpg_t[player.index].enable_entity_spawn + if rpg_t.enable_entity_spawn then + entity_mod = rpg_t.enable_entity_spawn else entity_mod = false end @@ -537,7 +537,7 @@ function Public.extra_settings(player) } ) - local spells, names = RPG.rebuild_spells() + local spells, names = Public.rebuild_spells() local conjure_label_style = conjure_label.style conjure_label_style.horizontally_stretchable = true @@ -548,7 +548,7 @@ function Public.extra_settings(player) local conjure_input_style = conjure_input.style conjure_input_style.height = 35 conjure_input_style.vertical_align = 'center' - conjure_gui_input = create_input_element(conjure_input, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index) + conjure_gui_input = create_input_element(conjure_input, 'dropdown', false, names, rpg_t.dropdown_select_index) for _, entity in pairs(spells) do if entity.type == 'item' then @@ -577,23 +577,23 @@ function Public.extra_settings(player) }) end end - if not spells[rpg_t[player.index].dropdown_select_index1] then - rpg_t[player.index].dropdown_select_index1 = 1 + if not spells[rpg_t.dropdown_select_index1] then + rpg_t.dropdown_select_index1 = 1 end - if not spells[rpg_t[player.index].dropdown_select_index2] then - rpg_t[player.index].dropdown_select_index2 = 1 + if not spells[rpg_t.dropdown_select_index2] then + rpg_t.dropdown_select_index2 = 1 end - if not spells[rpg_t[player.index].dropdown_select_index3] then - rpg_t[player.index].dropdown_select_index3 = 1 + if not spells[rpg_t.dropdown_select_index3] then + rpg_t.dropdown_select_index3 = 1 end mana_frame.add({type = 'label', caption = {'rpg_settings.spell_gui_setup'}, tooltip = {'rpg_settings.spell_gui_tooltip'}}) local spell_grid = mana_frame.add({type = 'table', column_count = 4, name = 'spell_grid_table'}) - spell_gui_input1 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index1) + spell_gui_input1 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t.dropdown_select_index1) spell_gui_input1.style.maximal_width = 135 - spell_gui_input2 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index2) + spell_gui_input2 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t.dropdown_select_index2) spell_gui_input2.style.maximal_width = 135 - spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index3) + spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t.dropdown_select_index3) spell_gui_input3.style.maximal_width = 135 spell_grid.add({type = 'sprite-button', name = spell_gui_button_name, sprite = 'item/raw-fish'}) end @@ -631,7 +631,7 @@ function Public.extra_settings(player) ) allocate_label.tooltip = ({'rpg_settings.allocation_tooltip'}) - local names = RPG.auto_allocate_nodes + local names = Public.auto_allocate_nodes local allocate_label_style = allocate_label.style allocate_label_style.horizontally_stretchable = true @@ -642,7 +642,7 @@ function Public.extra_settings(player) local name_input_style = name_input.style name_input_style.height = 35 name_input_style.vertical_align = 'center' - auto_allocate_gui_input = create_input_element(name_input, 'dropdown', false, names, rpg_t[player.index].allocate_index) + auto_allocate_gui_input = create_input_element(name_input, 'dropdown', false, names, rpg_t.allocate_index) end local data = { @@ -702,5 +702,3 @@ function Public.extra_settings(player) player.opened = main_frame end - -return Public diff --git a/modules/rpg/spells.lua b/modules/rpg/spells.lua index 1047c60e..9caa023a 100644 --- a/modules/rpg/spells.lua +++ b/modules/rpg/spells.lua @@ -260,7 +260,7 @@ function Public.conjure_items() mana_cost = 200, tick = 100, enabled = true, - sprite = 'recipe/repair_pack' + sprite = 'recipe/repair-pack' } spells[#spells + 1] = { name = {'spells.acid_stream'}, diff --git a/modules/rpg/table.lua b/modules/rpg/table.lua index 6b028ae5..c07a8ead 100644 --- a/modules/rpg/table.lua +++ b/modules/rpg/table.lua @@ -39,6 +39,14 @@ for a = 1, 9999, 1 do Public.experience_levels[#Public.experience_levels + 1] = Public.experience_levels[#Public.experience_levels] + a * 8 end +Public.gui_settings_levels = { + ['reset_text_label'] = 50, + ['stone_path_label'] = 20, + ['one_punch_label'] = 30, + ['flameboots_label'] = 100, + ['explosive_bullets_label'] = 50 +} + Public.die_cause = { ['ammo-turret'] = true, ['electric-turret'] = true, @@ -179,6 +187,30 @@ function Public.set_value_to_player(key, value, setter) end end +--- Sets a new table to rpg_t table +---@param key +---@param tbl +function Public.set_new_player_tbl(key, tbl) + if key and tbl then + if type(tbl) ~= 'table' then + return error('Given parameter is not a table.') + end + + this.rpg_t[key] = tbl + return this.rpg_t[key] + end +end + +--- Removes a player from rpg_t table +---@param key +function Public.remove_player(index) + if index then + if this.rpg_t[index] then + this.rpg_t[index] = nil + end + end +end + --- Sets value to table ---@param key function Public.set(key) diff --git a/modules/show_inventory.lua b/modules/show_inventory.lua index b7d39e17..0a384eee 100644 --- a/modules/show_inventory.lua +++ b/modules/show_inventory.lua @@ -35,6 +35,9 @@ local function get_player_data(player, remove) end local function unpack_inventory(inventory) + if not inventory then + return + end local unpacked = {} for i = 1, #inventory do unpacked[i] = inventory[i] @@ -288,6 +291,10 @@ local function open_inventory(source, target) data.last_tab = 'Main' local main = unpack_inventory(target.get_main_inventory()) + if not main then + return + end + local armor = unpack_inventory(target.get_inventory(defines.inventory.character_armor)) local guns = unpack_inventory(target.get_inventory(defines.inventory.character_guns)) local ammo = unpack_inventory(target.get_inventory(defines.inventory.character_ammo)) @@ -354,6 +361,10 @@ local function on_gui_click(event) return false end local main = unpack_inventory(viewingPlayer.get_main_inventory()) + if not main then + return + end + local armor = unpack_inventory(viewingPlayer.get_inventory(defines.inventory.character_armor)) local guns = unpack_inventory(viewingPlayer.get_inventory(defines.inventory.character_guns)) local ammo = unpack_inventory(viewingPlayer.get_inventory(defines.inventory.character_ammo)) @@ -419,6 +430,10 @@ local function update_gui(event) end main = unpack_inventory(player.get_main_inventory()) + if not main then + return + end + local armor = unpack_inventory(player.get_inventory(defines.inventory.character_armor)) local guns = unpack_inventory(player.get_inventory(defines.inventory.character_guns)) local ammo = unpack_inventory(player.get_inventory(defines.inventory.character_ammo)) diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 4eff145c..a117b4d8 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -1,5 +1,6 @@ local Event = require 'utils.event' local BiterHealthBooster = require 'modules.biter_health_booster_v2' +local Difficulty = require 'modules.difficulty_vote_by_amount' local BiterRolls = require 'modules.wave_defense.biter_rolls' local SideTargets = require 'modules.wave_defense.side_targets' local ThreatEvent = require 'modules.wave_defense.threat_events' @@ -501,17 +502,6 @@ local function increase_biter_damage() return end - local Difficulty - if is_loaded('modules.difficulty_vote_by_amount') then - Difficulty = is_loaded('modules.difficulty_vote_by_amount') - elseif is_loaded('modules.difficulty_vote') then - Difficulty = is_loaded('modules.difficulty_vote') - end - - if not Difficulty then - return - end - local e = game.forces.enemy local new = Difficulty.get().difficulty_vote_value * 0.04 local melee = new diff --git a/player_modifiers.lua b/player_modifiers.lua index 6ce2c043..dd461446 100644 --- a/player_modifiers.lua +++ b/player_modifiers.lua @@ -1,6 +1,7 @@ --Central to add all player modifiers together. --Will overwrite character stats from other mods. +local Event = require 'utils.event' local Global = require 'utils.global' local this = { @@ -17,8 +18,23 @@ Global.register( local Public = {} -function Public.get_table() - return this +function Public.get(key) + if key then + return this[key] + else + return this + end +end + +function Public.set(key, value) + if key and (value or value == false) then + this[key] = value + return this[key] + elseif key then + return this[key] + else + return this + end end local modifiers = { @@ -37,13 +53,23 @@ local modifiers = { } function Public.update_player_modifiers(player) + local player_modifiers = this.modifiers[player.index] + if not player_modifiers then + return + end + + local disabled_modifiers = this.disabled_modifier[player.index] + if not disabled_modifiers then + return + end + for k, modifier in pairs(modifiers) do local sum_value = 0 - for _, value in pairs(this.modifiers[player.index][k]) do + for _, value in pairs(player_modifiers[k]) do sum_value = sum_value + value end if player.character then - if this.disabled_modifier[player.index] and this.disabled_modifier[player.index][k] then + if disabled_modifiers and disabled_modifiers[k] then player[modifier] = 0 else player[modifier] = sum_value @@ -53,28 +79,30 @@ function Public.update_player_modifiers(player) end function Public.update_single_modifier(player, modifier, category, value) - if not this.modifiers[player.index] then + local player_modifiers = this.modifiers[player.index] + if not player_modifiers then return end if not modifier then return end - for k, _ in pairs(this.modifiers[player.index]) do - if modifiers[k] == modifier and this.modifiers[player.index][k] then + for k, _ in pairs(player_modifiers) do + if modifiers[k] == modifier and player_modifiers[k] then if category then - if not this.modifiers[player.index][k][category] then - this.modifiers[player.index][k][category] = {} + if not player_modifiers[k][category] then + player_modifiers[k][category] = {} end - this.modifiers[player.index][k][category] = value + player_modifiers[k][category] = value else - this.modifiers[player.index][k] = value + player_modifiers[k] = value end end end end function Public.disable_single_modifier(player, modifier, value) - if not this.disabled_modifier[player.index] then + local disabled_modifiers = this.disabled_modifier[player.index] + if not disabled_modifiers then return end if not modifier then @@ -83,30 +111,31 @@ function Public.disable_single_modifier(player, modifier, value) for k, _ in pairs(modifiers) do if modifiers[k] == modifier then if value then - this.disabled_modifier[player.index][k] = value + disabled_modifiers[k] = value else - this.disabled_modifier[player.index][k] = nil + disabled_modifiers[k] = nil end end end end function Public.get_single_modifier(player, modifier, category) - if not this.modifiers[player.index] then + local player_modifiers = this.modifiers[player.index] + if not player_modifiers then return end if not modifier then return end - for k, _ in pairs(this.modifiers[player.index]) do + for k, _ in pairs(player_modifiers) do if modifiers[k] == modifier then if category then - if this.modifiers[player.index][k] and this.modifiers[player.index][k][category] then - return this.modifiers[player.index][k][category] + if player_modifiers[k] and player_modifiers[k][category] then + return player_modifiers[k][category] end else - if this.modifiers[player.index][k] then - return this.modifiers[player.index][k] + if player_modifiers[k] then + return player_modifiers[k] end end return false @@ -116,21 +145,22 @@ function Public.get_single_modifier(player, modifier, category) end function Public.get_single_disabled_modifier(player, modifier, category) - if not this.disabled_modifier[player.index] then + local disabled_modifiers = this.disabled_modifier[player.index] + if not disabled_modifiers then return end if not modifier then return end - for k, _ in pairs(this.disabled_modifier[player.index]) do + for k, _ in pairs(disabled_modifiers) do if modifiers[k] == modifier then if category then - if this.disabled_modifier[player.index][k] and this.disabled_modifier[player.index][k][category] then - return this.disabled_modifier[player.index][k][category] + if disabled_modifiers[k] and disabled_modifiers[k][category] then + return disabled_modifiers[k][category] end else - if this.disabled_modifier[player.index][k] then - return this.disabled_modifier[player.index][k] + if disabled_modifiers[k] then + return disabled_modifiers[k] end end return false @@ -172,7 +202,6 @@ local function on_player_removed(event) end end -local Event = require 'utils.event' Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_respawned, on_player_respawned) Event.add(defines.events.on_player_removed, on_player_removed)