From 19d9b3efb85bdc4cf78a9132adcb60e7d7c08a37 Mon Sep 17 00:00:00 2001 From: ANAND Date: Sat, 28 Dec 2019 15:04:26 +0530 Subject: [PATCH] ctf_map_core: Move treasure registration into meta_helpers.lua (#545) --- .../ctf/ctf_map/ctf_map_core/meta_helpers.lua | 57 +++++++++++++++++++ mods/ctf/ctf_map/ctf_map_core/schem_map.lua | 48 +--------------- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_map_core/meta_helpers.lua b/mods/ctf/ctf_map/ctf_map_core/meta_helpers.lua index b5b9a50..186609a 100644 --- a/mods/ctf/ctf_map/ctf_map_core/meta_helpers.lua +++ b/mods/ctf/ctf_map/ctf_map_core/meta_helpers.lua @@ -64,6 +64,63 @@ local function update_physics(player) }) end +--------------------------- +-- TREASURE REGISTRATION -- +--------------------------- + +function ctf_map.register_treasures(map) + if not ctf_treasure then + return + end + + treasurer.treasures = {} + if map.treasures then + for _, item in pairs(map.treasures) do + item = item:split(",") + -- treasurer.register_treasure(name, rarity, preciousness, count) + if #item == 4 then + treasurer.register_treasure(item[1], + tonumber(item[2]), + tonumber(item[3]), + tonumber(item[4]) + ) + -- treasurer.register_treasure(name, rarity, preciousness, {min, max}) + elseif #item == 5 then + treasurer.register_treasure(item[1], + tonumber(item[2]), + tonumber(item[3]), + { + tonumber(item[4]), + tonumber(item[5]) + } + ) + end + end + else + -- If treasure is a part of map's initial stuff, don't register it + local blacklist = ctf_map.map.initial_stuff or give_initial_stuff.get_stuff() + for _, def in pairs(ctf_treasure.get_default_treasures()) do + local is_valid = true + for _, b_item in pairs(blacklist) do + local b_stack = ItemStack(b_item) + local t_stack = ItemStack(def[1]) + if b_stack:get_name() == t_stack:get_name() and + t_stack:get_count() == 1 then + is_valid = false + minetest.log("info", + "ctf_map: Omitting treasure - " .. def[1]) + break + end + end + if is_valid then + minetest.log("info", + "ctf_map: Registering treasure - " .. def[1]) + treasurer.register_treasure(def[1], def[2], def[3], def[4]) + end + end + end +end + --------------- -- CALLBACKS -- --------------- diff --git a/mods/ctf/ctf_map/ctf_map_core/schem_map.lua b/mods/ctf/ctf_map/ctf_map_core/schem_map.lua index 5a00ac0..788d050 100644 --- a/mods/ctf/ctf_map/ctf_map_core/schem_map.lua +++ b/mods/ctf/ctf_map/ctf_map_core/schem_map.lua @@ -380,53 +380,7 @@ ctf_match.register_on_new_match(function() -- Register per-map treasures, or the default set of treasures -- if treasures field hasn't been defined in map meta - if ctf_treasure then - treasurer.treasures = {} - if ctf_map.map.treasures then - for _, item in pairs(ctf_map.map.treasures) do - item = item:split(",") - -- treasurer.register_treasure(name, rarity, preciousness, count) - if #item == 4 then - treasurer.register_treasure(item[1], - tonumber(item[2]), - tonumber(item[3]), - tonumber(item[4])) - -- treasurer.register_treasure(name, rarity, preciousness, {min, max}) - elseif #item == 5 then - treasurer.register_treasure(item[1], - tonumber(item[2]), - tonumber(item[3]), - { - tonumber(item[4]), - tonumber(item[5]) - }) - end - end - else - -- If treasure is a part of map's initial stuff, don't register it - local blacklist = ctf_map.map.initial_stuff or give_initial_stuff.get_stuff() - for _, def in pairs(ctf_treasure.get_default_treasures()) do - local is_valid = true - for _, b_item in pairs(blacklist) do - local b_stack = ItemStack(b_item) - local t_stack = ItemStack(def[1]) - if b_stack:get_name() == t_stack:get_name() and - t_stack:get_count() == 1 then - is_valid = false - minetest.log("info", - "ctf_map: Omitting treasure - " .. def[1]) - break - end - end - - if is_valid then - minetest.log("info", - "ctf_map: Registering treasure - " .. def[1]) - treasurer.register_treasure(def[1], def[2], def[3], def[4]) - end - end - end - end + ctf_map.register_treasures(ctf_map.map) -- Place map place_map(ctf_map.map)