10 Commits

Author SHA1 Message Date
95991ce94f Typo 2018-06-14 08:11:18 +02:00
7a7ddc88af Add test award for punch entity 2018-06-14 08:09:21 +02:00
d25e638cfb Add kill_mob and punch_entity triggers; it's now possible to create awards for killing mobs and punching entities 2018-06-14 07:54:44 +02:00
21e1ce6675 Fix convert_data crash when craft data is missing
Crash occurs when no data for "craft" is available in the old data, fixed with a additional check.
2018-05-31 15:06:56 +01:00
0ae58ad0c3 Fix locked awards not taking difficulty into account 2018-04-17 22:37:09 +01:00
7d462c6aa5 Add difficulty multiplers to default mod awards 2018-04-17 22:29:13 +01:00
f0052386c8 Add award difficulty multipler 2018-04-17 22:25:53 +01:00
08f654cf94 Remove debug prints
Fixes #57
2018-04-17 22:10:40 +01:00
3fc12eb689 Update README.md 2018-04-06 22:12:56 +01:00
98fca7914b Add on_unlock() documentation 2018-04-06 22:11:08 +01:00
6 changed files with 191 additions and 14 deletions

View File

@ -17,21 +17,44 @@ awards.register_award("mymod:myaward", {
-- Optional:
difficulty = 1.0, -- Difficulty multipler
requires = { "amod:an_award" }, -- don't show this award or allow it to be unlocked
-- until required awards are unlocked
sound = {}, -- SimpleSoundSpec or false to play no sound
-- if not provided, uses default sound
image = "icon_image.png", -- uses default icon otherwise
background = "background_image.png", -- uses default background otherwise
trigger = { -- is only unlocked by direct calls to awards.unlock() otherwise
type = "trigger_type",
-- see specific docs on the trigger to see what else goes here
},
-- Callback. award_def is this table (plus some additional methods/members added by register_award)
on_unlock = function(name, award_def) end,
})
```
If the award is counted, ie: there's a trigger.target property, then the difficulty
multipler is timesd by target to get the overal difficulty. If the award isn't a
counted type then the difficulty multiplier is used as the overal difficulty.
Award difficulty affects how awards are sorted in a list - more difficult awards
are further down the list.
Actual code used to calculate award difficulty:
```lua
local difficulty = def.difficulty or 1
if def.trigger and def.trigger.target then
difficulty = difficulty * def.trigger.target
end
```
## Registering Trigger Types
```lua

18
api.lua
View File

@ -51,12 +51,14 @@ local function convert_data()
local ret = {}
local count = 0
for modname, items in pairs(data[from]) do
for itemname, value in pairs(items) do
itemname = modname .. ":" .. itemname
local key = minetest.registered_aliases[itemname] or itemname
ret[key] = value
count = count + value
if data[from] then
for modname, items in pairs(data[from]) do
for itemname, value in pairs(items) do
itemname = modname .. ":" .. itemname
local key = minetest.registered_aliases[itemname] or itemname
ret[key] = value
count = count + value
end
end
end
@ -67,8 +69,6 @@ local function convert_data()
awards.players[name] = data
end
print(dump(awards.players))
end
function awards.load()
@ -162,7 +162,6 @@ function awards.register_trigger(tname, tdef)
assert(player and player.is_player and player:is_player())
local name = player:get_player_name()
local data = awards.player(name)
print(dump(data))
-- Increment counter
local currentVal = (data[tname] or 0) + 1
@ -225,7 +224,6 @@ function awards.register_trigger(tname, tdef)
assert(player and player.is_player and player:is_player() and key)
local name = player:get_player_name()
local data = awards.player(name)
print(dump(data))
-- Increment counter
data[tname] = data[tname] or {}

View File

