mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-11 14:49:24 +02:00
RPG - fix level issue
This commit is contained in:
parent
e3875bee28
commit
02f0cda608
@ -1057,12 +1057,16 @@ function Public.rpg_reset_player(player, one_time_reset)
|
||||
mana_max = 0,
|
||||
last_spawned = 0,
|
||||
dropdown_select_index = 1,
|
||||
dropdown_select_index1 = 1,
|
||||
dropdown_select_index2 = 1,
|
||||
dropdown_select_index3 = 1,
|
||||
dropdown_select_name = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_1 = 1,
|
||||
dropdown_select_name_1 = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_2 = 1,
|
||||
dropdown_select_name_2 = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_3 = 1,
|
||||
dropdown_select_name_3 = Public.all_spells[1].name[1],
|
||||
allocate_index = 1,
|
||||
explosive_bullets = false,
|
||||
enable_entity_spawn = false,
|
||||
enable_entity_spawn = true,
|
||||
health_bar = rpg_t.health_bar,
|
||||
mana_bar = rpg_t.mana_bar,
|
||||
points_left = 0,
|
||||
@ -1087,25 +1091,30 @@ function Public.rpg_reset_player(player, one_time_reset)
|
||||
rpg_t.xp = round(old_xp)
|
||||
rpg_t.level = old_level
|
||||
else
|
||||
player.insert({name = 'raw-fish', count = 500})
|
||||
Public.set_new_player_tbl(
|
||||
player.index,
|
||||
{
|
||||
level = 1,
|
||||
level = 30,
|
||||
xp = 0,
|
||||
strength = 10,
|
||||
magicka = 10,
|
||||
magicka = 900,
|
||||
dexterity = 10,
|
||||
vitality = 10,
|
||||
mana = 0,
|
||||
mana_max = 0,
|
||||
mana = 5000,
|
||||
mana_max = 5000,
|
||||
last_spawned = 0,
|
||||
dropdown_select_index = 1,
|
||||
dropdown_select_index1 = 1,
|
||||
dropdown_select_index2 = 1,
|
||||
dropdown_select_index3 = 1,
|
||||
dropdown_select_name = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_1 = 1,
|
||||
dropdown_select_name_1 = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_2 = 1,
|
||||
dropdown_select_name_2 = Public.all_spells[1].name[1],
|
||||
dropdown_select_index_3 = 1,
|
||||
dropdown_select_name_3 = Public.all_spells[1].name[1],
|
||||
allocate_index = 1,
|
||||
explosive_bullets = false,
|
||||
enable_entity_spawn = false,
|
||||
enable_entity_spawn = true,
|
||||
points_left = 0,
|
||||
last_floaty_text = visuals_delay,
|
||||
xp_since_last_floaty_text = 0,
|
||||
|
@ -631,16 +631,38 @@ Gui.on_click(
|
||||
end
|
||||
end
|
||||
if conjure_gui_input and conjure_gui_input.valid and conjure_gui_input.selected_index then
|
||||
local items = conjure_gui_input.items
|
||||
local spell_name = items[conjure_gui_input.selected_index]
|
||||
if spell_name and spell_name[1] then
|
||||
rpg_t.dropdown_select_name = spell_name[1]
|
||||
end
|
||||
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.dropdown_select_index1 = spell_gui_input1.selected_index
|
||||
local items = spell_gui_input1.items
|
||||
local spell_name = items[spell_gui_input1.selected_index]
|
||||
|
||||
if spell_name and spell_name[1] then
|
||||
rpg_t.dropdown_select_name_1 = spell_name[1]
|
||||
end
|
||||
rpg_t.dropdown_select_index_1 = spell_gui_input1.selected_index
|
||||
end
|
||||
if spell_gui_input2 and spell_gui_input2.valid and spell_gui_input2.selected_index then
|
||||
rpg_t.dropdown_select_index2 = spell_gui_input2.selected_index
|
||||
local items = spell_gui_input2.items
|
||||
local spell_name = items[spell_gui_input2.selected_index]
|
||||
|
||||
if spell_name and spell_name[1] then
|
||||
rpg_t.dropdown_select_name_2 = spell_name[1]
|
||||
end
|
||||
rpg_t.dropdown_select_index_2 = spell_gui_input2.selected_index
|
||||
end
|
||||
if spell_gui_input3 and spell_gui_input3.valid and spell_gui_input3.selected_index then
|
||||
rpg_t.dropdown_select_index3 = spell_gui_input3.selected_index
|
||||
local items = spell_gui_input3.items
|
||||
local spell_name = items[spell_gui_input3.selected_index]
|
||||
if spell_name and spell_name[1] then
|
||||
rpg_t.dropdown_select_name_3 = spell_name[1]
|
||||
end
|
||||
rpg_t.dropdown_select_index_3 = spell_gui_input3.selected_index
|
||||
end
|
||||
if player.gui.screen[spell_gui_frame_name] then
|
||||
Public.update_spell_gui(player, nil)
|
||||
|
@ -851,7 +851,6 @@ local function on_player_used_capsule(event)
|
||||
return
|
||||
end
|
||||
|
||||
local conjure_items = Public.all_spells
|
||||
local projectile_types = Public.get_projectiles
|
||||
|
||||
local player = game.get_player(event.player_index)
|
||||
@ -894,7 +893,7 @@ local function on_player_used_capsule(event)
|
||||
local mana = rpg_t.mana
|
||||
local surface = player.surface
|
||||
|
||||
local spell = conjure_items[rpg_t.dropdown_select_index]
|
||||
local spell = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name)
|
||||
if not spell then
|
||||
return
|
||||
end
|
||||
|
@ -72,7 +72,6 @@ end
|
||||
|
||||
function Public.update_spell_gui(player, spell_index)
|
||||
local rpg_t = Public.get_value_from_player(player.index)
|
||||
local spells, names = Public.get_all_spells_filtered(rpg_t)
|
||||
local main_frame = player.gui.screen[spell_gui_frame_name]
|
||||
if not main_frame then
|
||||
return
|
||||
@ -80,41 +79,51 @@ 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.dropdown_select_index = rpg_t.dropdown_select_index1
|
||||
rpg_t.dropdown_select_name = rpg_t.dropdown_select_name_1
|
||||
rpg_t.dropdown_select_index = rpg_t.dropdown_select_index_1
|
||||
elseif spell_index == 2 then
|
||||
rpg_t.dropdown_select_index = rpg_t.dropdown_select_index2
|
||||
rpg_t.dropdown_select_name = rpg_t.dropdown_select_name_2
|
||||
rpg_t.dropdown_select_index = rpg_t.dropdown_select_index_2
|
||||
elseif spell_index == 3 then
|
||||
rpg_t.dropdown_select_index = rpg_t.dropdown_select_index3
|
||||
rpg_t.dropdown_select_name = rpg_t.dropdown_select_name_3
|
||||
rpg_t.dropdown_select_index = rpg_t.dropdown_select_index_3
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
local spell_1_data = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name_1)
|
||||
local spell_2_data = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name_2)
|
||||
local spell_3_data = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name_3)
|
||||
|
||||
spell_table[spell1_button_name].tooltip = spell_1_data and spell_1_data.name or '---'
|
||||
spell_table[spell1_button_name].sprite = spell_1_data and spell_1_data.sprite
|
||||
spell_table[spell2_button_name].tooltip = spell_2_data and spell_2_data.name or '---'
|
||||
spell_table[spell2_button_name].sprite = spell_2_data.sprite
|
||||
spell_table[spell3_button_name].tooltip = spell_3_data and spell_3_data.name or '---'
|
||||
spell_table[spell3_button_name].sprite = spell_3_data.sprite
|
||||
|
||||
if rpg_t.dropdown_select_index_1 == 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.dropdown_select_index2 == rpg_t.dropdown_select_index then
|
||||
if rpg_t.dropdown_select_index_2 == 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.dropdown_select_index3 == rpg_t.dropdown_select_index then
|
||||
if rpg_t.dropdown_select_index_3 == 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.dropdown_select_index].mana_cost
|
||||
local active_spell = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name)
|
||||
spell_table['mana-cost'].caption = active_spell.mana_cost
|
||||
spell_table['mana'].caption = math.floor(rpg_t.mana)
|
||||
spell_table['maxmana'].caption = math.floor(rpg_t.mana_max)
|
||||
|
||||
@ -148,25 +157,25 @@ function Public.spell_gui_settings(player)
|
||||
table.add(
|
||||
{
|
||||
type = 'sprite-button',
|
||||
sprite = spells[rpg_t.dropdown_select_index1].sprite,
|
||||
sprite = spells[rpg_t.dropdown_select_index_1].sprite,
|
||||
name = spell1_button_name,
|
||||
tooltip = names[rpg_t.dropdown_select_index1] or '---'
|
||||
tooltip = names[rpg_t.dropdown_select_index_1] or '---'
|
||||
}
|
||||
)
|
||||
table.add(
|
||||
{
|
||||
type = 'sprite-button',
|
||||
sprite = spells[rpg_t.dropdown_select_index2].sprite,
|
||||
sprite = spells[rpg_t.dropdown_select_index_2].sprite,
|
||||
name = spell2_button_name,
|
||||
tooltip = names[rpg_t.dropdown_select_index2] or '---'
|
||||
tooltip = names[rpg_t.dropdown_select_index_2] or '---'
|
||||
}
|
||||
)
|
||||
table.add(
|
||||
{
|
||||
type = 'sprite-button',
|
||||
sprite = spells[rpg_t.dropdown_select_index3].sprite,
|
||||
sprite = spells[rpg_t.dropdown_select_index_3].sprite,
|
||||
name = spell3_button_name,
|
||||
tooltip = names[rpg_t.dropdown_select_index3] or '---'
|
||||
tooltip = names[rpg_t.dropdown_select_index_3] or '---'
|
||||
}
|
||||
)
|
||||
|
||||
@ -545,25 +554,41 @@ 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.dropdown_select_index)
|
||||
local index = Public.get_spell_by_index(rpg_t, rpg_t.dropdown_select_name)
|
||||
if not index then
|
||||
index = rpg_t.dropdown_select_index
|
||||
end
|
||||
conjure_gui_input = create_input_element(conjure_input, 'dropdown', false, names, index)
|
||||
|
||||
if not spells[rpg_t.dropdown_select_index1] then
|
||||
rpg_t.dropdown_select_index1 = 1
|
||||
if not spells[rpg_t.dropdown_select_index_1] then
|
||||
rpg_t.dropdown_select_index_1 = 1
|
||||
end
|
||||
if not spells[rpg_t.dropdown_select_index2] then
|
||||
rpg_t.dropdown_select_index2 = 1
|
||||
if not spells[rpg_t.dropdown_select_index_2] then
|
||||
rpg_t.dropdown_select_index_2 = 1
|
||||
end
|
||||
if not spells[rpg_t.dropdown_select_index3] then
|
||||
rpg_t.dropdown_select_index3 = 1
|
||||
if not spells[rpg_t.dropdown_select_index_3] then
|
||||
rpg_t.dropdown_select_index_3 = 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.dropdown_select_index1)
|
||||
local index1 = Public.get_spell_by_index(rpg_t, rpg_t.dropdown_select_name_1)
|
||||
if not index1 then
|
||||
index1 = rpg_t.dropdown_select_index_1
|
||||
end
|
||||
spell_gui_input1 = create_input_element(spell_grid, 'dropdown', false, names, index1)
|
||||
spell_gui_input1.style.maximal_width = 135
|
||||
spell_gui_input2 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t.dropdown_select_index2)
|
||||
local index2 = Public.get_spell_by_index(rpg_t, rpg_t.dropdown_select_name_2)
|
||||
if not index2 then
|
||||
index2 = rpg_t.dropdown_select_index_2
|
||||
end
|
||||
spell_gui_input2 = create_input_element(spell_grid, 'dropdown', false, names, index2)
|
||||
spell_gui_input2.style.maximal_width = 135
|
||||
spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t.dropdown_select_index3)
|
||||
local index3 = Public.get_spell_by_index(rpg_t, rpg_t.dropdown_select_name_3)
|
||||
if not index3 then
|
||||
index3 = rpg_t.dropdown_select_index_3
|
||||
end
|
||||
spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, index3)
|
||||
spell_gui_input3.style.maximal_width = 135
|
||||
spell_grid.add({type = 'sprite-button', name = spell_gui_button_name, sprite = 'item/raw-fish'})
|
||||
end
|
||||
|
@ -1137,6 +1137,36 @@ Public.projectile_types = {
|
||||
Public.get_projectiles = Public.projectile_types
|
||||
Public.all_spells = spells
|
||||
|
||||
--- Gets a spell by index.
|
||||
---@param rpg_t table
|
||||
---@param spell_name string
|
||||
---@return int|boolean
|
||||
function Public.get_spell_by_index(rpg_t, spell_name)
|
||||
local _spells = Public.get_all_spells_filtered(rpg_t)
|
||||
for index, data in pairs(_spells) do
|
||||
if data and data.name[1] == spell_name then
|
||||
return index
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Gets a spell by name.
|
||||
---@param rpg_t table
|
||||
---@param spell_name string
|
||||
---@return table|boolean
|
||||
function Public.get_spell_by_name(rpg_t, spell_name)
|
||||
local _spells = Public.get_all_spells_filtered(rpg_t)
|
||||
for _, data in pairs(_spells) do
|
||||
if data and data.name[1] == spell_name then
|
||||
return data
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Retrieves the spells table or a given spell.
|
||||
---@param key string
|
||||
function Public.get_spells(key)
|
||||
@ -1258,8 +1288,8 @@ function Public.get_all_spells_filtered(rpg_t)
|
||||
local spell_names = {}
|
||||
|
||||
for i = 1, #spells do
|
||||
-- if spells[i].enabled and rpg_t and rpg_t.level >= spells[i].level then -- this needs fixing.
|
||||
if spells[i].enabled then
|
||||
if spells[i].enabled and rpg_t and rpg_t.level >= spells[i].level then -- this needs fixing.
|
||||
-- if spells[i].enabled then
|
||||
new_spells[#new_spells + 1] = spells[i]
|
||||
spell_names[#spell_names + 1] = spells[i].name
|
||||
end
|
||||
|
@ -196,7 +196,7 @@ end
|
||||
|
||||
--- Sets a new table to rpg_t table
|
||||
---@param key string
|
||||
---@param tbl string
|
||||
---@param tbl table
|
||||
function Public.set_new_player_tbl(key, tbl)
|
||||
if key and tbl then
|
||||
if type(tbl) ~= 'table' then
|
||||
|
Loading…
x
Reference in New Issue
Block a user