Add initial stuff to team chests

master
savilli 2022-03-12 23:24:12 +03:00
parent 50a665c08f
commit 9f0186e8bf
11 changed files with 98 additions and 85 deletions

View File

@ -105,14 +105,6 @@ local ID_AIR = minetest.CONTENT_AIR
local ID_IGNORE = minetest.CONTENT_IGNORE
local ID_CHEST = minetest.get_content_id("ctf_map:chest")
local ID_WATER = minetest.get_content_id("default:water_source")
local chest_formspec =
"size[8,9]" ..
"list[current_name;main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[current_name;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
local function get_place_positions(a, data, pos1, pos2)
if a.amount <= 0 then return {} end
@ -167,26 +159,44 @@ local function get_place_positions(a, data, pos1, pos2)
return ret
end
function ctf_map.prepare_map_nodes(mapmeta, treasurefy_node_callback, blacklisted_nodes)
local vm = VoxelManip()
local pos1, pos2 = vm:read_from_map(mapmeta.pos1, mapmeta.pos2)
local function prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nodes)
local Nx = pos2.x - pos1.x + 1
local Ny = pos2.y - pos1.y + 1
local data = vm:get_data()
local param2_data = vm:get_param2_data()
local math_floor = math.floor
if blacklisted_nodes then
local blacklist = {}
for _, node in ipairs(blacklisted_nodes) do
blacklist[minetest.get_content_id(node)] = true
end
for i, v in ipairs(data) do
if blacklist[v] then
data[i] = ID_AIR
end
end
local nodes = {}
for _, node in ipairs(blacklisted_nodes) do
nodes[minetest.get_content_id(node)] = false
end
for _, team in ipairs(ctf_teams.teamlist) do
local node = "ctf_teams:chest_" .. team
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
end
for i, v in ipairs(data) do
local op = nodes[v]
if op == false then
data[i] = ID_AIR
elseif op then
-- it's a team chest
local x = (i - 1) % Nx + pos1.x
local y = math_floor((i - 1) / Nx) % Ny + pos1.y
local z = math_floor((i - 1) / Ny / Nx) + pos1.z
local pos = {x=x, y=y, z=z}
op.on_construct(pos)
local inv = minetest.get_meta(pos):get_inventory()
inv:set_list("main", team_chest_items)
inv:set_list("pro", {})
inv:set_list("helper", {})
end
end
end
local function place_treasure_chests(mapmeta, pos1, pos2, data, param2_data, treasurefy_node_callback)
for i, a in pairs(mapmeta.chests) do
local place_positions = get_place_positions(a, data, pos1, pos2)
@ -195,12 +205,9 @@ function ctf_map.prepare_map_nodes(mapmeta, treasurefy_node_callback, blackliste
param2_data[pos.vi] = 0
-- Treasurefy
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Treasure Chest")
meta:set_string("formspec", chest_formspec)
minetest.registered_nodes["ctf_map:chest"].on_construct(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
local inv = minetest.get_meta(pos):get_inventory()
inv:set_list("main", {})
if treasurefy_node_callback then
treasurefy_node_callback(inv)
@ -213,6 +220,17 @@ function ctf_map.prepare_map_nodes(mapmeta, treasurefy_node_callback, blackliste
)
end
end
end
function ctf_map.prepare_map_nodes(mapmeta, treasurefy_node_callback, team_chest_items, blacklisted_nodes)
local vm = VoxelManip()
local pos1, pos2 = vm:read_from_map(mapmeta.pos1, mapmeta.pos2)
local data = vm:get_data()
local param2_data = vm:get_param2_data()
prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nodes)
place_treasure_chests(mapmeta, pos1, pos2, data, param2_data, treasurefy_node_callback)
vm:set_data(data)
vm:set_param2_data(param2_data)

View File

@ -125,6 +125,15 @@ minetest.register_alias("ctf_map:torch_ceiling", "default:torch_ceiling")
--
--- credit for most of code goes to tsm_chests mod used by CTF 2.0
local chest_formspec =
"size[8,9]" ..
"list[current_name;main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[current_name;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
minetest.register_node("ctf_map:chest", {
description = "Treasure Chest",
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
@ -134,6 +143,14 @@ minetest.register_node("ctf_map:chest", {
light_source = 2,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Treasure Chest")
meta:set_string("formspec", chest_formspec)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if player then
minetest.chat_send_player(player:get_player_name(),

View File

@ -127,7 +127,8 @@ return {
ctf_map.prepare_map_nodes(
ctf_map.current_map,
function(inv) ctf_map.treasure.treasurefy_node(inv, map_treasures) end,
ctf_modebase:get_current_mode().blacklisted_nodes
ctf_modebase:get_current_mode().team_chest_items or {},
ctf_modebase:get_current_mode().blacklisted_nodes or {}
)
end,
on_match_end = function()

View File

@ -3,11 +3,6 @@ ctf_modebase.map_on_next_match = nil
ctf_modebase.mode_on_next_match = nil
function ctf_modebase.start_match_after_vote()
for _, pos in pairs(ctf_teams.team_chests) do
minetest.remove_node(pos)
end
ctf_teams.team_chests = {}
local old_mode = ctf_modebase.current_mode
if ctf_modebase.mode_on_next_match ~= old_mode then

View File

@ -1,10 +0,0 @@
return {
"ctf_ranged:ammo",
"default:axe_mese",
"default:axe_diamond",
"default:shovel_mese",
"default:shovel_diamond",
"ctf_map:damage_cobble",
"ctf_map:spike",
"ctf_map:reinforced_cobble 2",
}

View File

@ -2,8 +2,7 @@ local rankings = ctf_rankings.init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)
local crafts, classes = ctf_core.include_files(
"crafts.lua",
local classes = ctf_core.include_files(
"paxel.lua",
"classes.lua"
)
@ -41,9 +40,16 @@ ctf_modebase.register_mode("classes", {
["grenades:frag" ] = {rarity = 0.1, max_stacks = 1},
["grenades:smoke"] = {rarity = 0.2, max_stacks = 2},
},
crafts = crafts,
crafts = {
"ctf_ranged:ammo", "default:axe_mese", "default:axe_diamond", "default:shovel_mese", "default:shovel_diamond",
"ctf_map:damage_cobble", "ctf_map:spike", "ctf_map:reinforced_cobble 2",
},
physics = {sneak_glitch = true, new_move = false},
blacklisted_nodes = {"default:apple"},
team_chest_items = {
"default:cobble 80", "default:wood 80", "ctf_map:damage_cobble 20", "ctf_map:reinforced_cobble 20",
"default:torch 30", "ctf_teams:door_steel 2",
},
rankings = rankings,
recent_rankings = recent_rankings,
summary_ranks = {

View File

@ -1,6 +0,0 @@
return {
"ctf_ranged:ammo",
"ctf_melee:sword_steel",
"ctf_melee:sword_mese",
"ctf_melee:sword_diamond",
}

View File

@ -2,10 +2,6 @@ local rankings = ctf_rankings.init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)
local crafts = ctf_core.include_files(
"crafts.lua"
)
local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func
local old_get_next_bounty = ctf_modebase.bounties.get_next_bounty
ctf_modebase.register_mode("classic", {
@ -34,8 +30,9 @@ ctf_modebase.register_mode("classic", {
["grenades:frag" ] = {rarity = 0.1, max_stacks = 1},
["grenades:smoke"] = {rarity = 0.2, max_stacks = 2},
},
crafts = crafts,
crafts = {"ctf_ranged:ammo", "ctf_melee:sword_steel", "ctf_melee:sword_mese", "ctf_melee:sword_diamond"},
physics = {sneak_glitch = true, new_move = false},
team_chest_items = {"default:cobble 99", "default:wood 99", "default:torch 30", "ctf_teams:door_steel 2"},
rankings = rankings,
recent_rankings = recent_rankings,
summary_ranks = {

View File

@ -52,6 +52,10 @@ ctf_modebase.register_mode("nade_fight", {
},
physics = {sneak_glitch = true, new_move = false},
blacklisted_nodes = {"default:apple"},
team_chest_items = {
"ctf_ranged:ammo", "default:axe_mese", "default:axe_diamond", "default:shovel_mese", "default:shovel_diamond",
"ctf_map:damage_cobble", "ctf_map:spike", "ctf_map:reinforced_cobble 2",
},
rankings = rankings,
recent_rankings = recent_rankings,
summary_ranks = {

View File

@ -31,8 +31,6 @@ ctf_teams = {
player_team = {},
online_players = {},
current_team_list = {},
team_chests = {}, -- Whenever a team chest is initialized it'll be put in this table
}
for team, def in pairs(ctf_teams.team) do
@ -96,4 +94,4 @@ minetest.register_on_mods_loaded(function()
))
end
end)
end)
end)

View File

@ -24,9 +24,8 @@ function ctf_teams.is_allowed_in_team_chest(listname, stack, player)
return true
end
local colors = ctf_teams.teamlist
for _, chest_color in pairs(colors) do
local chestcolor = ctf_teams.team[chest_color].color
for _, team in ipairs(ctf_teams.teamlist) do
local chestcolor = ctf_teams.team[team].color
local function get_chest_texture(chest_side, color, mask, extra)
return string.format(
"(default_chest_%s.png^[colorize:%s:130)^(default_chest_%s.png^[mask:ctf_teams_chest_%s_mask.png^[colorize:%s:60)%s",
@ -40,7 +39,7 @@ for _, chest_color in pairs(colors) do
end
local def = {
description = HumanReadable(chest_color).." Team's Chest",
description = HumanReadable(team).." Team's Chest",
tiles = {
get_chest_texture("top", chestcolor, "top"),
get_chest_texture("top", chestcolor, "top"),
@ -58,7 +57,8 @@ for _, chest_color in pairs(colors) do
function def.on_construct(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", string.format("%s Team's Chest", HumanReadable(chest_color)))
meta:set_string("infotext", string.format("%s Team's Chest", HumanReadable(team)))
local inv = meta:get_inventory()
inv:set_size("main", 4 * 7)
inv:set_size("pro", 4 * 7)
@ -70,20 +70,13 @@ for _, chest_color in pairs(colors) do
end
function def.on_rightclick(pos, node, player)
local meta = minetest.get_meta(pos)
local name = player:get_player_name()
if meta:get_string("infotext") == "" then
table.insert(ctf_teams.team_chests, pos)
def.on_construct(pos)
end
local flag_captured = ctf_modebase.flag_captured[chest_color]
if not flag_captured and chest_color ~= ctf_teams.get(name) then
local flag_captured = ctf_modebase.flag_captured[team]
if not flag_captured and team ~= ctf_teams.get(name) then
hud_events.new(player, {
quick = true,
text = "You're not on team " .. chest_color,
text = "You're not on team " .. team,
color = "warning",
})
return
@ -146,10 +139,10 @@ for _, chest_color in pairs(colors) do
to_list, to_index, count, player)
local name = player:get_player_name()
if chest_color ~= ctf_teams.get(name) then
if team ~= ctf_teams.get(name) then
hud_events.new(player, {
quick = true,
text = "You're not on team " .. chest_color,
text = "You're not on team " .. team,
color = "warning",
})
return 0
@ -182,10 +175,10 @@ for _, chest_color in pairs(colors) do
function def.allow_metadata_inventory_put(pos, listname, index, stack, player)
local name = player:get_player_name()
if chest_color ~= ctf_teams.get(name) then
if team ~= ctf_teams.get(name) then
hud_events.new(player, {
quick = true,
text = "You're not on team " .. chest_color,
text = "You're not on team " .. team,
color = "warning",
})
return 0
@ -221,16 +214,16 @@ for _, chest_color in pairs(colors) do
return 0
end
if ctf_modebase.flag_captured[chest_color] then
if ctf_modebase.flag_captured[team] then
return stack:get_count()
end
local name = player:get_player_name()
if chest_color ~= ctf_teams.get(name) then
if team ~= ctf_teams.get(name) then
hud_events.new(player, {
quick = true,
text = "You're not on team " .. chest_color,
text = "You're not on team " .. team,
color = "warning",
})
return 0
@ -261,5 +254,5 @@ for _, chest_color in pairs(colors) do
))
end
minetest.register_node("ctf_teams:chest_" .. chest_color, def)
minetest.register_node("ctf_teams:chest_" .. team, def)
end