2015-12-10 10:48:25 +01:00
-- SYS4 Achievements
-- by Sys4
2015-12-10 21:11:09 +01:00
sys4_achievements = { }
2015-12-10 10:48:25 +01:00
-- Init
local S
2015-12-10 21:11:09 +01:00
if minetest.get_modpath ( " intllib " ) then
S = intllib.Getter ( )
2015-12-10 10:48:25 +01:00
else
2015-12-10 21:11:09 +01:00
S = function ( s ) return s end
2015-12-10 10:48:25 +01:00
end
2015-12-10 21:11:09 +01:00
sys4_achievements.intllib = S
2015-12-10 10:48:25 +01:00
if not awards then
return
end
dofile ( minetest.get_modpath ( " sys4_achievements " ) .. " /api.lua " )
-- Achievements table définition
local a = {
2015-12-14 17:49:07 +01:00
-- Miner achievements (dig) --
2015-12-28 00:59:09 +01:00
2015-12-14 17:49:07 +01:00
-- Trees
{ name = ' tree_digger_begins ' ,
2015-12-28 00:59:09 +01:00
title = S ( " My first Tool " ) ,
2015-12-14 17:49:07 +01:00
node = ' default:tree ' ,
2015-12-28 00:59:09 +01:00
desc = S ( " Dig 10 tree blocks. " ) ,
2015-12-15 00:00:42 +01:00
icon = " default_tool_woodaxe.png " ,
2015-12-14 17:49:07 +01:00
type = " dig " ,
2015-12-21 09:33:57 +01:00
target = 10 ,
2015-12-28 00:59:09 +01:00
titems = { ' default:wood ' , ' default:acacia_wood ' , ' default:junglewood ' , ' default:pine_wood ' , ' default:stick ' , ' default:axe_wood ' } ,
tprizes = { ' default:torch ' } ,
tbook = S ( " En coupant du bois, vous vous apercevez qu'à ce rythme la nuit va arriver bien plus vite que prévue. Cela vous décide à faire une hache en bois pour essayer d'accelérer les choses. En outre, voici une torche au cas où. " )
} ,
2015-12-21 18:01:43 +01:00
2015-12-28 00:59:09 +01:00
{ name = ' tree_digger_newbee ' ,
title = S ( " Wooden Tools and Items " ) ,
node = ' default:tree ' ,
desc = S ( " Dig 20 tree blocks. " ) ,
icon = " default_tool_woodpick.png " ,
2015-12-21 18:01:43 +01:00
type = " dig " ,
2015-12-14 17:49:07 +01:00
target = 20 ,
2015-12-28 00:59:09 +01:00
titems = { ' default:pick_wood ' , ' default:sword_wood ' , ' default:shovel_wood ' , ' farming:hoe_wood ' , ' doors:door_wood ' , ' doors:trap_door ' , ' default:ladder ' , ' default:fence_wood ' , ' boats:boat ' , ' default:chest ' } ,
2015-12-10 10:48:25 +01:00
tprizes = nil ,
2015-12-28 00:59:09 +01:00
tbook = S ( " Vous disposez d'assez de bois pour construire votre premier abris. Cela vous a permis de réfléchir à l'élaboration de nouveaux objets qui pourraient vous etres utiles. Dépêchez-vous, la nuit est proche. " )
} ,
2015-12-12 11:14:21 +01:00
2015-12-21 18:01:43 +01:00
}
2015-12-10 10:48:25 +01:00
2015-12-21 18:01:43 +01:00
-- Secrets achievements table
local sa = {
{ name = ' secret_stuff ' ,
title = S ( " Not only Waste " ) ,
node = ' sys4_achievements:waste ' ,
desc = S ( " Dig 10 Waste blocks. " ) ,
icon = " waste.png " ,
type = " dig " ,
target = 10 ,
titems = nil ,
2015-12-28 00:59:09 +01:00
tprizes = { ' default:axe_diamond ' , ' default:pick_diamond ' , ' default:shovel_diamond ' , ' default:sword_diamond ' , ' farming:hoe_diamond ' , ' default:furnace ' , ' default:chest ' , ' default:meselamp ' } ,
tbook = S ( " Vous ne vous avouez pas vaincu si facilement ! \n Ces objets sont pour vous afin de récompenser votre acharnement. " )
2015-12-21 18:01:43 +01:00
}
}
-- Register achievements from tables
for i = 1 , # a do
2015-12-28 00:59:09 +01:00
local tbook = nil
if a [ i ] . tbook and a [ i ] . tbook ~= nil then
tbook = { title = " SYS4 AWARDS : " .. a [ i ] . title ,
text = sys4_achievements.write_book ( a [ i ] . tbook , a [ i ] . titems , a [ i ] . tprizes )
}
end
2015-12-21 18:01:43 +01:00
awards.register_achievement (
a [ i ] . name ,
{
title = a [ i ] . title ,
description = a [ i ] . desc ,
icon = a [ i ] . icon ,
trigger = { type = a [ i ] . type , node = a [ i ] . node , target = a [ i ] . target } ,
items = a [ i ] . titems ,
prizes = a [ i ] . tprizes ,
2015-12-28 00:59:09 +01:00
book = tbook ,
2015-12-21 18:01:43 +01:00
} )
end
2015-12-12 11:14:21 +01:00
for i = 1 , # sa do
2015-12-28 00:59:09 +01:00
local tbook = nil
if a [ i ] . tbook and a [ i ] . tbook ~= nil then
tbook = { title = " SYS4 AWARDS : " .. a [ i ] . title ,
text = sys4_achievements.write_book ( a [ i ] . tbook , a [ i ] . titems , a [ i ] . tprizes )
}
end
2015-12-12 11:14:21 +01:00
awards.register_achievement (
sa [ i ] . name ,
{
title = sa [ i ] . title ,
description = sa [ i ] . desc ,
icon = sa [ i ] . icon ,
trigger = { type = sa [ i ] . type , node = sa [ i ] . node , target = sa [ i ] . target } ,
items = sa [ i ] . titems ,
prizes = sa [ i ] . tprizes ,
2015-12-28 00:59:09 +01:00
book = tbook ,
2015-12-12 11:14:21 +01:00
secret = 1
2015-12-10 10:48:25 +01:00
} )
end
2015-12-17 18:24:25 +01:00
2015-12-21 18:01:43 +01:00
-- Register Specialized steps with some achievements
2015-12-17 18:24:25 +01:00
awards.register_onDig (
function ( player , data )
2015-12-21 09:33:57 +01:00
local playern = player : get_player_name ( )
2015-12-17 18:24:25 +01:00
local achievements = {
sys4_achievements.getAchievement ( " dig " , " tree_digger_begins " ) ,
2015-12-28 00:59:09 +01:00
sys4_achievements.getAchievement ( " dig " , " tree_digger_newbee " ) ,
2015-12-17 18:24:25 +01:00
}
for i = 1 , # achievements do
local achievement = achievements [ i ]
local name = achievement.award
2015-12-21 09:33:57 +01:00
if not sys4_achievements.has_achievement ( playern , name ) then
2015-12-17 18:24:25 +01:00
local node = achievement.node
local target = achievement.target
2015-12-21 09:33:57 +01:00
local mod = " "
local items = { }
2015-12-17 18:24:25 +01:00
if node == ' default:tree ' then
2015-12-21 09:33:57 +01:00
mod = ' default '
items = { ' tree ' , ' jungletree ' , ' pine_tree ' , ' acacia_tree ' }
2015-12-17 18:24:25 +01:00
end
2015-12-21 09:33:57 +01:00
local count = sys4_achievements.getItemCount ( " dig " , mod , items , playern , data )
2015-12-17 18:24:25 +01:00
if count > target - 1 then
return name
end
end
end
end )
awards.register_onPlace (
function ( player , data )
2015-12-21 09:33:57 +01:00
local playern = player : get_player_name ( )
2015-12-17 18:24:25 +01:00
local achievements = {
}
for i = 1 , # achievements do
local achievement = achievements [ i ]
local name = achievement.award
2015-12-21 09:33:57 +01:00
if not sys4_achievements.has_achievement ( playern , name ) then
2015-12-17 18:24:25 +01:00
local node = achievement.node
local target = achievement.target
2015-12-21 09:33:57 +01:00
local mod = " "
local items = { }
local count = sys4_achievements.getItemCount ( " place " , mod , items , playern , data )
2015-12-17 18:24:25 +01:00
if count > target - 1 then
return name
end
end
end
end )
sys4_achievements.register_onCraft (
function ( player , data )
2015-12-21 09:33:57 +01:00
local playern = player : get_player_name ( )
2015-12-17 18:24:25 +01:00
local achievements = {
}
for i = 1 , # achievements do
local achievement = achievements [ i ]
local name = achievement.award
2015-12-21 09:33:57 +01:00
if not sys4_achievements.has_achievement ( playern , name ) then
2015-12-17 18:24:25 +01:00
local node = achievement.node
local target = achievement.target
2015-12-21 09:33:57 +01:00
local mod = " "
local items = { }
local count = sys4_achievements.getItemCount ( " craft " , mod , items , playern , data )
2015-12-17 18:24:25 +01:00
if count > target - 1 then
return name
end
end
end
end )