More treasure chest features

master
Wuzzy 2022-03-03 19:23:57 +01:00
parent 655e790b60
commit 176d0d77a3
17 changed files with 162 additions and 54 deletions

View File

@ -95,6 +95,13 @@ Sounds:
- `lzr_sounds_footstep_stone.*.ogg`, `default_dirt_footstep.*.ogg`, `lzr_sounds_footstep_leaves.*.ogg`, `lzr_sounds_dug_grass.*.ogg`:
- by Wuzzy
- License: MIT License
- `lzr_treasure_chest_open.ogg`:
- by JUDITH136 <https://freesound.org/people/JUDITH136/sounds/408001/>
- License: CC BY 3.0
- `lzr_treasure_chest_open_fail.ogg`:
- by Dymewiz <https://freesound.org/people/Dymewiz/sounds/131029/>
- License: CC BY 3.0
- All other sounds come from Minetest Game (see license of Minetest Game 5.4.1 for details)
Code:

View File

@ -1,60 +1,9 @@
local movement_gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.81
local S = minetest.get_translator("lzr_treasure")
-- Register chests --
local register_chest = function(id, def)
minetest.register_node("lzr_treasure:"..id, {
description = def.description,
paramtype2 = "facedir",
tiles = def.tiles,
groups = { breakable = 1, chest = 1 },
sounds = def.sounds,
on_rotate = screwdriver.rotate_simple,
})
end
register_chest("chest_dark", {
description = S("Dark Chest"),
tiles = {
"xdecor_enderchest_top.png", "xdecor_enderchest_top.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_side.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_front.png"
},
sounds = lzr_sounds.node_sound_stone_defaults(),
})
register_chest("chest_dark_locked", {
description = S("Locked Dark Chest"),
tiles = {
"xdecor_enderchest_top.png", "xdecor_enderchest_top.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_side.png",
"xdecor_enderchest_side.png", "lzr_treasure_enderchest_lock.png"
},
sounds = lzr_sounds.node_sound_stone_defaults(),
})
register_chest("chest_wood", {
description = S("Wooden Chest"),
tiles = {
"default_chest_top.png", "default_chest_top.png",
"default_chest_side.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_front.png"
},
sounds = lzr_sounds.node_sound_wood_defaults(),
})
register_chest("chest_wood_locked", {
description = S("Locked Wooden Chest"),
tiles = {
"default_chest_top.png", "default_chest_top.png",
"default_chest_side.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_lock.png"
},
sounds = lzr_sounds.node_sound_wood_defaults(),
})
local N = function(s) return s end
-- Register treasure blocks --
minetest.register_node("lzr_treasure:gold_block", {
description = S("Gold Block"),
tiles = {"default_gold_block.png"},
@ -62,3 +11,155 @@ minetest.register_node("lzr_treasure:gold_block", {
sounds = lzr_sounds.node_sound_metal_defaults(),
})
-- Register chests --
local register_chest = function(id, def)
local sound_open = def.sound_open or "lzr_treasure_chest_open"
local sound_open_fail = def.sound_open_fail or "lzr_treasure_chest_open_fail"
minetest.register_node("lzr_treasure:chest_"..id.."_unlocked", {
description = def.description_unlocked,
paramtype2 = "facedir",
tiles = { def.tile_top, def.tile_bottom, def.tile_side, def.tile_side, def.tile_side, def.tile_front },
groups = { breakable = 1, chest = 1, rotatable = 1 },
sounds = def.node_sounds,
on_rotate = screwdriver.rotate_simple,
on_punch = function(pos, node, puncher)
minetest.log("action", "[lzr_treasure] "..puncher:get_player_name().." opens "..node.name.." at "..minetest.pos_to_string(pos))
minetest.set_node(pos, {name="lzr_treasure:chest_"..id.."_open_gold", param2=node.param2})
minetest.sound_play({name=sound_open, gain=0.5}, {pos=pos}, true)
end,
})
minetest.register_node("lzr_treasure:chest_"..id.."_locked", {
description = def.description_locked,
paramtype2 = "facedir",
tiles = { def.tile_top, def.tile_bottom, def.tile_side, def.tile_side, def.tile_side, def.tile_front_lock },
groups = { breakable = 1, chest = 2, rotatable = 1 },
sounds = def.node_sounds,
on_rotate = screwdriver.rotate_simple,
on_punch = function(pos, node, puncher)
minetest.sound_play({name=sound_open_fail, gain=0.3}, {pos=pos}, true)
end,
})
minetest.register_node("lzr_treasure:chest_"..id.."_open", {
description = def.description_open,
drawtype = "nodebox",
paramtype = "light",
collision_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 2/16, 0.5 },
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 2/16, 0.5 },
},
node_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, -0.5, -7/16, 2/16, 0.5 },
{ 7/16, -0.5, -0.5, 0.5, 2/16, 0.5 },
{ -7/16, -0.5, -0.5, 7/16, 2/16, -7/16 },
{ -7/16, -0.5, 7/16, 7/16, 2/16, 0.5 },
{ -7/16, -0.5, -7/16, 7/16, -7/16, 7/16 },
},
},
tiles = { def.tile_top, def.tile_bottom, def.tile_side, def.tile_side, def.tile_side, def.tile_front },
paramtype2 = "facedir",
groups = { breakable = 1, chest = 3, rotatable = 1 },
sounds = def.node_sounds,
on_rotate = screwdriver.rotate_simple,
})
-- Open chest with treasure
local treasure_id = "gold"
local treasure = "lzr_treasure:gold_block"
local treasure_tile = "default_gold_block.png"
local treasure_def = minetest.registered_nodes[treasure]
local sounds_open_treasure = table.copy(def.node_sounds)
sounds_open_treasure.footstep = table.copy(treasure_def.sounds.footstep)
sounds_open_treasure.dig = nil
sounds_open_treasure.dug = table.copy(treasure_def.sounds.dug)
minetest.register_node("lzr_treasure:chest_"..id.."_open_"..treasure_id, {
description = S(def.description_open_with, treasure_def.description),
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, -0.5, 0.5, 2/16, 0.5 },
{ -7/16, 2/16, -7/16, 7/16, 0.5, 7/16 },
},
},
tiles = {
"("..def.tile_top..")^("..treasure_tile.."^[mask:lzr_treasure_mask_block_in_chest_top.png)",
def.tile_bottom,
"("..def.tile_side..")^("..treasure_tile.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
"("..def.tile_side..")^("..treasure_tile.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
"("..def.tile_side..")^("..treasure_tile.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
"("..def.tile_front..")^("..treasure_tile.."^[mask:lzr_treasure_mask_block_in_chest_side.png)",
},
on_punch = function(pos, node, puncher)
-- Take treasure out of open chest
minetest.log("action", "[lzr_treasure] "..puncher:get_player_name().." takes treasure from "..node.name.." at "..minetest.pos_to_string(pos))
local inv = puncher:get_inventory()
local give = true
if lzr_gamestate.get_state() == lzr_gamestate.EDITOR and inv:contains_item("main", treasure) then
give = false
end
if give then
inv:add_item("main", treasure)
end
minetest.sound_play(sounds_open_treasure.dug, {pos=pos}, true)
-- spawn a few particles for the taken treasrue
minetest.add_particlespawner({
amount = 12,
time = 0.001,
minpos = vector.subtract(pos, vector.new(7/16, 7/16, 7/16)),
maxpos = vector.add(pos, vector.new(7/16, 7/16, 7/16)),
minvel = vector.new(-0.4, 0, -0.4),
maxvel = vector.new(0.4, 0.2, 0.4),
minacc = vector.new(0, -movement_gravity, 0),
maxacc = vector.new(0, -movement_gravity, 0),
minsize = 0.75,
maxsize = 0.75,
node = {name=treasure},
})
minetest.set_node(pos, {name="lzr_treasure:chest_"..id.."_open", param2=node.param2})
end,
paramtype2 = "facedir",
groups = { breakable = 1, chest = 4, rotatable = 1, },
sounds = sounds_open_treasure,
on_rotate = screwdriver.rotate_simple,
})
end
register_chest("wood", {
description_unlocked = S("Wooden Chest"),
description_locked = S("Locked Wooden Chest"),
description_open = S("Open Wooden Chest"),
description_open_with = N("Open Wooden Chest with @1"),
tile_top = "lzr_treasure_chest_top.png",
tile_bottom = "lzr_treasure_chest_top.png",
tile_side = "lzr_treasure_chest_side.png",
tile_front = "lzr_treasure_chest_front.png",
tile_front_lock = "lzr_treasure_chest_lock.png",
node_sounds = lzr_sounds.node_sound_wood_defaults(),
})
register_chest("dark", {
description_unlocked = S("Dark Chest"),
description_locked = S("Locked Dark Chest"),
description_open = S("Open Dark Chest"),
description_open_with = N("Open Dark Chest with @1"),
tile_top = "lzr_treasure_dark_chest_top.png",
tile_bottom = "lzr_treasure_dark_chest_top.png",
tile_side = "lzr_treasure_dark_chest_side.png",
tile_front = "lzr_treasure_dark_chest_front.png",
tile_front_lock = "lzr_treasure_dark_chest_lock.png",
node_sounds = lzr_sounds.node_sound_stone_defaults(),
})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB