initial_stuff: Only give best of type
parent
f1517b0b73
commit
c3ab2d13b1
|
@ -199,6 +199,15 @@ local function can_punchplayer(player, hitter)
|
|||
return true
|
||||
end
|
||||
|
||||
local item_levels = {
|
||||
"wood",
|
||||
"stone",
|
||||
"bronze",
|
||||
"steel",
|
||||
"mese",
|
||||
"diamond",
|
||||
}
|
||||
|
||||
return {
|
||||
on_new_match = function()
|
||||
team_list = {}
|
||||
|
@ -494,6 +503,36 @@ return {
|
|||
ctf_combat_mode.add_healer(patient, player, 60)
|
||||
recent_rankings.add(player, {hp_healed = amount, score = score}, true)
|
||||
end,
|
||||
initial_stuff_item_levels = {
|
||||
pick = function(item)
|
||||
local match = item:get_name():match("default:pick_(%a+)")
|
||||
|
||||
if match then
|
||||
return table.indexof(item_levels, match)
|
||||
end
|
||||
end,
|
||||
axe = function(item)
|
||||
local match = item:get_name():match("default:axe_(%a+)")
|
||||
|
||||
if match then
|
||||
return table.indexof(item_levels, match)
|
||||
end
|
||||
end,
|
||||
shovel = function(item)
|
||||
local match = item:get_name():match("default:shovel_(%a+)")
|
||||
|
||||
if match then
|
||||
return table.indexof(item_levels, match)
|
||||
end
|
||||
end,
|
||||
sword = function(item)
|
||||
local mod, match = item:get_name():match("(%a+):sword_(%a+)")
|
||||
|
||||
if mod and (mod == "default" or mod == "ctf_melee") and match then
|
||||
return table.indexof(item_levels, match)
|
||||
end
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
|
|
|
@ -19,7 +19,41 @@ function ctf_modebase.player.give_initial_stuff(player)
|
|||
minetest.log("action", "Giving initial stuff to player " .. player:get_player_name())
|
||||
|
||||
local inv = player:get_inventory()
|
||||
local item_level = {}
|
||||
get_initial_stuff(player, function(item)
|
||||
local mode = ctf_modebase:get_current_mode()
|
||||
|
||||
if mode and mode.initial_stuff_item_levels then
|
||||
for itype, get_level in pairs(mode.initial_stuff_item_levels) do
|
||||
local ilevel, keep = get_level(item)
|
||||
|
||||
if ilevel then
|
||||
if item_level[itype] then
|
||||
-- This item is a higher level than any of its type so far
|
||||
if ilevel > item_level[itype].level then
|
||||
-- remove the other lesser item unless it's a keeper
|
||||
if not item_level[itype].keep then
|
||||
-- minetest.log(dump(item_level[itype].item:get_name()).." r< "..dump(item:get_name()))
|
||||
|
||||
inv:remove_item("main", item_level[itype].item)
|
||||
end
|
||||
|
||||
item_level[itype] = {level = ilevel, item = item, keep = keep}
|
||||
elseif not keep then
|
||||
-- minetest.log(dump(item:get_name()).." s< "..dump(item_level[itype].item:get_name()))
|
||||
|
||||
return -- skip addition, something better is present
|
||||
end
|
||||
else
|
||||
-- First item of this type!
|
||||
item_level[itype] = {level = ilevel, item = item, keep = keep}
|
||||
end
|
||||
|
||||
-- We can't break after discovering an item type, as it might have multiple types
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
inv:remove_item("main", item)
|
||||
inv:add_item("main", item)
|
||||
end)
|
||||
|
|
|
@ -10,6 +10,28 @@ local classes = ctf_core.include_files(
|
|||
local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func
|
||||
local old_get_next_bounty = ctf_modebase.bounties.get_next_bounty
|
||||
local old_get_skin = ctf_cosmetics.get_skin
|
||||
local custom_item_levels = table.copy(features.initial_stuff_item_levels)
|
||||
|
||||
local function prioritize_medic_paxel(tooltype)
|
||||
return function(item)
|
||||
local iname = item:get_name()
|
||||
|
||||
if iname == "ctf_mode_classes:support_paxel" then
|
||||
return
|
||||
features.initial_stuff_item_levels[tooltype](
|
||||
ItemStack(string.format("default:%s_steel", tooltype))
|
||||
) + 0.1,
|
||||
true
|
||||
else
|
||||
return features.initial_stuff_item_levels[tooltype](item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
custom_item_levels.pick = prioritize_medic_paxel("pick" )
|
||||
custom_item_levels.axe = prioritize_medic_paxel("axe" )
|
||||
custom_item_levels.shovel = prioritize_medic_paxel("shovel")
|
||||
|
||||
ctf_modebase.register_mode("classes", {
|
||||
treasures = {
|
||||
["default:ladder_wood" ] = { max_count = 20, rarity = 0.3, max_stacks = 5},
|
||||
|
@ -71,6 +93,7 @@ ctf_modebase.register_mode("classes", {
|
|||
table.insert_all(initial_stuff, {"default:pick_stone", "default:torch 15", "default:stick 5"})
|
||||
return initial_stuff
|
||||
end,
|
||||
initial_stuff_item_levels = custom_item_levels,
|
||||
is_restricted_item = classes.is_restricted_item,
|
||||
on_mode_start = function()
|
||||
ctf_modebase.bounties.bounty_reward_func = ctf_modebase.bounty_algo.kd.bounty_reward_func
|
||||
|
|
|
@ -47,6 +47,7 @@ ctf_modebase.register_mode("classic", {
|
|||
stuff_provider = function()
|
||||
return {"default:sword_stone", "default:pick_stone", "default:torch 15", "default:stick 5"}
|
||||
end,
|
||||
initial_stuff_item_levels = features.initial_stuff_item_levels,
|
||||
on_mode_start = function()
|
||||
ctf_modebase.bounties.bounty_reward_func = ctf_modebase.bounty_algo.kd.bounty_reward_func
|
||||
ctf_modebase.bounties.get_next_bounty = ctf_modebase.bounty_algo.kd.get_next_bounty
|
||||
|
|
|
@ -81,6 +81,7 @@ ctf_modebase.register_mode("nade_fight", {
|
|||
"default:axe_steel"
|
||||
}
|
||||
end,
|
||||
initial_stuff_item_levels = features.initial_stuff_item_levels,
|
||||
on_mode_start = function()
|
||||
ctf_modebase.bounties.bounty_reward_func = ctf_modebase.bounty_algo.kd.bounty_reward_func
|
||||
ctf_modebase.bounties.get_next_bounty = ctf_modebase.bounty_algo.kd.get_next_bounty
|
||||
|
|
Loading…
Reference in New Issue