Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial whynot_awards #66

Merged
merged 42 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8a6805a
initial whynot_awards
bell07 Feb 23, 2022
c34052c
Apply dacmot's suggestions from code review
Lazerbeak12345 Aug 18, 2022
2306fe5
Initial awards tree draft
dacmot Oct 5, 2022
7df510e
Add awards tree PDF
dacmot Oct 5, 2022
48e3cd3
export ignore private folder
dacmot Oct 5, 2022
472c5b4
Make graph fit on one page
dacmot Oct 5, 2022
4bee63a
Rotate PDF 90deg
dacmot Oct 15, 2022
76bcf5b
Initial work on new awards
dacmot Feb 10, 2024
fde02af
WIP
dacmot Feb 14, 2024
722ac74
Add wild seeds collection award
dacmot Feb 20, 2024
7a88bcc
Update awards graph
dacmot Feb 22, 2024
971424f
Refactor trigger functions
dacmot Feb 22, 2024
aee68b0
Add farming awards and triggers
dacmot Feb 24, 2024
d41805e
Remove debugging code
dacmot Feb 24, 2024
3811d09
Correction to store previous value
dacmot Feb 26, 2024
4ca957a
Add award for planting crops
dacmot Mar 3, 2024
778d59f
Remove redundant award dependency
dacmot Mar 5, 2024
9b69730
Various little fixes and tweaks
dacmot Mar 5, 2024
124e09e
Add triggers for max distance, depth and altitude
dacmot Mar 5, 2024
010666b
Add more awards
dacmot Mar 5, 2024
95b97f7
Add well and chocolate awards
dacmot Mar 8, 2024
1f0d772
Add craft furnace and make distance awards harder
dacmot Mar 8, 2024
b47e334
Merge branch 'main' into whynot_awards
dacmot Mar 8, 2024
8055453
Merge remote-tracking branch 'upstream/whynot_awards' into whynot_awards
dacmot Mar 8, 2024
ac9b1ac
Merge branch 'whynot_awards' into new_awards
dacmot Mar 8, 2024
d7882e3
Merge remote-tracking branch 'upstream/main' into new_awards
dacmot Mar 15, 2024
cba4838
Add many awards that lead to the supercub airplane
dacmot Mar 16, 2024
34b46ef
Correct supercub awards
dacmot Mar 18, 2024
455b445
Allow variable rate subbanding
dacmot Mar 18, 2024
581ded6
Remove redundant nil check
dacmot Mar 20, 2024
0c0068c
Move many dependencies to optional and add more optional ones
dacmot Mar 23, 2024
cb113c1
Make sure the old dig_after_node function is still called
dacmot Mar 30, 2024
0515917
Add mtg_plus to optional dependencies to ensure it loads before us
dacmot Mar 31, 2024
2218cc6
Correct a few typos
dacmot Mar 31, 2024
112bbde
Add French translation
dacmot Mar 31, 2024
85d1f5d
Cleanups an optimizations
dacmot Mar 31, 2024
2780b8b
Started making images from existing textures
dacmot Apr 6, 2024
390d3ab
More texture modifiers
dacmot Apr 6, 2024
50fa89c
French translation correction
dacmot Apr 7, 2024
338164d
Complete replacing textures with modifiers
dacmot Apr 7, 2024
f3199b7
Remove extra spaces
dacmot Apr 14, 2024
b4d88a4
Add distance, depth, altitude awards icons
dacmot Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.* export-ignore
builder export-ignore
private export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.dia.autosave
54 changes: 54 additions & 0 deletions builder/mods_src/libs/whynot_awards/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Set builtin awards to hidden
Lazerbeak12345 marked this conversation as resolved.
Show resolved Hide resolved
-- 4 awards are registered with minetest.after() so these cannot be hidden

awards.registered_awards = {}


awards.register_award("whynot_spawnpoint", {
title = "Find your new home",
description = "Your home is the place with your bed. If you sleep once in bed, you always respawn at this position in case of death",
icon = "beds_bed.png",
-- prices = { }, -- Price is a new home ;-)
-- on_unlock = function(name, def) end

})

local orig_beds_on_rightclick = beds.on_rightclick
function beds.on_rightclick(pos, player)
orig_beds_on_rightclick(pos, player)
local player_name = player:get_player_name()
if beds.player[player_name] then
awards.unlock(player_name, "whynot_spawnpoint")
end
end


awards.register_award("whynot_welcome", {
title = "Welcome to the WhyNot? game",
icon = "beds_bed.png",
description = "You are embarking on a Minetest journey. Whether it's for the thrill of survival, the satisfaction of exploration, or the arts of crafting and creative designs, we hope you will find it enjoyable.",
trigger = {
type = "join",
target = 2,
},
})

awards.register_award("whynot_tree",{
title = "Lumberjack",
description = "Chop some wood, karate-style",
trigger = {
type = "dig",
node = "group:tree",
target = 2,
},
})

