CRASHFIX: add sanity check for unlocked skills when players join (in case the skills mod database has been deleted)

This commit is contained in:
marco_a 2023-12-08 16:43:44 +01:00
parent 8c46e6f9f7
commit b46a061989
3 changed files with 29 additions and 9 deletions

View File

@ -119,14 +119,14 @@ function equip(arena, p_name)
local weapons = block_league.get_player_weapons(p_name)
local propulsor = arena.mode == 1 and "block_league:propulsor" or "block_league:propulsor_dm"
for i, weapon_name in pairs(weapons) do
for _, weapon_name in pairs(weapons) do
inv:add_item("main", ItemStack(weapon_name))
end
inv:add_item("main", ItemStack(propulsor))
local skill = block_league.get_player_skill(p_name)
p_name:get_skill(skill):enable()
p_name:enable_skill(skill)
end
end

View File

@ -1,17 +1,16 @@
local p_data = {} -- KEY: p_name, INDEX: {equip = {weapons = {...}, skill = s_name}}
local storage = minetest.get_mod_storage()
local function unlock_default_skills() end
local p_data = {} -- KEY: p_name, INDEX: {equip = {weapons = {...}, skill = s_name}}
function block_league.create_player_data(p_name)
local default_weapons = {"block_league:smg", "block_league:sword", "block_league:pixelgun"}
local default_skill = "block_league:hp"
p_name:unlock_skill("block_league:hp")
p_name:unlock_skill("block_league:sp")
p_name:get_skill("block_league:hp"):disable()
p_name:get_skill("block_league:sp"):disable()
unlock_default_skills(p_name)
--TODO: indagare "non puoi usare questa abilità adesso" inviato due volte al primo accesso
@ -29,12 +28,18 @@ end
function block_league.load_player_data(p_name)
-- inserire qui nuove abilità da sbloccare automaticamente
-- in case skills' database has been reset
if not next(p_name:get_unlocked_skills("block_league")) then
unlock_default_skills(p_name)
end
p_data[p_name] = minetest.deserialize(storage:get_string(p_name))
block_league.set_player_weapons(p_name, p_data[p_name].equip.weapons)
block_league.set_player_skill(p_name, p_data[p_name].equip.skill)
end
-- appunti per il futuro:
-- 1. meglio tenere `type` e `param`, dato che si allacceranno armi, abilità,
-- esperienza e valuta della mod;
@ -54,3 +59,18 @@ end
function block_league.is_player_in_storage(p_name)
return storage:get_string(p_name) ~= ""
end
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function unlock_default_skills(p_name)
p_name:unlock_skill("block_league:hp")
p_name:unlock_skill("block_league:sp")
p_name:get_skill("block_league:hp"):disable()
p_name:get_skill("block_league:sp"):disable()
end

View File

@ -26,7 +26,7 @@ minetest.register_on_joinplayer(function(player)
remove_weapons(player:get_inventory())
-- se il server è crashato, disabilito l'abilità rimasta
p_name:get_skill(block_league.get_player_skill(p_name)):disable()
p_name:disable_skill(block_league.get_player_skill(p_name))
end)