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

Add the "Thief" class #1174

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 21 additions & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local CLASS_SWITCH_COOLDOWN = 30

local classes = {}

local class_list = {"knight", "ranged", "support"}
local class_list = {"knight", "ranged", "support", "thief"}
local class_props = {
knight = {
name = "Knight",
Expand Down Expand Up @@ -55,6 +55,26 @@ local class_props = {
disallowed_items_markup = {
["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png",
},
},
thief = {
name = "Thief",
description = "Criminal class, punch enemies with a bare hand to have a chance of stealing an item from them",
visual_size = vector.new(0.9, 0.9, 0.9),
physics = {speed = 1.2},
items = {
"ctf_mode_classes:scaling_ladder",
"default:cobble 99"
},
disallowed_items = {
"ctf_melee:",
"ctf_ranged:rifle",
"ctf_ranged:smg",
"ctf_ranged:sniper_magnum",
"ctf_ranged:shotgun",
},
disallowed_items_markup = {
["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png"
},
}
}

Expand Down
18 changes: 10 additions & 8 deletions mods/ctf/ctf_modes/ctf_mode_classes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ local rankings = ctf_rankings.init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)

local classes = ctf_core.include_files(
ctf_modes_classes = {}
ctf_modes_classes.classes = ctf_core.include_files(
"paxel.lua",
"classes.lua"
"classes.lua",
"thief.lua"
)

local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func
Expand Down Expand Up @@ -92,12 +94,12 @@ ctf_modebase.register_mode("classes", {
end
end,
stuff_provider = function(player)
local initial_stuff = table.copy(classes.get(player).items or {})
local initial_stuff = table.copy(ctf_modes_classes.classes.get(player).items or {})
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,
is_restricted_item = ctf_modes_classes.classes.is_restricted_item,
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
Expand All @@ -107,21 +109,21 @@ ctf_modebase.register_mode("classes", {
return old_get_skin(player)
end

return old_get_skin(player) .. classes.get_skin_overlay(player)
return old_get_skin(player) .. ctf_modes_classes.classes.get_skin_overlay(player)
end
end,
on_mode_end = function()
ctf_modebase.bounties.bounty_reward_func = old_bounty_reward_func
ctf_modebase.bounties.get_next_bounty = old_get_next_bounty
ctf_cosmetics.get_skin = old_get_skin

classes.finish()
ctf_modes_classes.classes.finish()
end,
on_new_match = features.on_new_match,
on_match_end = features.on_match_end,
team_allocator = features.team_allocator,
on_allocplayer = function(player, new_team)
classes.update(player)
ctf_modes_classes.classes.update(player)
features.on_allocplayer(player, new_team)
end,
on_leaveplayer = features.on_leaveplayer,
Expand All @@ -132,7 +134,7 @@ ctf_modebase.register_mode("classes", {
on_flag_drop = features.on_flag_drop,
on_flag_capture = features.on_flag_capture,
on_flag_rightclick = function(clicker)
classes.show_class_formspec(clicker)
ctf_modes_classes.classes.show_class_formspec(clicker)
end,
get_chest_access = features.get_chest_access,
on_punchplayer = features.on_punchplayer,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_classes/thief.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local robbery_cooldown = ctf_core.init_cooldowns()
local ROBBERY_INTERVAL = 5

local function rob_player(player, robber)
local inv = player:get_inventory()
local stack = inv:get_stack("main", math.random(1, inv:get_size("main")))
local mode = ctf_modebase:get_current_mode()
if mode and mode.stuff_provider then
for _, item in ipairs(ctf_modes_classes.classes.get(player).items) do
if stack:get_name() == item or stack:get_name() == "" then
return "You didn't find anything to rob."
end
end
if robber:get_inventory():room_for_item("main", stack) then
inv:remove_item("main", stack)
robber:get_inventory():add_item("main", stack)
else
local pos = player:get_pos()
inv:remove_item("main", stack)
minetest.add_item(pos, stack)
end
return string.format("You stole %s %s", stack:get_count(), stack:get_description())
end
end

minetest.register_on_punchplayer(function(punched, puncher)
if puncher and puncher:is_player() and punched and punched:is_player() then
if puncher:get_wielded_item():get_name() == "" then
if robbery_cooldown:get(puncher:get_player_name()) then
hud_events.new(puncher, {
text = "You can only rob every "..ROBBERY_INTERVAL.." seconds",
color = "warning",
quick = true,
})
return
end
local msg = rob_player(punched, puncher)
if msg then
hud_events.new(puncher, {
text = msg,
color = "warning",
quick = true,
})
end
robbery_cooldown:set(puncher, ROBBERY_INTERVAL)
end
end
end)