@ -87,6 +87,7 @@ if minetest.get_modpath("default") then
title = S("Light It Up"),
description = S("Place 100 torches."),
icon = "awards_novicebuilder.png^awards_level1.png",
difficulty = 0.01,
trigger = {
type = "place",
node = "default:torch",
@ -97,8 +98,9 @@ if minetest.get_modpath("default") then
-- Light ALL the things!
awards.register_award("award_well_lit",{
title = S("Well Lit"),
description = S("Place 1,000 torches."),
icon = "awards_novicebuilder.png^awards_level2.png",
description = S("Place 1,000 torches."),
difficulty = 0.01,
trigger = {
type = "place",
node = "default:torch",
@ -110,6 +112,7 @@ if minetest.get_modpath("default") then
title = S("Really Well Lit"),
description = S("Craft 10 mese lamps."),
icon = "default_meselamp.png",
difficulty = 0.2,
trigger = {
type = "craft",
item = "default:meselamp",
@ -121,6 +124,7 @@ if minetest.get_modpath("default") then
title = S("Outpost"),
description = S("Craft 200 stone bricks."),
icon = "default_stone_brick.png^awards_level1.png",
difficulty = 0.08,
trigger = {
type = "craft",
item = "default:stonebrick",
@ -132,6 +136,7 @@ if minetest.get_modpath("default") then
title = S("Watchtower"),
description = S("Craft 800 stone bricks."),
icon = "default_stone_brick.png^awards_level2.png",
difficulty = 0.08,
trigger = {
type = "craft",
item = "default:stonebrick",
@ -143,6 +148,7 @@ if minetest.get_modpath("default") then
title = S("Fortress"),
description = S("Craft 3,200 stone bricks."),
icon = "default_stone_brick.png^awards_level3.png",
difficulty = 0.08,
trigger = {
type = "craft",
item = "default:stonebrick",
@ -154,6 +160,7 @@ if minetest.get_modpath("default") then
title = S("Desert Dweller"),
description = S("Craft 400 desert stone bricks."),
icon = "default_desert_stone_brick.png",
difficulty = 0.09,
trigger = {
type = "craft",
item = "default:desert_stonebrick",
@ -165,6 +172,7 @@ if minetest.get_modpath("default") then
title = S("Pharaoh"),
description = S("Craft 100 sandstone bricks."),
icon = "default_sandstone_brick.png",
difficulty = 0.09,
trigger = {
type = "craft",
item = "default:sandstonebrick",
@ -176,6 +184,7 @@ if minetest.get_modpath("default") then
title = S("Little Library"),
description = S("Craft 7 bookshelves."),
icon = "default_bookshelf.png",
difficulty = 0.2,
trigger = {
type = "craft",
item = "default:bookshelf",
@ -188,6 +197,7 @@ if minetest.get_modpath("default") then
description = S("Mine your first obsidian."),
icon = "default_obsidian.png^awards_level1.png",
background = "awards_bg_mining.png",
difficulty = 1.5,
trigger = {
type = "dig",
node = "default:obsidian",
@ -201,6 +211,7 @@ if minetest.get_modpath("default") then
description = S("Mine 50 obsidian."),
icon = "default_obsidian.png^awards_level2.png",
background = "awards_bg_mining.png",
difficulty = 1.5,
trigger = {
type = "dig",
node = "default:obsidian",
@ -214,6 +225,7 @@ if minetest.get_modpath("default") then
description = S("Mine any block while being very close to lava."),
background = "awards_bg_mining.png",
icon = "default_lava.png",
difficulty = 1,
})
awards.register_on_dig(function(player,data)
local pos = player:get_pos()
@ -229,6 +241,7 @@ if minetest.get_modpath("default") then
title = S("On The Way"),
description = S("Place 100 rails."),
icon = "carts_rail_straight.png",
difficulty = 0.1,
trigger = {
type = "place",
node = "default:rail",
@ -240,6 +253,7 @@ if minetest.get_modpath("default") then
title = S("First Day in the Woods"),
description = S("Dig 6 tree blocks."),
icon = "default_tree.png^awards_level1.png",
difficulty = 0.03,
trigger = {
type = "dig",
node = "default:tree",
@ -252,6 +266,7 @@ if minetest.get_modpath("default") then
title = S("Lumberjack"),
description = S("Dig 36 tree blocks."),
icon = "default_tree.png^awards_level2.png",
difficulty = 0.03,
trigger = {
type = "dig",
node = "default:tree",
@ -264,6 +279,7 @@ if minetest.get_modpath("default") then
title = S("Semi-pro Lumberjack"),
description = S("Dig 216 tree blocks."),
icon = "default_tree.png^awards_level3.png",
difficulty = 0.03,
trigger = {
type = "dig",
node = "default:tree",
@ -276,6 +292,7 @@ if minetest.get_modpath("default") then
title = S("Professional Lumberjack"),
description = S("Dig 1,296 tree blocks."),
icon = "default_tree.png^awards_level4.png",
difficulty = 0.03,
trigger = {
type = "dig",
node = "default:tree",
@ -288,6 +305,7 @@ if minetest.get_modpath("default") then
title = S("Junglebaby"),
description = S("Dig 100 jungle tree blocks."),
icon = "default_jungletree.png^awards_level1.png",
difficulty = 0.05,
trigger = {
type = "dig",
node = "default:jungletree",
@ -300,6 +318,7 @@ if minetest.get_modpath("default") then
title = S("Jungleman"),
description = S("Dig 1,000 jungle tree blocks."),
icon = "default_jungletree.png^awards_level2.png",
difficulty = 0.05,
trigger = {
type = "dig",
node = "default:jungletree",
@ -313,6 +332,7 @@ if minetest.get_modpath("default") then
description = S("Mine your first mese ore."),
icon = "default_stone.png^default_mineral_mese.png",
background = "awards_bg_mining.png",
difficulty = 1,
trigger = {
type = "dig",
node = "default:stone_with_mese",
@ -327,6 +347,7 @@ if minetest.get_modpath("default") then
description = S("Mine a mese block."),
icon = "default_mese_block.png",
background = "awards_bg_mining.png",
difficulty = 1.1,
trigger = {
type = "dig",
node = "default:mese",
@ -340,6 +361,7 @@ if minetest.get_modpath("default") then
description = S("Dig 1,000 copper ores."),
icon = "default_stone.png^default_mineral_copper.png",
background = "awards_bg_mining.png",
difficulty = 0.2,
trigger = {
type = "dig",
node = "default:stone_with_copper",
@ -353,6 +375,7 @@ if minetest.get_modpath("default") then
description = S("Dig 100 stone blocks."),
icon = "awards_miniminer.png^awards_level1.png",
background = "awards_bg_mining.png",
difficulty = 0.02,
trigger = {
type = "dig",
node = "default:stone",
@ -366,6 +389,7 @@ if minetest.get_modpath("default") then
description = S("Dig 1,000 stone blocks."),
icon = "awards_miniminer.png^awards_level2.png",
background = "awards_bg_mining.png",
difficulty = 0.02,
trigger = {
type = "dig",
node = "default:stone",
@ -379,6 +403,7 @@ if minetest.get_modpath("default") then
description = S("Dig 10,000 stone blocks."),
icon = "awards_miniminer.png^awards_level3.png",
background = "awards_bg_mining.png",
difficulty = 0.02,
trigger = {
type = "dig",
node = "default:stone",
@ -392,6 +417,7 @@ if minetest.get_modpath("default") then
description = S("Dig 1,000 sand."),
icon = "default_sand.png",
background = "awards_bg_mining.png",
difficulty = 0.05,
trigger = {
type = "dig",
node = "default:sand",
@ -403,6 +429,7 @@ if minetest.get_modpath("default") then
title = S("Crafter of Sticks"),
description = S("Craft 100 sticks."),
icon = "default_stick.png",
difficulty = 0.01,
trigger = {
type = "craft",
item = "default:stick",
@ -414,6 +441,7 @@ if minetest.get_modpath("default") then
title = S("Jungle Discoverer"),
description = S("Mine your first jungle grass."),
icon = "default_junglegrass.png",
difficulty = 0.009,
trigger = {
type = "dig",
node = "default:junglegrass",
@ -425,6 +453,7 @@ if minetest.get_modpath("default") then
title = S("Grasslands Discoverer"),
description = S("Mine some grass."),
icon = "default_grass_3.png",
difficulty = 0.009,
trigger = {
type = "dig",
node = "default:grass_1",
@ -436,6 +465,7 @@ if minetest.get_modpath("default") then
title = S("Savannah Discoverer"),
description = S("Mine some dry grass."),
icon = "default_dry_grass_3.png",
difficulty = 0.009,
trigger = {
type = "dig",
node = "default:dry_grass_3",
@ -447,6 +477,7 @@ if minetest.get_modpath("default") then
title = S("Desert Discoverer"),
description = S("Mine your first cactus."),
icon = "default_cactus_side.png",
difficulty = 0.03,
trigger = {
type = "dig",
node = "default:cactus",
@ -458,6 +489,7 @@ if minetest.get_modpath("default") then
title = S("Far Lands"),
description = S("Mine your first dry shrub."),
icon = "default_dry_shrub.png",
difficulty = 0.009,
trigger = {
type = "dig",
node = "default:dry_shrub",
@ -469,6 +501,7 @@ if minetest.get_modpath("default") then
title = S("Glacier Discoverer"),
description = S("Mine your first ice."),
icon = "default_ice.png",
difficulty = 0.02,
trigger = {
type = "dig",
node = "default:ice",
@ -481,6 +514,7 @@ if minetest.get_modpath("default") then
title = S("Very Simple Snow Man"),
description = S("Place two snow blocks."),
icon = "default_snow.png",
difficulty = 0.02,
trigger = {
type = "place",
node = "default:snowblock",
@ -493,6 +527,7 @@ if minetest.get_modpath("default") then
description = S("Mine your first gold ore."),
icon = "default_stone.png^default_mineral_gold.png^awards_level1.png",
background = "awards_bg_mining.png",
difficulty = 0.9,
trigger = {
type = "dig",
node = "default:stone_with_gold",
@ -505,6 +540,7 @@ if minetest.get_modpath("default") then
description = S("Mine 45 gold ores."),
icon = "default_stone.png^default_mineral_gold.png^awards_level2.png",
background = "awards_bg_mining.png",
difficulty = 0.9,
trigger = {
type = "dig",
node = "default:stone_with_gold",
@ -516,6 +552,7 @@ if minetest.get_modpath("default") then
title = S("Wow, I am Diamonds!"),
description = S("Mine your first diamond ore."),
icon = "default_stone.png^default_mineral_diamond.png^awards_level1.png",
difficulty = 1,
trigger = {
type = "dig",
node = "default:stone_with_diamond",
@ -528,6 +565,7 @@ if minetest.get_modpath("default") then
description = S("Mine 18 diamond ores."),
icon = "default_stone.png^default_mineral_diamond.png^awards_level2.png",
background = "awards_bg_mining.png",
difficulty = 1,
trigger = {
type = "dig",
node = "default:stone_with_diamond",
@ -539,6 +577,7 @@ if minetest.get_modpath("default") then
title = S("Hardest Block on Earth"),
description = S("Craft a diamond block."),
icon = "default_diamond_block.png",
difficulty = 1.1,
trigger = {
type = "craft",
item = "default:diamondblock",
@ -550,6 +589,7 @@ if minetest.get_modpath("default") then
title = S("In the Dungeon"),
description = S("Mine a mossy cobblestone."),
icon = "default_mossycobble.png",
difficulty = 0.9,
trigger = {
type = "dig",
node = "default:mossycobble",
@ -561,6 +601,7 @@ if minetest.get_modpath("default") then
title = S("Smelter"),
description = S("Craft 10 furnaces."),
icon = "default_furnace_front.png",
difficulty = 0.08,
trigger = {
type = "craft",
item= "default:furnace",
@ -572,6 +613,7 @@ if minetest.get_modpath("default") then
title = S("Treasurer"),
description = S("Craft 15 chests."),
icon = "default_chest_front.png",
difficulty = 0.08,
trigger = {
type = "craft",
item= "default:chest",
@ -583,6 +625,7 @@ if minetest.get_modpath("default") then
title = S("Bankier"),
description = S("Craft 30 locked chests."),
icon = "default_chest_lock.png",
difficulty = 0.08,
trigger = {
type = "craft",
item= "default:chest_locked",
@ -594,6 +637,7 @@ if minetest.get_modpath("default") then
title = S("Bricker"),
description = S("Craft 200 brick blocks."),
icon = "default_brick.png",
difficulty = 0.03,
trigger = {
type = "craft",
item= "default:brick",
@ -605,6 +649,7 @@ if minetest.get_modpath("default") then
title = S("House of Obsidian"),
description = S("Craft 100 obsidian bricks."),
icon = "default_obsidian_brick.png",
difficulty = 0.4,
trigger = {
type = "craft",
item= "default:obsidianbrick",
@ -616,6 +661,7 @@ if minetest.get_modpath("default") then
title = S("Build a Cave"),
description = S("Place 100 stone."),
icon = "default_stone.png",
difficulty = 0.1,
trigger = {
type = "place",
node = "default:stone",
@ -627,6 +673,7 @@ if minetest.get_modpath("default") then
title = S("Long Ladder"),
description = S("Place 400 wooden ladders."),
icon = "default_ladder_wood.png",
difficulty = 0.1,
trigger = {
type = "place",
node = "default:ladder_wood",
@ -638,6 +685,7 @@ if minetest.get_modpath("default") then
title = S("Industrial Age"),
description = S("Place 40 steel ladders."),
icon = "default_ladder_steel.png",
difficulty = 1,
trigger = {
type = "place",
node = "default:ladder_steel",
@ -649,6 +697,7 @@ if minetest.get_modpath("default") then
title = S("Yummy!"),
description = S("Eat 80 apples."),
icon = "default_apple.png",
difficulty = 0.1,
trigger = {
type = "eat",
item = "default:apple",
@ -909,3 +958,45 @@ if minetest.get_modpath("nyancat") then
}
})
end
if minetest.get_modpath("mobs_animal") then
awards.register_award("mobs:kill_chicken", {
title = S("Chicken"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
mob = "mobs_animal:chicken",
target = 5
}
})
awards.register_award("mobs:kill_cow", {
title = S("Cows"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
mob = "mobs_animal:cow",
target = 5
}
})
awards.register_award("mobs:kill_all", {
title = S("All"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
target = 5
}
})
end
awards.register_award("pnch_entity_test", {
title = S("All"),
description = S("A test award for punching"),
difficulty = 0.001,
trigger = {
type = "punch_entity",
target = 5
}
})

View File

@ -12,3 +12,4 @@ moreblocks?
fire?
flowers?
nyancat?
mobs_animal?

10
gui.lua
View File

@ -13,9 +13,13 @@ local function order_awards(name)
if def then
hash_is_unlocked[awardname] = true
local score = -100000
local difficulty = def.difficulty or 1
if def.trigger and def.trigger.target then
score = score + def.trigger.target
difficulty = difficulty * def.trigger.target
end
score = score + difficulty
retval[#retval + 1] = {
name = awardname,
def = def,
@ -30,12 +34,12 @@ local function order_awards(name)
for _, def in pairs(awards.registered_awards) do
if not hash_is_unlocked[def.name] and def:can_unlock(data) then
local started = false
local score
local score = def.difficulty or 1
if def.secret then
score = 1000000
elseif def.trigger and def.trigger.target and def.getProgress then
local progress = def:getProgress(data).perc
score = (1 - progress) * def.trigger.target
score = score * (1 - progress) * def.trigger.target
if progress < 0.001 then
score = score + 100
else

View File

@ -135,3 +135,63 @@ minetest.register_on_item_eat(function(_, _, itemstack, player, _)
itemname = minetest.registered_aliases[itemname] or itemname
awards.notify_craft(player, itemname, itemstack:get_count())
end)
-- trigger for killing entities with more than 1 point of health
awards.register_trigger("kill_mob", {
type = "counted_key",
progress = "@1/@2 killed",
auto_description = { "Kill @2", "Kill @1×@2" },
auto_description_total = { "Kill @1 mob", "Kill @1 mobs." },
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.mob] or def.trigger.mob
end
})
-- wait for all mobs to be registered
minetest.after(0, function()
local ents = minetest.registered_entities
local mobs = {}
for _, ent in pairs(ents) do
if ent.hp_max ~= nil and ent.hp_max > 0 then
table.insert(mobs,ent)
end
end
for _, mob in pairs(mobs) do
local old_func = mob.on_punch
mob.on_punch = function(self, player, a, b, c, d)
old_func(self, player, a, b, c, d)
if player and player:is_player() then
if self.health <= 0 then
awards.notify_kill_mob(player, self.name)
end
end
end
end
end)
-- trigger for killing an entity
awards.register_trigger("punch_entity", {
type = "counted_key",
progress = "@1/@2 punched",
auto_description = { "Punch @2", "Punch @1×@2" },
auto_description_total = { "Punch @1 entity", "Punch @1 entities." },
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.mob] or def.trigger.mob
end
})
-- wait for all entities to be registered
minetest.after(0, function()
local ents = minetest.registered_entities
for _, ent in pairs(ents) do
if ent.hp_max == nil then
local old_func = ent.on_punch
ent.on_punch = function(self, player, a, b, c, d)
old_func(self, player, a, b, c, d)
if player and player:is_player() then
awards.notify_punch_entity(player, self.name)
end
end
end
end
end)