diff --git a/modules/rpg/core.lua b/modules/rpg/core.lua index bf3463cf..d7b750f0 100644 --- a/modules/rpg/core.lua +++ b/modules/rpg/core.lua @@ -3,6 +3,9 @@ local Public = require 'modules.rpg.table' local Bullets = require 'modules.rpg.explosive_gun_bullets' Public.explosive_bullet = Bullets +local RangeBuffs = require 'modules.rpg.range_buffs' +Public.range_buffs = RangeBuffs + local Functions = require 'modules.rpg.functions' Public.functions = Functions diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 143d07da..005be6a9 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -2,6 +2,7 @@ local Public = require 'modules.rpg.table' local Task = require 'utils.task' local Gui = require 'utils.gui' local Color = require 'utils.color_presets' +local P = require 'utils.player_modifiers' local Token = require 'utils.token' local Alert = require 'utils.alert' @@ -514,6 +515,35 @@ function Public.level_limit_exceeded(player, value) return false end +function Public.update_player_stats(player) + 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', round(strength * 0.2, 3)) + P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', round(strength * 0.007, 3)) + P.update_single_modifier(player, 'character_maximum_following_robot_count_bonus', 'rpg', round(strength / 2 * 0.03, 3)) + + local magic = rpg_t.magicka - 10 + local v = magic * 0.22 + P.update_single_modifier(player, 'character_build_distance_bonus', 'rpg', math.min(60, round(v * 0.12, 3))) + P.update_single_modifier(player, 'character_item_drop_distance_bonus', 'rpg', math.min(60, round(v * 0.05, 3))) + P.update_single_modifier(player, 'character_reach_distance_bonus', 'rpg', math.min(60, round(v * 0.12, 3))) + P.update_single_modifier(player, 'character_loot_pickup_distance_bonus', 'rpg', math.min(20, round(v * 0.12, 3))) + P.update_single_modifier(player, 'character_item_pickup_distance_bonus', 'rpg', math.min(20, round(v * 0.12, 3))) + P.update_single_modifier(player, 'character_resource_reach_distance_bonus', 'rpg', math.min(20, round(v * 0.05, 3))) + if rpg_t.mana_max >= rpg_extra.mana_limit then + rpg_t.mana_max = rpg_extra.mana_limit + else + rpg_t.mana_max = round((magic) * 2, 3) + end + + local dexterity = rpg_t.dexterity - 10 + P.update_single_modifier(player, 'character_running_speed_modifier', 'rpg', round(dexterity * 0.0010, 3)) -- reduced since too high speed kills UPS. + P.update_single_modifier(player, 'character_crafting_speed_modifier', 'rpg', round(dexterity * 0.015, 3)) + P.update_single_modifier(player, 'character_health_bonus', 'rpg', round((rpg_t.vitality - 10) * 6, 3)) + P.update_player_modifiers(player) +end + function Public.level_up_effects(player) local position = {x = player.position.x - 0.75, y = player.position.y - 1} player.surface.create_entity({name = 'flying-text', position = position, text = '+LVL ', color = level_up_floating_text_color}) @@ -542,19 +572,41 @@ function Public.xp_effects(player) player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} end +function Public.get_range_modifier(player) + local rpg_t = Public.get_value_from_player(player.index) + if not rpg_t then + return false + end + local total = (rpg_t.strength - 10) * 0.010 + if total > 5 then -- limit it to 5 for now, until we've tested it enough + total = 5 + end + return round(total, 3) +end + function Public.get_melee_modifier(player) local rpg_t = Public.get_value_from_player(player.index) - return (rpg_t.strength - 10) * 0.10 + if not rpg_t then + return false + end + local total = (rpg_t.strength - 10) * 0.10 + return total end function Public.get_final_damage_modifier(player) local rpg_t = Public.get_value_from_player(player.index) + if not rpg_t then + return false + end local rng = random(10, 35) * 0.01 return (rpg_t.strength - 10) * rng end function Public.get_final_damage(player, entity, original_damage_amount) local modifier = Public.get_final_damage_modifier(player) + if not modifier then + return false + end local damage = original_damage_amount + original_damage_amount * modifier if entity.prototype.resistances then if entity.prototype.resistances.physical then @@ -571,6 +623,9 @@ end function Public.get_heal_modifier(player) local rpg_t = Public.get_value_from_player(player.index) + if not rpg_t then + return false + end return (rpg_t.vitality - 10) * 0.06 end diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index 89f0da7d..29d8a059 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -473,35 +473,6 @@ function Public.draw_level_text(player) } end -function Public.update_player_stats(player) - 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', round(strength * 0.2, 3)) - P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', round(strength * 0.007, 3)) - P.update_single_modifier(player, 'character_maximum_following_robot_count_bonus', 'rpg', round(strength / 2 * 0.03, 3)) - - local magic = rpg_t.magicka - 10 - local v = magic * 0.22 - P.update_single_modifier(player, 'character_build_distance_bonus', 'rpg', math.min(60, round(v * 0.12, 3))) - P.update_single_modifier(player, 'character_item_drop_distance_bonus', 'rpg', math.min(60, round(v * 0.05, 3))) - P.update_single_modifier(player, 'character_reach_distance_bonus', 'rpg', math.min(60, round(v * 0.12, 3))) - P.update_single_modifier(player, 'character_loot_pickup_distance_bonus', 'rpg', math.min(20, round(v * 0.12, 3))) - P.update_single_modifier(player, 'character_item_pickup_distance_bonus', 'rpg', math.min(20, round(v * 0.12, 3))) - P.update_single_modifier(player, 'character_resource_reach_distance_bonus', 'rpg', math.min(20, round(v * 0.05, 3))) - if rpg_t.mana_max >= rpg_extra.mana_limit then - rpg_t.mana_max = rpg_extra.mana_limit - else - rpg_t.mana_max = round((magic) * 2, 3) - end - - local dexterity = rpg_t.dexterity - 10 - P.update_single_modifier(player, 'character_running_speed_modifier', 'rpg', round(dexterity * 0.0010, 3)) -- reduced since too high speed kills UPS. - P.update_single_modifier(player, 'character_crafting_speed_modifier', 'rpg', round(dexterity * 0.015, 3)) - P.update_single_modifier(player, 'character_health_bonus', 'rpg', round((rpg_t.vitality - 10) * 6, 3)) - P.update_player_modifiers(player) -end - function Public.toggle(player, recreate) local screen = player.gui.screen local main_frame = screen[main_frame_name] diff --git a/modules/rpg/table.lua b/modules/rpg/table.lua index e4418485..52686f16 100644 --- a/modules/rpg/table.lua +++ b/modules/rpg/table.lua @@ -107,6 +107,7 @@ function Public.reset_table() this.rpg_extra.enable_flame_boots = false this.rpg_extra.enable_explosive_bullets = false this.rpg_extra.enable_explosive_bullets_globally = false + this.rpg_extra.enable_range_buffs = false this.rpg_extra.mana_per_tick = 0.1 this.rpg_extra.xp_modifier_when_mining = 0.0045 this.rpg_extra.force_mana_per_tick = false @@ -272,11 +273,7 @@ end --- If you disable mana but enable then only health will be shown ---@param value function Public.enable_health_and_mana_bars(value) - if value then - this.rpg_extra.enable_health_and_mana_bars = value - else - this.rpg_extra.enable_health_and_mana_bars = false - end + this.rpg_extra.enable_health_and_mana_bars = value or false return this.rpg_extra.enable_health_and_mana_bars end @@ -284,11 +281,7 @@ end --- Enables the mana feature that allows players to spawn entities. ---@param value function Public.enable_mana(value) - if value then - this.rpg_extra.enable_mana = value - else - this.rpg_extra.enable_mana = false - end + this.rpg_extra.enable_mana = value or false return this.rpg_extra.enable_mana end @@ -297,11 +290,7 @@ end --- It boosts the amount of xp the players get after x amount of waves. ---@param value function Public.enable_wave_defense(value) - if value then - this.rpg_extra.enable_wave_defense = value - else - this.rpg_extra.enable_wave_defense = false - end + this.rpg_extra.enable_wave_defense = value or false return this.rpg_extra.enable_wave_defense end @@ -309,11 +298,7 @@ end --- Enables/disabled flame boots. ---@param value function Public.enable_flame_boots(value) - if value then - this.rpg_extra.enable_flame_boots = value - else - this.rpg_extra.enable_flame_boots = false - end + this.rpg_extra.enable_flame_boots = value or false return this.rpg_extra.enable_flame_boots end @@ -321,45 +306,46 @@ end --- Enables/disabled explosive bullets globally. ---@param value function Public.enable_explosive_bullets_globally(value) - if value then - this.rpg_extra.enable_explosive_bullets_globally = value - else - this.rpg_extra.enable_explosive_bullets_globally = false - end + this.rpg_extra.enable_explosive_bullets_globally = value or false return this.rpg_extra.enable_explosive_bullets_globally end --- Fetches if the explosive bullets module is activated globally. -function Public.get_explosive_bullets() +function Public.get_explosive_bullets_globally() return this.rpg_extra.enable_explosive_bullets_globally end ---- Enables/disabled explosive bullets. ----@param value -function Public.enable_explosive_bullets(value) - if value then - this.rpg_extra.enable_explosive_bullets = value - else - this.rpg_extra.enable_explosive_bullets = false - end - - return this.rpg_extra.enable_explosive_bullets -end - --- Fetches if the explosive bullets module is activated. function Public.get_explosive_bullets() return this.rpg_extra.enable_explosive_bullets end +--- Enables/disabled explosive bullets. +---@param value +function Public.enable_explosive_bullets(value) + this.rpg_extra.enable_explosive_bullets = value or false + + return this.rpg_extra.enable_explosive_bullets +end + +--- Fetches if the range buffs module is activated. +function Public.get_range_buffs() + return this.rpg_extra.enable_range_buffs +end + +--- Enables/disabled range buffs. +---@param value +function Public.enable_range_buffs(value) + this.rpg_extra.enable_range_buffs = value or false + + return this.rpg_extra.enable_range_buffs +end + --- Enables/disabled personal tax. ---@param value function Public.personal_tax_rate(value) - if value then - this.rpg_extra.personal_tax_rate = value - else - this.rpg_extra.personal_tax_rate = false - end + this.rpg_extra.personal_tax_rate = value or false return this.rpg_extra.personal_tax_rate end @@ -367,11 +353,7 @@ end --- Enables/disabled stone-path-tile creation on mined. ---@param value function Public.enable_stone_path(value) - if value then - this.rpg_extra.enable_stone_path = value - else - this.rpg_extra.enable_stone_path = false - end + this.rpg_extra.enable_stone_path = value or false return this.rpg_extra.enable_stone_path end @@ -379,11 +361,7 @@ end --- Enables/disabled auto-allocations of skill-points. ---@param value function Public.enable_auto_allocate(value) - if value then - this.rpg_extra.enable_auto_allocate = value - else - this.rpg_extra.enable_auto_allocate = false - end + this.rpg_extra.enable_auto_allocate = value or false return this.rpg_extra.enable_auto_allocate end @@ -391,11 +369,7 @@ end --- Enables/disabled stone-path-tile creation on mined. ---@param value function Public.enable_one_punch(value) - if value then - this.rpg_extra.enable_one_punch = value - else - this.rpg_extra.enable_one_punch = false - end + this.rpg_extra.enable_one_punch = value or false return this.rpg_extra.enable_one_punch end @@ -403,11 +377,7 @@ end --- Enables/disabled stone-path-tile creation on mined. ---@param value function Public.enable_one_punch_globally(value) - if value then - this.rpg_extra.enable_one_punch_globally = value - else - this.rpg_extra.enable_one_punch_globally = false - end + this.rpg_extra.enable_one_punch_globally = value or false return this.rpg_extra.enable_one_punch_globally end