1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Tweaking level up formula for late late game

Tweaking xp gained from infinite research to add 60% towards current level up progress.
Added max level for boosts
This commit is contained in:
SimonFlapse 2019-02-19 17:02:07 +01:00
parent 5cf640eecd
commit c00f786241
2 changed files with 98 additions and 78 deletions

View File

@ -357,9 +357,9 @@ local Config = {
experience = {
enabled = true,
-- controls the formula for calculating level up costs in stone sent to surface
difficulty_scale = 15, -- Diggy default 15. Higher increases experience requirement climb
difficulty_scale = 20, -- Diggy default 15. Higher increases experience requirement climb
first_lvl_xp = 350, -- Diggy default 350. This sets the price for the first level.
xp_fine_tune = 200, -- Diggy default 200. This value is used to fine tune the overall requirement climb without affecting the speed
xp_fine_tune = 400, -- Diggy default 200. This value is used to fine tune the overall requirement climb without affecting the speed
cost_precision = 3, -- Diggy default 3. This sets the precision of the required experience to level up. E.g. 1234 becomes 1200 with precision 2 and 1230 with precision 3.
-- percentage * mining productivity level gets added to mining speed
@ -369,7 +369,7 @@ local Config = {
['sand-rock-big'] = 5,
['rock-big'] = 5,
['rock-huge'] = 10,
['rocket_launch'] = 0.01, -- XP reward in percentage of total experience when a rocket launches (Diggy default: 0.01 which equals 1%)
['rocket_launch'] = 0.01, -- XP reward in percentage of total experience when a rocket launches (Diggy default: 0.01 which equals 1%)
['science-pack-1'] = 4,
['science-pack-2'] = 8,
['science-pack-3'] = 15,
@ -377,17 +377,18 @@ local Config = {
['production-science-pack'] = 25,
['high-tech-science-pack'] = 50,
['space-science-pack'] = 10,
['enemy_killed'] = 10, -- Base XP for killing biters and spitters.
['enemy_killed'] = 10, -- Base XP for killing biters and spitters.
['death-penalty'] = 0.0035, -- XP deduct in percentage of total experience when a player dies (Diggy default: 0.0035 which equals 0.35%)
--['cave-in-penalty'] = 100 -- XP lost every cave in.
--['cave-in-penalty'] = 100 -- XP lost every cave in.
['infinity-research'] = 0.60 -- XP reward in percentage of the required experience from current level to next level (Diggy default: 0.60 which equals 60%)
},
buffs = {
-- define new buffs here, they are handed out for each level
mining_speed = {value = 5},
inventory_slot = {value = 1},
mining_speed = {value = 5, max = 100},
inventory_slot = {value = 1, max = 100},
-- double_level is the level interval for receiving a double bonus (Diggy default: 5 which equals every 5th level)
health_bonus = {value = 2.5, double_level = 5},
health_bonus = {value = 2.5, double_level = 5, max = 500},
},
-- add or remove a table entry to add or remove a unlockable item from the market.

View File

@ -69,15 +69,16 @@ local table_column_layout = {type = 'table', column_count = 2}
local level_up_formula = (function (level_reached)
local difficulty_scale = floor(config.difficulty_scale)
local level_fine_tune = floor(config.xp_fine_tune)
local start_value = (floor(config.first_lvl_xp) * 0.5)
local start_value = (floor(config.first_lvl_xp))
local precision = (floor(config.cost_precision))
local function formula(level)
return (
difficulty_scale * (level) ^ 3
+ (level_fine_tune + start_value) * (level) ^ 2
return (floor(
(1.15 ^ (level * 0.1))
+ difficulty_scale * (level) ^ 3
+ level_fine_tune * (level) ^ 2
+ start_value * (level)
- difficulty_scale * (level)
- level_fine_tune * (level)
- level_fine_tune * (level))
)
end
local value = formula(level_reached + 1)
@ -90,6 +91,30 @@ local level_up_formula = (function (level_reached)
return value - lower_value
end)
local level_table = {}
---Get experience requirement for a given level
---Primarily used for the Experience GUI to display total experience required to unlock a specific item
---@param level number a number specifying the level
---@return number required total experience to reach supplied level
local function calculate_level_xp(level)
if level_table[level] == nil then
local value
if level == 1 then
value = level_up_formula(level-1)
else
value = level_up_formula(level-1)+calculate_level_xp(level-1)
end
insert(level_table, level, value)
end
return level_table[level]
end
---Get a percentage of required experience between a level and the next level
---@param level number a number specifying the current level
---@return number a percentage of the required experience to level up from one level to the other
local function percentage_of_level_req(level, percentage)
return level_up_formula(level)*percentage
end
---Updates the market contents based on the current level.
---@param force LuaForce the force which the unlocking requirement should be based of
function Experience.update_market_contents(force)
@ -109,64 +134,70 @@ end
---@param force LuaForce the force of which will be updated
---@param level_up number a level if updating as part of a level up (optional)
function Experience.update_mining_speed(force, level_up)
level_up = level_up ~= nil and level_up or 0
local buff = config.buffs['mining_speed']
if level_up > 0 and buff ~= nil then
local level = get_force_data(force).current_level
local adjusted_value = floor(max(buff.value, 24*0.9^level))
local value = (buff.double_level ~= nil and level_up % buff.double_level == 0) and adjusted_value * 2 or adjusted_value
mining_efficiency.level_modifier = mining_efficiency.level_modifier + (value * 0.01)
if buff.max == nil or force.manual_mining_speed_modifier < buff.max then
level_up = level_up ~= nil and level_up or 0
if level_up > 0 and buff ~= nil then
local level = get_force_data(force).current_level
local adjusted_value = floor(max(buff.value, 24*0.9^level))
local value = (buff.double_level ~= nil and level_up % buff.double_level == 0) and adjusted_value * 2 or adjusted_value
mining_efficiency.level_modifier = mining_efficiency.level_modifier + (value * 0.01)
end
-- remove the current buff
local old_modifier = force.manual_mining_speed_modifier - mining_efficiency.active_modifier
-- update the active modifier
mining_efficiency.active_modifier = mining_efficiency.research_modifier + mining_efficiency.level_modifier
-- add the new active modifier to the non-buffed modifier
force.manual_mining_speed_modifier = old_modifier + mining_efficiency.active_modifier
end
-- remove the current buff
local old_modifier = force.manual_mining_speed_modifier - mining_efficiency.active_modifier
-- update the active modifier
mining_efficiency.active_modifier = mining_efficiency.research_modifier + mining_efficiency.level_modifier
-- add the new active modifier to the non-buffed modifier
force.manual_mining_speed_modifier = old_modifier + mining_efficiency.active_modifier
end
---Updates a forces inventory slots. By removing active modifiers and re-adding
---@param force LuaForce the force of which will be updated
---@param level_up number a level if updating as part of a level up (optional)
function Experience.update_inventory_slots(force, level_up)
level_up = level_up ~= nil and level_up or 0
local buff = config.buffs['inventory_slot']
if level_up > 0 and buff ~= nil then
local value = (buff.double_level ~= nil and level_up % buff.double_level == 0) and buff.value * 2 or buff.value
inventory_slots.level_modifier = inventory_slots.level_modifier + value
if buff.max == nil or force.character_inventory_slots_bonus < buff.max then
level_up = level_up ~= nil and level_up or 0
if level_up > 0 and buff ~= nil then
local value = (buff.double_level ~= nil and level_up % buff.double_level == 0) and buff.value * 2 or buff.value
inventory_slots.level_modifier = inventory_slots.level_modifier + value
end
-- remove the current buff
local old_modifier = force.character_inventory_slots_bonus - inventory_slots.active_modifier
-- update the active modifier
inventory_slots.active_modifier = inventory_slots.research_modifier + inventory_slots.level_modifier
-- add the new active modifier to the non-buffed modifier
force.character_inventory_slots_bonus = old_modifier + inventory_slots.active_modifier
end
-- remove the current buff
local old_modifier = force.character_inventory_slots_bonus - inventory_slots.active_modifier
-- update the active modifier
inventory_slots.active_modifier = inventory_slots.research_modifier + inventory_slots.level_modifier
-- add the new active modifier to the non-buffed modifier
force.character_inventory_slots_bonus = old_modifier + inventory_slots.active_modifier
end
---Updates a forces inventory slots. By removing active modifiers and re-adding
---Updates a forces health bonus. By removing active modifiers and re-adding
---@param force LuaForce the force of which will be updated
---@param level_up number a level if updating as part of a level up (optional)
function Experience.update_health_bonus(force, level_up)
level_up = level_up ~= nil and level_up or 0
local buff = config.buffs['health_bonus']
if level_up > 0 and buff ~= nil then
local value = (buff.double_level ~= nil and level_up%buff.double_level == 0) and buff.value*2 or buff.value
health_bonus.level_modifier = health_bonus.level_modifier + value
if buff.max == nil or force.character_health_bonus < buff.max then
level_up = level_up ~= nil and level_up or 0
if level_up > 0 and buff ~= nil then
local value = (buff.double_level ~= nil and level_up%buff.double_level == 0) and buff.value*2 or buff.value
health_bonus.level_modifier = health_bonus.level_modifier + value
end
-- remove the current buff
local old_modifier = force.character_health_bonus - health_bonus.active_modifier
-- update the active modifier
health_bonus.active_modifier = health_bonus.research_modifier + health_bonus.level_modifier
-- add the new active modifier to the non-buffed modifier
force.character_health_bonus = old_modifier + health_bonus.active_modifier
end
-- remove the current buff
local old_modifier = force.character_health_bonus - health_bonus.active_modifier
-- update the active modifier
health_bonus.active_modifier = health_bonus.research_modifier + health_bonus.level_modifier
-- add the new active modifier to the non-buffed modifier
force.character_health_bonus = old_modifier + health_bonus.active_modifier
end
-- declaration of variables to prevent table look ups @see Experience.register
@ -204,14 +235,19 @@ end
local function on_research_finished(event)
local research = event.research
local force = research.force
local award_xp = 0
for _, ingredient in pairs(research.research_unit_ingredients) do
local name = ingredient.name
local reward = config.XP[name]
award_xp = award_xp + reward
local exp
if research.research_unit_count_formula ~= nil then
local force_data = get_force_data(force)
exp = percentage_of_level_req(force_data.current_level, config.XP['infinity-research'])
else
local award_xp = 0
for _, ingredient in pairs(research.research_unit_ingredients) do
local name = ingredient.name
local reward = config.XP[name]
award_xp = award_xp + reward
end
exp = award_xp * research.research_unit_count
end
local exp = award_xp * research.research_unit_count
local text = format('Research completed! +%s XP', exp)
for _, p in pairs(game.connected_players) do
local player_index = p.index
@ -310,23 +346,6 @@ local function on_player_respawned(event)
ScoreTable.add('Experience lost', exp)
end
local level_table = {}
---Get experiment requirement for a given level
---Primarily used for the Experience GUI to display total experience required to unlock a specific item
---@param level number a number specifying the level
---@return number required total experience to reach supplied level
local function calculate_level_xp(level)
if level_table[level] == nil then
local value
if level == 1 then
value = level_up_formula(level-1)
else
value = level_up_formula(level-1)+calculate_level_xp(level-1)
end
insert(level_table, level, value)
end
return level_table[level]
end
local function redraw_title(data)
local force_data = get_force_data('player')
data.frame.caption = Utils.comma_value(force_data.total_experience) .. ' total experience earned!'