awards.register_award("whynot_planks",{
title = "Woody",
description = "Chop some wood, karate-style",
trigger = {
type = "craft",
item = "group:plank",
target = 2,
},
})
2 changes: 2 additions & 0 deletions builder/mods_src/libs/whynot_awards/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = whynot_awards
depends = awards, beds, mtg_plus
dacmot marked this conversation as resolved.
Show resolved Hide resolved
300 changes: 300 additions & 0 deletions mods/libs/whynot_awards/custom_triggers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
-- Check if a player object is valid for awards.
local function player_ok(player)
return minetest.is_player(player) and minetest.player_exists(player:get_player_name())
end

-- Don't actually use translator here. We define empty S() to fool the update_translations script
-- into extracting those strings for the templates. Actual translation is done in api_triggers.lua.
local S = function (str)
return str
end


minetest.register_on_joinplayer(function(player, _)
if (player_ok(player)) then
local awards_data = awards.player(player:get_player_name())
if (awards_data) then
awards_data["max"] = awards_data["max"] or {}
awards_data["max"]["depth"] = awards_data["max"]["depth"] or 0
awards_data["max"]["altitude"] = awards_data["max"]["altitude"] or 0
awards_data["max"]["distance"] = awards_data["max"]["distance"] or 0

awards_data["prev_eatwildfood_eat"] = awards_data["prev_eatwildfood_eat"] or {}
awards_data["prev_gatherfruitvegetable_collect"] = awards_data["prev_gatherfruitvegetable_collect"] or {}
awards_data["prev_plant_crops_place"] = awards_data["prev_plant_crops_place"] or {}
awards_data["prev_gatherwildseeds_collect"] = awards_data["prev_gatherwildseeds_collect"] or {}
end
end
end)


local function check_action_with_item_in_collection(trigger_name, award_action, itemname, collection, player)
if (not (player_ok(player) and collection[itemname])) then
return
end

local awards_data = awards.player(player:get_player_name())
if (awards_data) then
itemname = minetest.registered_aliases[itemname] or itemname

-- Uncomment to debug with qa_block
Whynot_awards.playerawardsdata = awards_data

local prev_action = "prev_"..trigger_name.."_"..award_action
local award_action_counts = awards_data[award_action]
local prev_action_counts = awards_data[prev_action]

local items_collected = award_action_counts[itemname]
if (prev_action_counts[itemname] ~= items_collected and (items_collected <= 1 or prev_action_counts[itemname] == nil)) then
awards["notify_"..trigger_name](player)
prev_action_counts[itemname] = items_collected
end
end
end


local function check_action_with_collection(trigger_name, award_action, collection, player)
if (not player_ok(player)) then
return
end

local awards_data = awards.player(player:get_player_name())
if (awards_data) then
-- Uncomment to debug with qa_block
Whynot_awards.playerawardsdata = awards_data

local prev_action = "prev_"..trigger_name.."_"..award_action
local award_action_counts = awards_data[award_action]
local prev_action_counts = awards_data[prev_action]

local notify_award_trigger = awards["notify_"..trigger_name]

for _, itemname in pairs(collection) do
local items_collected = award_action_counts[itemname]
if (prev_action_counts[itemname] ~= items_collected and (items_collected <= 1 or prev_action_counts[itemname] == nil)) then
notify_award_trigger(player)
prev_action_counts[itemname] = items_collected
end
end
end
end


------------------------------------
awards.register_trigger("collect", {
type = "counted_key",
progress = S("@1/@2 collected"),
auto_description = { S("Collect: @2"), S("Collect: @1×@2") },
auto_description_total = { S("Collect @1 items."), S("Collect @1 items.") },
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.item] or def.trigger.item
end,
key_is_item = true,
})

local base_minetest_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if (not player_ok(digger)) then
return
end

-- Uncomment to debug with qa_block
local awards_data = awards.player(digger:get_player_name())
Whynot_awards.playerawardsdata = awards_data

for _, itemstr in ipairs(drops) do
local itemstack = ItemStack(itemstr)
if (not itemstack:is_empty()) then
awards.notify_collect(digger, itemstack:get_name(), itemstack:get_count())
end
end

return base_minetest_handle_node_drops(pos, drops, digger)
end


----------------------------------------
awards.register_trigger("eatwildfood", {
type = "counted",
progress = S("@1/@2 eaten"),
auto_description = { S("Eat @2 wild food"), S("Eat @1×@2 different wild foods") },
})

local foodstuff_to_gather = {}
foodstuff_to_gather["default:apple"] = 1
foodstuff_to_gather["flowers:mushroom_brown"] = 1
foodstuff_to_gather["default:blueberries"] = 1
minetest.register_on_item_eat(function(_, _, itemstack, player, _)
check_action_with_item_in_collection("eatwildfood", "eat", itemstack:get_name(), foodstuff_to_gather, player)
end)


--------------------------------
awards.register_trigger("max", {
type = "counted_key",
progress = S("@1/@2 reached"),
auto_description = { S("Reach @2"), S("Reach @1 @2") },
get_key = function (self, def)
return def.trigger.max_param
end,
})

