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
This commit is contained in:
Alex 2018-12-13 23:48:41 -08:00 committed by FaceDeer
parent 1011901938
commit bcc2f64c2e
5 changed files with 72 additions and 63 deletions

@ -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,17 +11,23 @@ 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)
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)
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
for _, item in pairs(items_dropped) do
awards.increment_item_counter(data, "digtron_dug", item)
@ -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

@ -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}
@ -355,8 +353,6 @@ local node_callbacks = function(dug_nodes, placed_nodes, player)
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
local pos_copy = {x=new_pos.x, y=new_pos.y, z=new_pos.z}

@ -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