Gain experience toward skills by crafting
This commit is contained in:
parent
1fe2bfdb4c
commit
e769d22a00
@ -76,6 +76,25 @@ function skills.add_exp(name, exp)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function skills.add_skill_exp(name, skill_id, exp)
|
||||||
|
local sk = skills.get_skill(name,skill_id)
|
||||||
|
local skill = skills.available_skills[skill_id]
|
||||||
|
local next_level = math.floor(((sk.level^1.75) * skill.level_exp))
|
||||||
|
local pskills = pd.get(name,"skills")
|
||||||
|
|
||||||
|
pskills[skill_id].exp = pskills[skill_id].exp + exp
|
||||||
|
local increased = false
|
||||||
|
while pskills[skill_id].exp >= next_level and pskills[skill_id].level < skill.max_level do
|
||||||
|
increased = true
|
||||||
|
pskills[skill_id].level = pskills[skill_id].level + 1
|
||||||
|
pskills[skill_id].exp = pskills[skill_id].exp - next_level
|
||||||
|
next_level = math.floor(((pskills[skill_id].level^1.75) * skill.level_exp))
|
||||||
|
end
|
||||||
|
|
||||||
|
pd.set(name,"skills",pskills)
|
||||||
|
return increased
|
||||||
|
end
|
||||||
|
|
||||||
function skills.get_probability(name, skill1, skill2)
|
function skills.get_probability(name, skill1, skill2)
|
||||||
--print("get_probablilty("..name..","..tostring(skill1)..","..tostring(skill2)..")")
|
--print("get_probablilty("..name..","..tostring(skill1)..","..tostring(skill2)..")")
|
||||||
if ( name == nil or name == "" ) then
|
if ( name == nil or name == "" ) then
|
||||||
@ -116,20 +135,8 @@ minetest.register_on_joinplayer(function (player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local skill_id = tonumber(listname)
|
local skill_id = tonumber(listname)
|
||||||
local exp_dropped = stack:get_definition().exp_value * stack:get_count()
|
local exp_dropped = stack:get_definition().exp_value * stack:get_count()
|
||||||
local sk = skills.get_skill(name,skill_id)
|
|
||||||
local skill = skills.available_skills[skill_id]
|
|
||||||
local next_level = math.floor(((sk.level^1.75) * skill.level_exp))
|
|
||||||
local pskills = pd.get(name,"skills")
|
|
||||||
|
|
||||||
pskills[skill_id].exp = pskills[skill_id].exp + exp_dropped
|
skills.add_skill_exp(name,skill_id,exp_dropped)
|
||||||
|
|
||||||
while pskills[skill_id].exp >= next_level and pskills[skill_id].level < skill.max_level do
|
|
||||||
pskills[skill_id].level = pskills[skill_id].level + 1
|
|
||||||
pskills[skill_id].exp = pskills[skill_id].exp - next_level
|
|
||||||
next_level = math.floor(((pskills[skill_id].level^1.75) * skill.level_exp))
|
|
||||||
end
|
|
||||||
|
|
||||||
pd.set(name,"skills",pskills)
|
|
||||||
|
|
||||||
stack:clear()
|
stack:clear()
|
||||||
inv:set_stack(listname,index,stack)
|
inv:set_stack(listname,index,stack)
|
||||||
|
@ -84,11 +84,17 @@ end
|
|||||||
|
|
||||||
local function on_craft(itemstack,player,old_craftgrid,craft_inv)
|
local function on_craft(itemstack,player,old_craftgrid,craft_inv)
|
||||||
if itemstack:get_definition().skill ~= nil then
|
if itemstack:get_definition().skill ~= nil then
|
||||||
local probability = skills.get_probability(player:get_player_name(),SKILL_CRAFTING,itemstack:get_definition().skill)
|
local name = player:get_player_name()
|
||||||
|
local probability = skills.get_probability(name,SKILL_CRAFTING,itemstack:get_definition().skill)
|
||||||
local rangeLow = ( probability - 10 ) / 100
|
local rangeLow = ( probability - 10 ) / 100
|
||||||
probability = probability / 100
|
probability = probability / 100
|
||||||
local wear = math.floor(50000 - ( 50000 * math.random(rangeLow,probability) ))
|
local wear = math.floor(50000 - ( 50000 * math.random(rangeLow,probability) ))
|
||||||
itemstack:add_wear(wear)
|
itemstack:add_wear(wear)
|
||||||
|
local i = skills.add_skill_exp(name,SKILL_CRAFTING,1)
|
||||||
|
local ii = skills.add_skill_exp(name,itemstack:get_definition().skill,1)
|
||||||
|
if i or ii then
|
||||||
|
minetest.chat_send_player(name,"Your skills are increasing!")
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user