195 lines
5.4 KiB
Lua
Raw Normal View History

2015-12-10 10:48:25 +01:00
-- SYS4 Achievements
-- by Sys4
sys4_achievements = {}
2015-12-10 10:48:25 +01:00
-- Init
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
2015-12-10 10:48:25 +01:00
else
S = function(s) return s end
2015-12-10 10:48:25 +01:00
end
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-14 17:49:07 +01:00
-- Trees
{ name = 'tree_digger_begins',
title = S("My first Tool"),
2015-12-14 17:49:07 +01:00
node = 'default:tree',
desc = S("Dig 10 tree blocks."),
icon = "default_tool_woodaxe.png",
2015-12-14 17:49:07 +01:00
type = "dig",
target = 10,
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ù.")
},
{ name = 'tree_digger_newbee',
title = S("Wooden Tools and Items"),
node = 'default:tree',
desc = S("Dig 20 tree blocks."),
icon = "default_tool_woodpick.png",
type = "dig",
2015-12-14 17:49:07 +01:00
target = 20,
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,
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-10 10:48:25 +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,
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 !\nCes objets sont pour vous afin de récompenser votre acharnement.")
}
}
-- Register achievements from tables
for i=1, #a do
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
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,
book = tbook,
})
end
for i=1, #sa do
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
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,
book = tbook,
secret = 1
2015-12-10 10:48:25 +01:00
})
end
-- Register Specialized steps with some achievements
awards.register_onDig(
function(player, data)
local playern = player:get_player_name()
local achievements = {
sys4_achievements.getAchievement("dig", "tree_digger_begins"),
sys4_achievements.getAchievement("dig", "tree_digger_newbee"),
}
for i=1, #achievements do
local achievement = achievements[i]
local name = achievement.award
if not sys4_achievements.has_achievement(playern, name) then
local node = achievement.node
local target = achievement.target
local mod = ""
local items = {}
if node == 'default:tree' then
mod = 'default'
items = {'tree', 'jungletree', 'pine_tree', 'acacia_tree'}
end
local count = sys4_achievements.getItemCount("dig", mod, items, playern, data)
if count > target - 1 then
return name
end
end
end
end)
awards.register_onPlace(
function(player, data)
local playern = player:get_player_name()
local achievements = {
}
for i=1, #achievements do
local achievement = achievements[i]
local name = achievement.award
if not sys4_achievements.has_achievement(playern, name) then
local node = achievement.node
local target = achievement.target
local mod = ""
local items = {}
local count = sys4_achievements.getItemCount("place", mod, items, playern, data)
if count > target - 1 then
return name
end
end
end
end)
sys4_achievements.register_onCraft(
function(player, data)
local playern = player:get_player_name()
local achievements = {
}
for i=1, #achievements do
local achievement = achievements[i]
local name = achievement.award
if not sys4_achievements.has_achievement(playern, name) then
local node = achievement.node
local target = achievement.target
local mod = ""
local items = {}
local count = sys4_achievements.getItemCount("craft", mod, items, playern, data)
if count > target - 1 then
return name
end
end
end
end)