local player_index = 1
local subbanding = 5
local function check_positions()
local connected_players = minetest.get_connected_players()
if player_index > #connected_players then
player_index = 1
end

local end_index = math.min(player_index + subbanding, #connected_players)
for i = player_index, end_index do
local player = connected_players[i]
if (player_ok(player)) then
local awards_data = awards.player(player:get_player_name())
if (awards_data) then
local position = player:get_pos()
local py = position.y
local max_data = awards_data["max"]

local depth_delta = math.floor(math.min(py + max_data["depth"], 0))
if (depth_delta < 0) then
awards.notify_max(player, "depth", math.abs(depth_delta))
end

local altitude_delta = math.floor(math.max(py - max_data["altitude"], 0))
if (altitude_delta > 0) then
awards.notify_max(player, "altitude", altitude_delta)
end

local px = position.x
local pz = position.z
local distance = math.floor(math.sqrt(px * px + pz * pz))
local distance_delta = math.max(distance - max_data["distance"], 0)
if (distance_delta > 0) then
awards.notify_max(player, "distance", distance_delta)
end
end
end
end

player_index = player_index + player_index - end_index
minetest.after(1, check_positions)
end
check_positions()


if (minetest.get_modpath("farming") and minetest.global_exists("farming") and farming.mod == "redo") then

-------------------------------------------
awards.register_trigger("gatherwildseeds",{
type = "counted",
progress = S("@1/@2 grains found"),
auto_description = { S("Find @2 wild seed"), S("Find @1×@2 different wild seeds") },
})

local grains_to_gather = {"farming:seed_wheat", "farming:seed_oat", "farming:seed_barley", "farming:seed_rye", "farming:seed_cotton", "farming:rice", "farming:seed_hemp"}
local function check_wildseeds(grassname)
local grassitem = minetest.registered_nodes[grassname]
if (grassitem) then
local old_after_dig_node = grassitem.after_dig_node
minetest.override_item(grassname, {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if (old_after_dig_node) then
old_after_dig_node(pos, oldnode, oldmetadata, digger)
end
check_action_with_collection("gatherwildseeds", "collect", grains_to_gather, digger)
end
})
end
end

-- Grass drops overrides from farming/grass.lua
for i = 4, 5 do
check_wildseeds("default:grass_" .. i)

if minetest.registered_nodes["default:dry_grass_1"] then
check_wildseeds("default:dry_grass_" .. i)
end
end

check_wildseeds("default:junglegrass")

------------------------------------------------
awards.register_trigger("gatherfruitvegetable",{
type = "counted",
progress = S("@1/@2 fruits and vegetables found"),
auto_description = { S("Find @2 fruit or vegetable"), S("Find @1×@2 different fruits and vegetables") },
})

local function check_fruits_and_vegetables(cropname, index)
local fullcropname = cropname .. "_" .. index
local node = minetest.registered_nodes[fullcropname]
if (node) then
local old_after_dig_node = node.after_dig_node
minetest.override_item(fullcropname, {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if (old_after_dig_node) then
old_after_dig_node(pos, oldnode, oldmetadata, digger)
end
check_action_with_item_in_collection("gatherfruitvegetable", "collect", cropname, farming.registered_plants, digger)
end
})
end
end

-- This doesn't work for all plants. Some, like beans, don't use the usual crop/seed naming conventions
for _, plantdef in pairs(farming.registered_plants) do
for i = 1, plantdef.steps do
check_fruits_and_vegetables(plantdef.crop, i)
end
end


-------------------------------------
awards.register_trigger("plow_soil",{
type = "counted",
progress = S("@1/@2 plowed squares of soil"),
auto_description = { S("Plow @2 square of soil"), S("Plow @1×@2 squares of soil") },
})

for name, itemdef in pairs(minetest.registered_tools) do
if (string.find(name, "farming:hoe")) then
local base_on_use = itemdef.on_use
minetest.override_item(name, {
on_use = function(itemstack, user, pointed_thing)
awards.notify_plow_soil(user)
return base_on_use(itemstack, user, pointed_thing)
end
})
end
end


---------------------------------------
awards.register_trigger("plant_crops",{
type = "counted",
progress = S("@1/@2 different crop types planted"),
auto_description = { S("Planted @2 crop"), S("Planted @1×@2 different types of crops") },
})

local registered_seeds = {}
for _, plantdef in pairs(farming.registered_plants) do
local seed_name = plantdef.seed
local reg_item = minetest.registered_items[seed_name]
if (reg_item) then
registered_seeds[seed_name] = 1
local base_on_place = reg_item.on_place
minetest.override_item(seed_name, {
on_place = function(itemstack, placer, pointed_thing)
base_on_place(itemstack, placer, pointed_thing)
awards.notify_place(placer, itemstack:get_name())
check_action_with_item_in_collection("plant_crops", "place", itemstack:get_name(), registered_seeds, placer)
end
})
end
end


end -- if farming

Loading