From bcc2f64c2e3216a3cededb7fcf1d7c73e2c7886f Mon Sep 17 00:00:00 2001 From: Alex <24834740+GreenXenith@users.noreply.github.com> Date: Thu, 13 Dec 2018 23:48:41 -0800 Subject: [PATCH] Use updated awards API (#31) * Use updated awards API * Fix dig/place incrementing * Use awards.player() in crates * Use new 'dig' incrementor for digtron packing * Only initialize tables if they dont exist * Fix typo * Remove init function, use checks instead --- awards.lua | 123 ++++++++++++++++++++++------------------ class_layout.lua | 4 -- nodes/node_builders.lua | 2 +- nodes/node_crate.lua | 4 +- util_execute_cycle.lua | 2 +- 5 files changed, 72 insertions(+), 63 deletions(-) diff --git a/awards.lua b/awards.lua index c4b98ea..cf5ccc6 100644 --- a/awards.lua +++ b/awards.lua @@ -1,8 +1,8 @@ if not minetest.get_modpath("awards") then - digtron.award_item_dug = function (items, player, count) end - digtron.award_layout = function (layout, player) end - digtron.award_item_built = function(item_name, player) end - digtron.award_crate = function (layout, player) end + digtron.award_item_dug = function (items, name, count) end + digtron.award_layout = function (layout, name) end + digtron.award_item_built = function(item_name, name) end + digtron.award_crate = function (layout, name) end return end --------------------------------------------------------------------------- @@ -11,18 +11,24 @@ end local MP = minetest.get_modpath(minetest.get_current_modname()) local S, NS = dofile(MP.."/intllib.lua") -digtron.award_item_dug = function (items_dropped, player) - if table.getn(items_dropped) == 0 then +digtron.award_item_dug = function (items_dropped, name) + if table.getn(items_dropped) == 0 or not name or name == "" then return end - local data = awards.players[player] + local data = awards.player(name) + + if not data.digtron_dug_groups then + data.digtron_dug_groups = { + tree = 0, + dirt = 0, + grass = 0, + } + end + if not data.digtron_dug then + data.digtron_dug = {} + end - awards.tbv(data, "digtron_dug_groups") - awards.tbv(data["digtron_dug_groups"], "tree", 0) - awards.tbv(data["digtron_dug_groups"], "dirt", 0) - awards.tbv(data["digtron_dug_groups"], "grass", 0) - for _, item in pairs(items_dropped) do awards.increment_item_counter(data, "digtron_dug", item) if minetest.get_item_group(item, "tree") > 0 then @@ -37,111 +43,118 @@ digtron.award_item_dug = function (items_dropped, player) end if awards.get_item_count(data, "digtron_dug", "default:mese_crystal") > 100 then - awards.unlock(player, "digtron_100mese_dug") + awards.unlock(name, "digtron_100mese_dug") end if awards.get_item_count(data, "digtron_dug", "default:diamond") > 100 then - awards.unlock(player, "digtron_100diamond_dug") + awards.unlock(name, "digtron_100diamond_dug") end if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 1000 then - awards.unlock(player, "digtron_1000coal_dug") + awards.unlock(name, "digtron_1000coal_dug") if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 10000 then - awards.unlock(player, "digtron_10000coal_dug") + awards.unlock(name, "digtron_10000coal_dug") end end if awards.get_item_count(data, "digtron_dug", "default:iron_lump") > 1000 then - awards.unlock(player, "digtron_1000iron_dug") + awards.unlock(name, "digtron_1000iron_dug") end if awards.get_item_count(data, "digtron_dug", "default:copper_lump") > 1000 then - awards.unlock(player, "digtron_1000copper_dug") + awards.unlock(name, "digtron_1000copper_dug") end if awards.get_item_count(data, "digtron_dug", "default:gold_lump") > 100 then - awards.unlock(player, "digtron_100gold_dug") + awards.unlock(name, "digtron_100gold_dug") end - local total_count = awards.get_total_item_count(data, "digtron_dug") + local total_count = awards.get_total_keyed_count(data, "digtron_dug") if total_count > 1000 then - awards.unlock(player, "digtron_1000_dug") + awards.unlock(name, "digtron_1000_dug") if total_count > 10000 then - awards.unlock(player, "digtron_10000_dug") + awards.unlock(name, "digtron_10000_dug") if total_count > 100000 then - awards.unlock(player, "digtron_100000_dug") + awards.unlock(name, "digtron_100000_dug") if total_count > 1000000 then - awards.unlock(player, "digtron_1000000_dug") + awards.unlock(name, "digtron_1000000_dug") end end end end if data["digtron_dug_groups"]["tree"] > 1000 then - awards.unlock(player, "digtron_1000wood_dug") + awards.unlock(name, "digtron_1000wood_dug") if data["digtron_dug_groups"]["tree"] > 10000 then - awards.unlock(player, "digtron_10000wood_dug") + awards.unlock(name, "digtron_10000wood_dug") end end if data["digtron_dug_groups"]["dirt"] > 1000 then - awards.unlock(player, "digtron_1000dirt_dug") + awards.unlock(name, "digtron_1000dirt_dug") end if data["digtron_dug_groups"]["grass"] > 1000 then - awards.unlock(player, "digtron_1000grass_dug") + awards.unlock(name, "digtron_1000grass_dug") end end -digtron.award_item_built = function(item_name, player) - local data = awards.players[player] +digtron.award_item_built = function(item_name, name) + if not name or name == "" then + return + end + local data = awards.player(name) + if not data.digtron_built then + data.digtron_built = {} + end + awards.increment_item_counter(data, "digtron_built", item_name) - local total_count = awards.get_total_item_count(data, "digtron_built") + local total_count = awards.get_total_keyed_count(data, "digtron_built") if total_count > 1000 then - awards.unlock(player, "digtron_1000_built") + awards.unlock(name, "digtron_1000_built") if total_count > 10000 then - awards.unlock(player, "digtron_10000_built") + awards.unlock(name, "digtron_10000_built") end end end -digtron.award_layout = function (layout, player) - if layout == nil or player == nil or player == "" then +digtron.award_layout = function(layout, name) + if layout == nil or not name or name == "" then return end if layout.water_touching then - awards.unlock(player, "digtron_water") + awards.unlock(name, "digtron_water") end if layout.lava_touching then - awards.unlock(player, "digtron_lava") + awards.unlock(name, "digtron_lava") end if table.getn(layout.all) > 9 then - awards.unlock(player, "digtron_size10") + awards.unlock(name, "digtron_size10") if table.getn(layout.all) > 99 then - awards.unlock(player, "digtron_size100") + awards.unlock(name, "digtron_size100") end end if table.getn(layout.diggers) > 24 then - awards.unlock(player, "digtron_digger25") + awards.unlock(name, "digtron_digger25") end if table.getn(layout.builders) > 24 then - awards.unlock(player, "digtron_builder25") + awards.unlock(name, "digtron_builder25") end if layout.controller.y > 100 then - awards.unlock(player, "digtron_height100") + awards.unlock(name, "digtron_height100") if layout.controller.y > 1000 then - awards.unlock(player, "digtron_height1000") + awards.unlock(name, "digtron_height1000") end elseif layout.controller.y < -100 then - awards.unlock(player, "digtron_depth100") + awards.unlock(name, "digtron_depth100") if layout.controller.y < -1000 then - awards.unlock(player, "digtron_depth1000") + awards.unlock(name, "digtron_depth1000") if layout.controller.y < -2000 then - awards.unlock(player, "digtron_depth2000") + awards.unlock(name, "digtron_depth2000") if layout.controller.y < -4000 then - awards.unlock(player, "digtron_depth4000") + awards.unlock(name, "digtron_depth4000") if layout.controller.y < -8000 then - awards.unlock(player, "digtron_depth8000") + awards.unlock(name, "digtron_depth8000") if layout.controller.y < -16000 then - awards.unlock(player, "digtron_depth16000") + awards.unlock(name, "digtron_depth16000") if layout.controller.y < -30000 then - awards.unlock(player, "digtron_depth30000") + awards.unlock(name, "digtron_depth30000") end end end @@ -151,16 +164,16 @@ digtron.award_layout = function (layout, player) end end -digtron.award_crate = function (layout, player) - if layout == nil or player == nil or player == "" then +digtron.award_crate = function(layout, name) + if layout == nil or not name or name == "" then return end -- Note that we're testing >10 rather than >9 because this layout includes the crate node if table.getn(layout.all) > 10 then - awards.unlock(player, "digtron_crate10") + awards.unlock(name, "digtron_crate10") if table.getn(layout.all) > 100 then - awards.unlock(player, "digtron_crate100") + awards.unlock(name, "digtron_crate100") end end end @@ -401,4 +414,4 @@ awards.register_achievement("digtron_crate100",{ description = S("Stored 100 or more Digtron blocks in one crate."), background = "awards_bg_mining.png", icon = "digtron_plate.png^digtron_crate.png", -- TODO: Visually distinguish this from Bigtron -}) \ No newline at end of file +}) diff --git a/class_layout.lua b/class_layout.lua index 541fd35..c69d3bd 100644 --- a/class_layout.lua +++ b/class_layout.lua @@ -335,8 +335,6 @@ local node_callbacks = function(dug_nodes, placed_nodes, player) local old_node = dug_node[2] local old_meta = dug_node[3] - minetest.log("action", string.format("%s removes Digtron component %s at (%d, %d, %d)", player:get_player_name(), old_node.name, old_pos.x, old_pos.y, old_pos.z)) - for _, callback in ipairs(minetest.registered_on_dignodes) do -- Copy pos and node because callback can modify them local pos_copy = {x=old_pos.x, y=old_pos.y, z=old_pos.z} @@ -354,8 +352,6 @@ local node_callbacks = function(dug_nodes, placed_nodes, player) local new_pos = placed_node[1] local new_node = placed_node[2] local old_node = placed_node[3] - - minetest.log("action", string.format("%s adds Digtron component %s at (%d, %d, %d)", player:get_player_name(), new_node.name, new_pos.x, new_pos.y, new_pos.z)) for _, callback in ipairs(minetest.registered_on_placenodes) do -- Copy pos and node because callback can modify them diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 8cc91b4..0d523b7 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -305,4 +305,4 @@ minetest.register_node("digtron:builder", { end return built_count end, -}) \ No newline at end of file +}) diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index 6484ef5..f060f10 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -59,8 +59,8 @@ local store_digtron = function(pos, clicker, loaded_node_name, protected) if modpath_awards then -- We're about to tell the awards mod that we're digging a node, but we -- don't want it to count toward any actual awards. Pre-decrement. - local data = awards.players[clicker:get_player_name()] - awards.increment_item_counter(data, "count", old_node.name, -1) + local data = awards.player(clicker:get_player_name()) + awards.increment_item_counter(data, "dig", old_node.name, -1) end for _, callback in ipairs(minetest.registered_on_dignodes) do diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index b294aa2..1c7ba4a 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -580,4 +580,4 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) node_to_dig, whether_to_dig = layout.nodes_dug:pop() end return pos, status_text, 0 -end \ No newline at end of file +end