From e110bbbc7a8dea47b9ed536fcd31dc21169c6bd6 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 5 Apr 2018 17:00:41 +0100 Subject: Add award unlock requirements Fixes #52 --- api.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'api.lua') diff --git a/api.lua b/api.lua index 39f7f09..1cf05f9 100644 --- a/api.lua +++ b/api.lua @@ -296,6 +296,19 @@ function awards.register_achievement(name, def) tdef:on_register(def) end + function def:can_unlock(data) + if not self.requires then + return true + end + + for i=1, #self.requires do + if not data.unlocked[self.requires[i]] then + return false + end + end + return true + end + -- Add Award awards.registered_awards[name] = def @@ -341,6 +354,12 @@ function awards.unlock(name, award) return end + if not awdef:can_unlock(data) then + minetest.log("warning", "can_unlock returned false in unlock of " .. + award .. " for " .. name) + return + end + -- Unlock Award minetest.log("action", name.." has unlocked award "..name) data.unlocked[award] = award -- cgit v1.2.3